Skip to content

Commit ec63983

Browse files
committed
Bump version
1 parent e447be3 commit ec63983

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-html-css",
33
"displayName": "HTML CSS Support",
44
"description": "CSS support for HTML documents",
5-
"version": "0.9.4",
5+
"version": "0.9.5",
66
"publisher": "ecmel",
77
"license": "MIT",
88
"homepage": "https://github.com/ecmel/vscode-html-css",

src/extension.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import fetch from "node-fetch";
2+
3+
import { parse, walk } from "css-tree";
4+
15
import {
26
languages,
37
Range,
@@ -13,12 +17,7 @@ import {
1317
CompletionList
1418
} from "vscode";
1519

16-
import {
17-
parse,
18-
walk
19-
} from "css-tree";
20-
21-
import fetch from "node-fetch";
20+
const NONE = "<NONE>";
2221

2322
class ClassCompletionItemProvider implements CompletionItemProvider {
2423

@@ -33,7 +32,8 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
3332
constructor(context: ExtensionContext) {
3433
this.parseRemoteConfig();
3534

36-
context.subscriptions.push(workspace.onDidChangeConfiguration(e => this.parseRemoteConfig()));
35+
context.subscriptions.push(workspace
36+
.onDidChangeConfiguration(e => this.parseRemoteConfig()));
3737
}
3838

3939
parseRemoteConfig() {
@@ -47,6 +47,12 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
4747

4848
fetchRemoteStyleSheet(key: string): Thenable<string> {
4949
return new Promise(resolve => {
50+
51+
if (key === NONE) {
52+
resolve(NONE);
53+
return;
54+
}
55+
5056
const items = this.cache.get(key);
5157

5258
if (items) {
@@ -55,7 +61,7 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
5561
const items = new Map<string, CompletionItem>();
5662

5763
fetch(key).then(res => {
58-
if (res.status === 200) {
64+
if (res.status < 400) {
5965
res.text().then(text => {
6066
walk(parse(text), (node) => {
6167
if (node.type === "ClassSelector") {
@@ -65,12 +71,12 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
6571
this.cache.set(key, items);
6672
resolve(key);
6773
}, () => {
68-
resolve("");
74+
resolve(NONE);
6975
});
7076
} else {
71-
resolve("");
77+
resolve(NONE);
7278
}
73-
}, () => resolve(""));
79+
}, () => resolve(NONE));
7480
}
7581
});
7682
}
@@ -90,7 +96,8 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
9096
const href = this.findLinkHref.exec(link[1]);
9197

9298
if (href && href[2].startsWith("http")) {
93-
promises.push(this.fetchRemoteStyleSheet(href[2]).then(key => keys.add(key)));
99+
promises.push(this.fetchRemoteStyleSheet(href[2])
100+
.then(key => keys.add(key)));
94101
}
95102
}
96103
}
@@ -105,7 +112,8 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
105112
const promises = [];
106113

107114
for (let i = 0; i < this.remoteStyles.length; i++) {
108-
promises.push(this.fetchRemoteStyleSheet(this.remoteStyles[i]).then(key => keys.add(key)));
115+
promises.push(this.fetchRemoteStyleSheet(this.remoteStyles[i])
116+
.then(key => keys.add(key)));
109117
}
110118

111119
Promise.all(promises).then(() => resolve(keys));
@@ -133,7 +141,8 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
133141
document: TextDocument,
134142
position: Position,
135143
token: CancellationToken,
136-
context: CompletionContext): ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
144+
context: CompletionContext)
145+
: ProviderResult<CompletionItem[] | CompletionList<CompletionItem>> {
137146

138147
return new Promise((resolve, reject) => {
139148
const range = new Range(this.start, position);
@@ -147,7 +156,8 @@ class ClassCompletionItemProvider implements CompletionItemProvider {
147156
this.findDocumentLinks(text).then(links => {
148157
links.forEach(key => styles.add(key));
149158

150-
styles.forEach(key => this.cache.get(key)?.forEach((value, name) => items.set(name, value)));
159+
styles.forEach(key => this.cache.get(key)
160+
?.forEach((value, name) => items.set(name, value)));
151161

152162
resolve([...items.values()]);
153163
});

0 commit comments

Comments
 (0)