1
1
'use strict' ;
2
2
3
- import * as async from 'async' ;
4
3
import * as _ from 'lodash' ;
5
4
import * as vscode from 'vscode' ;
6
5
import CssClassDefinition from './common/css-class-definition' ;
@@ -12,61 +11,56 @@ import ParseEngineGateway from './parse-engine-gateway';
12
11
let notifier : Notifier = new Notifier ( 'html-css-class-completion.cache' ) ;
13
12
let uniqueDefinitions : CssClassDefinition [ ] ;
14
13
15
- function cache ( ) : Promise < void > {
16
- return new Promise < void > ( async ( resolve , reject ) : Promise < void > => {
17
- try {
18
- notifier . notify ( 'eye' , 'Looking for CSS classes on the workspace...' ) ;
14
+ async function cache ( ) : Promise < void > {
15
+ try {
16
+ notifier . notify ( 'eye' , 'Looking for CSS classes on the workspace...' ) ;
19
17
20
- console . log ( 'Looking for parseable documents...' ) ;
21
- let uris : vscode . Uri [ ] = await Fetcher . findAllParseableDocuments ( ) ;
18
+ console . log ( 'Looking for parseable documents...' ) ;
19
+ let uris : vscode . Uri [ ] = await Fetcher . findAllParseableDocuments ( ) ;
22
20
23
- if ( ! uris ) {
24
- console . log ( "Found no documents" ) ;
25
- notifier . statusBarItem . hide ( ) ;
26
- return ;
27
- }
21
+ if ( ! uris ) {
22
+ console . log ( "Found no documents" ) ;
23
+ notifier . statusBarItem . hide ( ) ;
24
+ return ;
25
+ }
28
26
29
- console . log ( 'Found all parseable documents.' ) ;
30
- let definitions : CssClassDefinition [ ] = [ ] ;
27
+ console . log ( 'Found all parseable documents.' ) ;
28
+ let definitions : CssClassDefinition [ ] = [ ] ;
31
29
32
- let failedLogs : string = '' ;
33
- let failedLogsCount : number = 0 ;
30
+ let failedLogs : string = '' ;
31
+ let failedLogsCount : number = 0 ;
34
32
35
- console . log ( 'Parsing documents and looking for CSS class definitions...' ) ;
36
- return async . each ( uris , async ( uri , callback ) => {
33
+ console . log ( 'Parsing documents and looking for CSS class definitions...' ) ;
34
+
35
+ try {
36
+ await Promise . all ( uris . map ( async ( uri : vscode . Uri ) => {
37
37
try {
38
- Array . prototype . push . apply ( definitions , await ParseEngineGateway . callParser ( uri ) ) ;
39
- callback ( ) ;
38
+ definitions . push ( ...await ParseEngineGateway . callParser ( uri ) )
40
39
} catch ( error ) {
41
40
failedLogs += `${ uri . path } \n` ;
42
41
failedLogsCount ++ ;
43
- callback ( ) ;
44
- }
45
- } , ( error ) => {
46
- if ( error ) {
47
- console . error ( 'Failed to parse the documents: ' , error ) ;
48
- return reject ( error ) ;
49
42
}
50
-
51
- uniqueDefinitions = _ . uniqBy ( definitions , ( x ) => x . className ) ;
52
-
53
- console . log ( 'Sumary:' ) ;
54
- console . log ( uris . length , 'parseable documents found' ) ;
55
- console . log ( definitions . length , 'CSS class definitions found' ) ;
56
- console . log ( uniqueDefinitions . length , 'unique CSS class definitions found' ) ;
57
- console . log ( failedLogsCount , 'failed attempts to parse. List of the documents:' ) ;
58
- console . log ( failedLogs ) ;
59
-
60
- notifier . notify ( 'zap' , 'CSS classes cached (click to cache again)' ) ;
61
-
62
- return resolve ( ) ;
63
- } ) ;
43
+ } ) ) ;
64
44
} catch ( error ) {
65
- console . error ( 'Failed while looping through the documents to cache the classes definitions:' , error ) ;
66
- notifier . notify ( 'alert' , 'Failed to cache the CSS classes on the workspace (click for another attempt)' ) ;
67
- return reject ( error ) ;
45
+ console . error ( 'Failed to parse the documents: ' , error ) ;
46
+ throw error ;
68
47
}
69
- } ) ;
48
+
49
+ uniqueDefinitions = _ . uniqBy ( definitions , ( x : CssClassDefinition ) => x . className ) ;
50
+
51
+ console . log ( 'Sumary:' ) ;
52
+ console . log ( uris . length , 'parseable documents found' ) ;
53
+ console . log ( definitions . length , 'CSS class definitions found' ) ;
54
+ console . log ( uniqueDefinitions . length , 'unique CSS class definitions found' ) ;
55
+ console . log ( failedLogsCount , 'failed attempts to parse. List of the documents:' ) ;
56
+ console . log ( failedLogs ) ;
57
+
58
+ notifier . notify ( 'zap' , 'CSS classes cached (click to cache again)' ) ;
59
+ } catch ( error ) {
60
+ console . error ( 'Failed while looping through the documents to cache the classes definitions:' , error ) ;
61
+ notifier . notify ( 'alert' , 'Failed to cache the CSS classes on the workspace (click for another attempt)' ) ;
62
+ throw error ;
63
+ }
70
64
}
71
65
72
66
export async function activate ( context : vscode . ExtensionContext ) : Promise < void > {
0 commit comments