@@ -18,28 +18,22 @@ import {
1818
1919const NONE = "__!NONE!__" ;
2020
21- class ClassCompletionItemProvider implements CompletionItemProvider {
21+ export class ClassCompletionItemProvider implements CompletionItemProvider {
2222
2323 readonly start = new Position ( 0 , 0 ) ;
2424 readonly cache = new Map < string , Map < string , CompletionItem > > ( ) ;
2525 readonly canComplete = / c l a s s \s * = \s * ( [ " ' ] ) (?: (? ! \1) .) * $ / si;
2626 readonly findLinkRel = / r e l \s * = \s * ( [ " ' ] ) ( (?: (? ! \1) .) + ) \1/ si;
2727 readonly findLinkHref = / h r e f \s * = \s * ( [ " ' ] ) ( (?: (? ! \1) .) + ) \1/ si;
2828
29- remoteStyleSheets : string [ ] = [ ] ;
29+ # remoteStyleSheets: string [ ] = [ ] ;
3030
31- constructor ( context : ExtensionContext ) {
32- this . parseConfig ( ) ;
33- context . subscriptions . push ( workspace . onDidChangeConfiguration ( e => this . parseConfig ( ) ) ) ;
31+ get remoteStyleSheets ( ) : string [ ] {
32+ return this . #remoteStyleSheets;
3433 }
3534
36- parseConfig ( ) {
37- const config = workspace . getConfiguration ( "css" ) ;
38- const remoteStyleSheets = config . get < string [ ] > ( "remoteStyleSheets" ) ;
39-
40- if ( remoteStyleSheets ) {
41- this . remoteStyleSheets = remoteStyleSheets ;
42- }
35+ set remoteStyleSheets ( value : string [ ] ) {
36+ this . #remoteStyleSheets = value ;
4337 }
4438
4539 parseTextToItems ( text : string , items : Map < string , CompletionItem > ) {
@@ -111,8 +105,8 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
111105 const keys = new Set < string > ( ) ;
112106 const promises = [ ] ;
113107
114- for ( let i = 0 ; i < this . remoteStyleSheets . length ; i ++ ) {
115- promises . push ( this . fetchRemoteStyleSheet ( this . remoteStyleSheets [ i ] )
108+ for ( let i = 0 ; i < this . # remoteStyleSheets. length ; i ++ ) {
109+ promises . push ( this . fetchRemoteStyleSheet ( this . # remoteStyleSheets[ i ] )
116110 . then ( key => keys . add ( key ) ) ) ;
117111 }
118112
@@ -163,10 +157,22 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
163157 }
164158}
165159
160+ function parseConfig ( provider : ClassCompletionItemProvider ) {
161+ const config = workspace . getConfiguration ( "css" ) ;
162+ const remoteStyleSheets = config . get < string [ ] > ( "remoteStyleSheets" ) ;
163+
164+ if ( remoteStyleSheets ) {
165+ provider . remoteStyleSheets = remoteStyleSheets ;
166+ }
167+ }
168+
166169export function activate ( context : ExtensionContext ) {
167- context . subscriptions . push ( languages
168- . registerCompletionItemProvider ( "html" ,
169- new ClassCompletionItemProvider ( context ) , "\"" , "'" ) ) ;
170+ const provider = new ClassCompletionItemProvider ( ) ;
171+
172+ parseConfig ( provider ) ;
173+
174+ context . subscriptions . push ( workspace . onDidChangeConfiguration ( e => parseConfig ( provider ) ) ) ;
175+ context . subscriptions . push ( languages . registerCompletionItemProvider ( "html" , provider , "\"" , "'" ) ) ;
170176}
171177
172178export function deactivate ( ) { }
0 commit comments