@@ -31,13 +31,20 @@ import { Style, StyleType, parse } from "./parser";
31
31
32
32
const start = new Position ( 0 , 0 ) ;
33
33
const cache = new Map < string , Style [ ] > ( ) ;
34
- const isRemote = / ^ h t t p s ? : \/ \/ / i;
35
- const wordRange = / [ _ a - z A - Z 0 - 9 - ] + / ;
36
- const findSelector = / ( [ ^ ( \[ { } \] ) \s ] + ) (? ! [ ^ ( \[ { ] * [ } \] ) ] ) / gi;
37
- const findAttribute = / ( c l a s s | c l a s s N a m e ) \s * [ = : ] \s * ( [ " ' ] ) ( .* ?) \2/ gis;
38
- const canComplete = / ( i d | c l a s s | c l a s s N a m e ) \s * [ = : ] \s * ( [ " ' ] ) (?: .(? ! \2) ) * $ / is;
39
34
40
35
export class Provider implements CompletionItemProvider , DefinitionProvider {
36
+ private get isRemote ( ) {
37
+ return / ^ h t t p s ? : \/ \/ / i;
38
+ }
39
+
40
+ private get wordRange ( ) {
41
+ return / [ _ a - z A - Z 0 - 9 - ] + / ;
42
+ }
43
+
44
+ private get canComplete ( ) {
45
+ return / ( i d | c l a s s | c l a s s N a m e ) \s * [ = : ] \s * ( [ " ' ] ) (?: .(? ! \2) ) * $ / is;
46
+ }
47
+
41
48
private async fetch ( url : string ) {
42
49
try {
43
50
const res = await fetch ( url ) ;
@@ -82,7 +89,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
82
89
const globs = getStyleSheets ( document . uri ) ;
83
90
84
91
for ( const glob of globs ) {
85
- if ( isRemote . test ( glob ) ) {
92
+ if ( this . isRemote . test ( glob ) ) {
86
93
styles . set ( glob , await this . getRemote ( glob ) ) ;
87
94
} else if ( folder ) {
88
95
const files = await workspace . findFiles (
@@ -123,7 +130,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
123
130
type : StyleType
124
131
) {
125
132
const map = await this . getCompletionMap ( document , type ) ;
126
- const range = document . getWordRangeAtPosition ( position , wordRange ) ;
133
+ const range = document . getWordRangeAtPosition ( position , this . wordRange ) ;
127
134
const items = [ ] ;
128
135
129
136
for ( const item of map . values ( ) ) {
@@ -141,7 +148,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
141
148
) : ProviderResult < CompletionItem [ ] | CompletionList < CompletionItem > > {
142
149
const range = new Range ( start , position ) ;
143
150
const text = document . getText ( range ) ;
144
- const match = canComplete . exec ( text ) ;
151
+ const match = this . canComplete . exec ( text ) ;
145
152
146
153
return new Promise ( ( resolve , reject ) =>
147
154
match && ! token . isCancellationRequested
@@ -158,12 +165,12 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
158
165
159
166
private async getDefinitions ( document : TextDocument , position : Position ) {
160
167
const styles = await this . getStyles ( document ) ;
161
- const range = document . getWordRangeAtPosition ( position , wordRange ) ;
168
+ const range = document . getWordRangeAtPosition ( position , this . wordRange ) ;
162
169
const selector = document . getText ( range ) ;
163
170
const locations : Location [ ] = [ ] ;
164
171
165
172
for ( const entry of styles ) {
166
- if ( ! isRemote . test ( entry [ 0 ] ) ) {
173
+ if ( ! this . isRemote . test ( entry [ 0 ] ) ) {
167
174
entry [ 1 ]
168
175
. filter ( ( style ) => style . selector === selector )
169
176
. forEach ( ( style ) =>
@@ -186,7 +193,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
186
193
) : ProviderResult < Definition | LocationLink [ ] > {
187
194
const range = new Range ( start , position ) ;
188
195
const text = document . getText ( range ) ;
189
- const match = canComplete . exec ( text ) ;
196
+ const match = this . canComplete . exec ( text ) ;
190
197
191
198
return new Promise ( ( resolve , reject ) =>
192
199
match && ! token . isCancellationRequested
@@ -196,6 +203,8 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
196
203
}
197
204
198
205
async validate ( document : TextDocument ) {
206
+ const findSelector = / ( [ ^ ( \[ { } \] ) \s ] + ) (? ! [ ^ ( \[ { ] * [ } \] ) ] ) / gi;
207
+ const findAttribute = / ( c l a s s | c l a s s N a m e ) \s * [ = : ] \s * ( [ " ' ] ) ( .* ?) \2/ gis;
199
208
const diagnostics : Diagnostic [ ] = [ ] ;
200
209
const map = await this . getCompletionMap ( document , StyleType . CLASS ) ;
201
210
const text = document . getText ( ) ;
0 commit comments