@@ -41,6 +41,18 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
4141 } ) ;
4242 }
4343
44+ fetchLocal ( key : string ) : Thenable < string > {
45+ return new Promise ( resolve => {
46+ const items = new Map < string , CompletionItem > ( ) ;
47+
48+ workspace . fs . readFile ( Uri . file ( key ) ) . then ( content => {
49+ this . parseTextToItems ( content . toString ( ) , items ) ;
50+ this . cache . set ( key , items ) ;
51+ resolve ( key ) ;
52+ } , ( ) => resolve ( this . none ) ) ;
53+ } ) ;
54+ }
55+
4456 fetchRemote ( key : string ) : Thenable < string > {
4557 return new Promise ( resolve => {
4658 const items = new Map < string , CompletionItem > ( ) ;
@@ -60,32 +72,18 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
6072 } ) ;
6173 }
6274
63- fetchLocal ( key : string ) : Thenable < string > {
64- return new Promise ( resolve => {
65- const items = new Map < string , CompletionItem > ( ) ;
66-
67- workspace . fs . readFile ( Uri . file ( key ) ) . then ( content => {
68- this . parseTextToItems ( content . toString ( ) , items ) ;
69- this . cache . set ( key , items ) ;
70- resolve ( key ) ;
71- } , ( ) => resolve ( this . none ) ) ;
72- } ) ;
73- }
74-
7575 fetchStyleSheet ( key : string ) : Thenable < string > {
7676 return new Promise ( resolve => {
7777 if ( key === this . none ) {
7878 resolve ( this . none ) ;
79+ } else if ( this . cache . get ( key ) ) {
80+ resolve ( key ) ;
81+ } else if ( key . startsWith ( "/" ) ) {
82+ this . fetchLocal ( key ) . then ( key => resolve ( key ) ) ;
83+ } else if ( this . isRemote . test ( key ) ) {
84+ this . fetchRemote ( key ) . then ( key => resolve ( key ) ) ;
7985 } else {
80- if ( this . cache . get ( key ) ) {
81- resolve ( key ) ;
82- } else if ( this . isRemote . test ( key ) ) {
83- this . fetchRemote ( key ) . then ( key => resolve ( key ) ) ;
84- } else if ( key . startsWith ( "/" ) ) {
85- this . fetchLocal ( key ) . then ( key => resolve ( key ) ) ;
86- } else {
87- resolve ( this . none ) ;
88- }
86+ resolve ( this . none ) ;
8987 }
9088 } ) ;
9189 }
@@ -185,10 +183,11 @@ export class ClassCompletionItemProvider implements CompletionItemProvider {
185183 if ( canComplete ) {
186184 const items = this . findDocumentStyles ( text ) ;
187185
188- this . findLocalStyles ( ) . then ( locals =>
189- this . findRemoteStyles ( document . uri ) . then ( styles =>
190- this . findDocumentLinks ( text ) . then ( links =>
191- resolve ( this . buildItems ( items , styles , links , locals ) ) ) ) ) ;
186+ Promise . all ( [
187+ this . findLocalStyles ( ) ,
188+ this . findDocumentLinks ( text ) ,
189+ this . findRemoteStyles ( document . uri ) ,
190+ ] ) . then ( keys => resolve ( this . buildItems ( items , ...keys ) ) ) ;
192191 } else {
193192 reject ( ) ;
194193 }
0 commit comments