@@ -20,10 +20,13 @@ import {
2020
2121export class ClassCompletionItemProvider implements CompletionItemProvider {
2222
23+
24+ readonly none = "__!NONE!__" ;
25+ readonly fixed = "__!FIXED!__" ;
2326 readonly start = new Position ( 0 , 0 ) ;
2427 readonly files = new Set < string > ( ) ;
28+ readonly styles = new Set < string > ( [ this . fixed ] ) ;
2529 readonly cache = new Map < string , Map < string , CompletionItem > > ( ) ;
26- readonly none = "__!NONE!__" ;
2730 readonly isRemote = / ^ h t t p s ? : \/ \/ / i;
2831 readonly canComplete = / ( i d | c l a s s | c l a s s N a m e ) \s * = \s * ( [ " ' ] ) (?: (? ! \2) .) * $ / si;
2932 readonly findLinkRel = / r e l \s * = \s * ( [ " ' ] ) ( (?: (? ! \1) .) + ) \1/ si;
@@ -146,20 +149,25 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
146149 } ) ;
147150 }
148151
149- findDocumentStyles ( text : string ) : Map < string , CompletionItem > {
150- const items = new Map < string , CompletionItem > ( ) ;
151- const findStyles = / < s t y l e [ ^ > ] * > ( [ ^ < ] + ) < \/ s t y l e > / gi;
152+ findDocumentStyles ( text : string ) : Thenable < Set < string > > {
153+ return new Promise ( resolve => {
154+ const items = new Map < string , CompletionItem > ( ) ;
155+ const findStyles = / < s t y l e [ ^ > ] * > ( [ ^ < ] + ) < \/ s t y l e > / gi;
152156
153- let style ;
157+ let style ;
154158
155- while ( ( style = findStyles . exec ( text ) ) !== null ) {
156- this . parseTextToItems ( style [ 1 ] , items ) ;
157- }
159+ while ( ( style = findStyles . exec ( text ) ) !== null ) {
160+ this . parseTextToItems ( style [ 1 ] , items ) ;
161+ }
162+
163+ this . cache . set ( this . fixed , items ) ;
158164
159- return items ;
165+ resolve ( this . styles ) ;
166+ } ) ;
160167 }
161168
162- buildItems ( items : Map < string , CompletionItem > , sets : Set < string > [ ] , type : CompletionItemKind ) : CompletionItem [ ] {
169+ buildItems ( sets : Set < string > [ ] , type : CompletionItemKind ) : CompletionItem [ ] {
170+ const items = new Map < string , CompletionItem > ( ) ;
163171 const keys = new Set < string > ( ) ;
164172
165173 sets . forEach ( v => v . forEach ( v => keys . add ( v ) ) ) ;
@@ -192,13 +200,12 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
192200 ? CompletionItemKind . Value
193201 : CompletionItemKind . Enum ;
194202
195- const items = this . findDocumentStyles ( text ) ;
196-
197203 Promise . all ( [
198204 this . findLocalStyles ( ) ,
199205 this . findDocumentLinks ( text ) ,
206+ this . findDocumentStyles ( text ) ,
200207 this . findRemoteStyles ( document . uri ) ,
201- ] ) . then ( keys => resolve ( this . buildItems ( items , keys , type ) ) ) ;
208+ ] ) . then ( keys => resolve ( this . buildItems ( keys , type ) ) ) ;
202209 } else {
203210 reject ( ) ;
204211 }
0 commit comments