Skip to content

Commit dc8833c

Browse files
committed
WIP
1 parent e42bf01 commit dc8833c

File tree

13 files changed

+90
-21378
lines changed

13 files changed

+90
-21378
lines changed

package.json

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
{
2-
"name": "html-css-class-completion",
3-
"displayName": "HTML CSS Class Completion",
4-
"description": "Provides CSS class name completion for the HTML class attribute based on the CSS files on your workspace.",
5-
"version": "1.0.3",
6-
"publisher": "Zignd",
7-
"engines": {
8-
"vscode": "^1.4.0"
9-
},
10-
"categories": [
11-
"Languages",
12-
"Other"
13-
],
14-
"activationEvents": [
15-
"*"
16-
],
17-
"contributes": {
18-
"commands": [
19-
{
20-
"command": "html-css-class-completion.cache",
21-
"title": "Cache CSS class definitions"
22-
}
23-
]
24-
},
25-
"icon": "images/icon.png",
26-
"repository": {
27-
"url": "https://github.com/Zignd/HTML-CSS-Class-Completion"
28-
},
29-
"main": "./out/src/extension",
30-
"scripts": {
31-
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
32-
"compile": "node ./node_modules/vscode/bin/compile -watch -p ./",
33-
"postinstall": "node ./node_modules/vscode/bin/install"
34-
},
35-
"devDependencies": {
36-
"typescript": "^1.8.5",
37-
"vscode": "^0.11.0"
38-
},
39-
"dependencies": {
40-
"async": "^2.0.1",
41-
"css": "^2.2.1"
42-
}
43-
}
2+
"name": "html-css-class-completion",
3+
"displayName": "HTML CSS Class Completion",
4+
"description": "Provides CSS class name completion for the HTML class attribute based on the CSS files on your workspace.",
5+
"version": "1.0.3",
6+
"publisher": "Zignd",
7+
"engines": {
8+
"vscode": "^1.4.0"
9+
},
10+
"categories": [
11+
"Languages",
12+
"Other"
13+
],
14+
"activationEvents": [
15+
"*"
16+
],
17+
"contributes": {
18+
"commands": [
19+
{
20+
"command": "html-css-class-completion.cache",
21+
"title": "Cache CSS class definitions"
22+
}
23+
]
24+
},
25+
"icon": "images/icon.png",
26+
"repository": {
27+
"url": "https://github.com/Zignd/HTML-CSS-Class-Completion"
28+
},
29+
"main": "./out/src/extension",
30+
"scripts": {
31+
"vscode:prepublish": "tsc -p ./",
32+
"compile": "tsc -watch -p ./",
33+
"postinstall": "node ./node_modules/vscode/bin/install"
34+
},
35+
"devDependencies": {
36+
"@types/css": "^0.0.30",
37+
"@types/lodash": "^4.14.37",
38+
"@types/mocha": "^2.2.32",
39+
"@types/node": "^6.0.40",
40+
"@types/verror": "^1.6.28",
41+
"typescript": "^2.0.3",
42+
"vscode": "^1.0.3"
43+
},
44+
"dependencies": {
45+
"css": "^2.2.1",
46+
"mocha": "^3.1.2",
47+
"verror": "^1.8.1",
48+
"lodash": "^4.16.4"
49+
}
50+
}

src/extension.ts

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
import * as async from 'async';
43
import * as _ from 'lodash';
54
import * as vscode from 'vscode';
65
import CssClassDefinition from './common/css-class-definition';
@@ -12,61 +11,56 @@ import ParseEngineGateway from './parse-engine-gateway';
1211
let notifier: Notifier = new Notifier('html-css-class-completion.cache');
1312
let uniqueDefinitions: CssClassDefinition[];
1413

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...');
1917

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();
2220

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+
}
2826

29-
console.log('Found all parseable documents.');
30-
let definitions: CssClassDefinition[] = [];
27+
console.log('Found all parseable documents.');
28+
let definitions: CssClassDefinition[] = [];
3129

32-
let failedLogs: string = '';
33-
let failedLogsCount: number = 0;
30+
let failedLogs: string = '';
31+
let failedLogsCount: number = 0;
3432

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) => {
3737
try {
38-
Array.prototype.push.apply(definitions, await ParseEngineGateway.callParser(uri));
39-
callback();
38+
definitions.push(...await ParseEngineGateway.callParser(uri))
4039
} catch (error) {
4140
failedLogs += `${uri.path}\n`;
4241
failedLogsCount++;
43-
callback();
44-
}
45-
}, (error) => {
46-
if (error) {
47-
console.error('Failed to parse the documents: ', error);
48-
return reject(error);
4942
}
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+
}));
6444
} 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;
6847
}
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+
}
7064
}
7165

7266
export async function activate(context: vscode.ExtensionContext): Promise<void> {

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"module": "commonjs",
44
"target": "es6",
55
"outDir": "out",
6-
"noLib": true,
6+
"lib": [
7+
"es6"
8+
],
79
"sourceMap": true,
810
"rootDir": ".",
911
"noImplicitAny": true,

typings.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)