@@ -15,64 +15,58 @@ const completionTriggerChars = ['"', '\'', ' ', '.'];
1515
1616let caching : boolean = false ;
1717
18- function cache ( ) : Promise < void > {
19- return new Promise < void > ( async ( resolve , reject ) : Promise < void > => {
20- try {
21- notifier . notify ( 'eye' , 'Looking for CSS classes in the workspace...' ) ;
18+ async function cache ( ) : Promise < void > {
19+ try {
20+ notifier . notify ( 'eye' , 'Looking for CSS classes in the workspace...' ) ;
2221
23- console . log ( 'Looking for parseable documents...' ) ;
24- let uris : Uri [ ] = await Fetcher . findAllParseableDocuments ( ) ;
22+ console . log ( 'Looking for parseable documents...' ) ;
23+ let uris : Uri [ ] = await Fetcher . findAllParseableDocuments ( ) ;
2524
26- if ( ! uris ) {
27- console . log ( "Found no documents" ) ;
28- notifier . statusBarItem . hide ( ) ;
29- return ;
30- }
31-
32- console . log ( 'Found all parseable documents.' ) ;
33- let definitions : CssClassDefinition [ ] = [ ] ;
25+ if ( ! uris || uris . length === 0 ) {
26+ console . log ( "Found no documents" ) ;
27+ notifier . statusBarItem . hide ( ) ;
28+ return ;
29+ }
3430
35- let filesParsed : number = 0 ;
36- let failedLogs : string = '' ;
37- let failedLogsCount : number = 0 ;
31+ console . log ( 'Found all parseable documents.' ) ;
32+ let definitions : CssClassDefinition [ ] = [ ] ;
3833
39- console . log ( 'Parsing documents and looking for CSS class definitions...' ) ;
34+ let filesParsed : number = 0 ;
35+ let failedLogs : string = '' ;
36+ let failedLogsCount : number = 0 ;
4037
41- try {
42- await Bluebird . map ( uris , async ( uri ) => {
43- try {
44- Array . prototype . push . apply ( definitions , await ParseEngineGateway . callParser ( uri ) ) ;
45- } catch ( error ) {
46- failedLogs += `${ uri . path } \n` ;
47- failedLogsCount ++ ;
48- }
49- filesParsed ++ ;
50- notifier . notify ( 'eye' , 'Looking for CSS classes in the workspace... (' + ( ( filesParsed / uris . length ) * 100 ) . toFixed ( 2 ) + '%)' , false ) ;
51- } , { concurrency : 30 } ) ;
52- } catch ( err ) {
53- console . error ( 'Failed to parse the documents: ' , err ) ;
54- notifier . notify ( 'alert' , 'Failed to cache the CSS classes in the workspace (click for another attempt)' ) ;
55- return reject ( err ) ;
56- }
38+ console . log ( 'Parsing documents and looking for CSS class definitions...' ) ;
5739
58- uniqueDefinitions = _ . uniqBy ( definitions , def => def . className ) ;
40+ try {
41+ await Bluebird . map ( uris , async ( uri ) => {
42+ try {
43+ Array . prototype . push . apply ( definitions , await ParseEngineGateway . callParser ( uri ) ) ;
44+ } catch ( error ) {
45+ failedLogs += `${ uri . path } \n` ;
46+ failedLogsCount ++ ;
47+ }
48+ filesParsed ++ ;
49+ notifier . notify ( 'eye' , 'Looking for CSS classes in the workspace... (' + ( ( filesParsed / uris . length ) * 100 ) . toFixed ( 2 ) + '%)' , false ) ;
50+ } , { concurrency : 30 } ) ;
51+ } catch ( err ) {
52+ notifier . notify ( 'alert' , 'Failed to cache the CSS classes in the workspace (click for another attempt)' ) ;
53+ throw new verror . VError ( err , 'Failed to parse the documents' ) ;
54+ }
5955
60- console . log ( 'Summary:' ) ;
61- console . log ( uris . length , 'parseable documents found' ) ;
62- console . log ( definitions . length , 'CSS class definitions found' ) ;
63- console . log ( uniqueDefinitions . length , 'unique CSS class definitions found' ) ;
64- console . log ( failedLogsCount , 'failed attempts to parse. List of the documents:' ) ;
65- console . log ( failedLogs ) ;
56+ uniqueDefinitions = _ . uniqBy ( definitions , def => def . className ) ;
6657
67- notifier . notify ( 'zap' , 'CSS classes cached (click to cache again)' ) ;
58+ console . log ( 'Summary:' ) ;
59+ console . log ( uris . length , 'parseable documents found' ) ;
60+ console . log ( definitions . length , 'CSS class definitions found' ) ;
61+ console . log ( uniqueDefinitions . length , 'unique CSS class definitions found' ) ;
62+ console . log ( failedLogsCount , 'failed attempts to parse. List of the documents:' ) ;
63+ console . log ( failedLogs ) ;
6864
69- return resolve ( ) ;
70- } catch ( error ) {
71- console . error ( 'Failed to cache the class definitions during the iterations over the documents that were found:' , error ) ;
72- notifier . notify ( 'alert' , 'Failed to cache the CSS classes in the workspace (click for another attempt)' ) ;
73- return reject ( error ) ;
74- }
75- } ) ;
65+ notifier . notify ( 'zap' , 'CSS classes cached (click to cache again)' ) ;
66+ } catch ( err ) {
67+ notifier . notify ( 'alert' , 'Failed to cache the CSS classes in the workspace (click for another attempt)' ) ;
68+ throw new verror . VError ( err , 'Failed to cache the class definitions during the iterations over the documents that were founds' ) ;
69+ }
7670}
7771
7872function provideCompletionItemsGenerator ( languageSelector : string , classMatchRegex : RegExp , classPrefix : string = '' ) {
0 commit comments