@@ -12,39 +12,62 @@ import ParseEngineGateway from './parse-engine-gateway';
12
12
let notifier : Notifier = new Notifier ( 'html-css-class-completion.cache' ) ;
13
13
let uniqueDefinitions : CssClassDefinition [ ] ;
14
14
15
- async function cache ( ) : Promise < void > {
16
- console . log ( 'HTML CSS Class Completion: Looking for CSS classes on the workspace...' ) ;
17
- notifier . notify ( 'eye' , 'Looking for CSS classes on the workspace...' ) ;
18
-
19
- let uris : vscode . Uri [ ] = await Fetcher . findAllParseableDocuments ( ) ;
20
- let definitions : CssClassDefinition [ ] = [ ] ;
21
-
22
- try {
23
- for ( let uri of uris ) {
24
- try {
25
- Array . prototype . push . apply ( definitions , await ParseEngineGateway . callParser ( uri ) ) ;
26
- } catch ( error ) {
27
- console . error ( `HTML CSS Class Completion: Failed to cache css classes from "${ uri } "` ) ;
28
- }
29
- }
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...' ) ;
19
+
20
+ console . log ( 'Looking for parseable documents...' ) ;
21
+ let uris : vscode . Uri [ ] = await Fetcher . findAllParseableDocuments ( ) ;
22
+
23
+ console . log ( 'Found all parseable documents.' ) ;
24
+ let definitions : CssClassDefinition [ ] = [ ] ;
25
+
26
+ let failedLogs : string = '' ;
27
+ let failedLogsCount : number = 0 ;
28
+
29
+ console . log ( 'Parsing documents and looking for CSS class definitions...' ) ;
30
+ return async . each ( uris , async ( uri , callback ) => {
31
+ try {
32
+ Array . prototype . push . apply ( definitions , await ParseEngineGateway . callParser ( uri ) ) ;
33
+ callback ( ) ;
34
+ } catch ( error ) {
35
+ failedLogs += `${ uri . path } \n` ;
36
+ failedLogsCount ++ ;
37
+ callback ( ) ;
38
+ }
39
+ } , ( error ) => {
40
+ if ( error ) {
41
+ console . error ( 'Failed to parse the documents: ' , error ) ;
42
+ return reject ( error ) ;
43
+ }
30
44
31
- uniqueDefinitions = _ . uniqBy ( definitions , ( x ) => x . className ) ;
32
- notifier . notify ( 'zap' , 'CSS classes cached (click to cache again)' ) ;
33
- } catch ( error ) {
34
- console . error ( 'HTML CSS Class Completion: Failed while looping through the documents to cache the classes definitions:' , error ) ;
35
- notifier . notify ( 'alert' , 'Failed to cache the CSS classes on the workspace (click for another attempt)' ) ;
36
- }
37
- }
45
+ uniqueDefinitions = _ . uniqBy ( definitions , ( x ) => x . className ) ;
38
46
39
- function registerCompletionItemProvider ( ) : void {
40
-
47
+ console . log ( 'Sumary:' ) ;
48
+ console . log ( uris . length , 'parseable documents found' ) ;
49
+ console . log ( definitions . length , 'CSS class definitions found' ) ;
50
+ console . log ( uniqueDefinitions . length , 'unique CSS class definitions found' ) ;
51
+ console . log ( failedLogsCount , 'failed attempts to parse. List of the documents:' ) ;
52
+ console . log ( failedLogs ) ;
53
+
54
+ notifier . notify ( 'zap' , 'CSS classes cached (click to cache again)' ) ;
55
+
56
+ return resolve ( ) ;
57
+ } ) ;
58
+ } catch ( error ) {
59
+ console . error ( 'Failed while looping through the documents to cache the classes definitions:' , error ) ;
60
+ notifier . notify ( 'alert' , 'Failed to cache the CSS classes on the workspace (click for another attempt)' ) ;
61
+ return reject ( error ) ;
62
+ }
63
+ } ) ;
41
64
}
42
65
43
66
export async function activate ( context : vscode . ExtensionContext ) : Promise < void > {
44
67
context . subscriptions . push ( vscode . commands . registerCommand ( 'html-css-class-completion.cache' , async ( ) => {
45
68
await cache ( ) ;
46
69
} ) ) ;
47
-
70
+
48
71
await cache ( ) ;
49
72
50
73
context . subscriptions . push ( vscode . languages . registerCompletionItemProvider ( 'html' , {
@@ -98,4 +121,4 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
98
121
export function deactivate ( ) : void {
99
122
}
100
123
101
- // TODO: Look for the CSS classes in case a new file is added to the workspace. I think the API does not provide and event for that. Maybe I should consider opening a PR.
124
+ // TODO: Look for CSS class definitions automatically in case a new file is added to the workspace. I think the API does not provide and event for that. Maybe I should consider opening a PR.
0 commit comments