Skip to content

Commit 9664f02

Browse files
committed
Fixed watcher bug.
1 parent f89afd6 commit 9664f02

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

CHANGELOG.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
All notable changes to the extension will be documented in this file.
44

5-
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
5+
## [1.3.3] - 2020-12-22
6+
7+
- Fixed watcher bug.
8+
- Fixed cleanup.
69

710
## [1.3.2] - 2020-12-22
811

912
- Update documentation.
10-
- Fixed recursion bug for template inheritance.
11-
- Fixed inheritance RegEx.
13+
14+
## [1.3.1] - 2020-12-22
15+
1216
- Unified path handling.
17+
- Fixed recursion bug for template inheritance.
1318

1419
## [1.3.0] - 2020-12-21
1520

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 Intellisense for HTML",
5-
"version": "1.3.2",
5+
"version": "1.3.3",
66
"publisher": "ecmel",
77
"license": "MIT",
88
"homepage": "https://github.com/ecmel/vscode-html-css",

src/completion.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,34 @@ export class ClassCompletionItemProvider implements CompletionItemProvider, Disp
2323
readonly start = new Position(0, 0);
2424
readonly cache = new Map<string, Map<string, CompletionItem>>();
2525
readonly extends = new Map<string, Set<string>>();
26-
readonly disposables: Disposable[] = [];
26+
readonly watchers = new Map<string, Disposable>();
2727
readonly isRemote = /^https?:\/\//i;
2828
readonly canComplete = /(id|class|className)\s*=\s*(["'])(?:(?!\2).)*$/si;
2929
readonly findLinkRel = /rel\s*=\s*(["'])((?:(?!\1).)+)\1/si;
3030
readonly findLinkHref = /href\s*=\s*(["'])((?:(?!\1).)+)\1/si;
3131
readonly findExtended = /(?:{{\s*<|{%\s*extends)\s*"?([\/\.\\0-9_a-z-A-Z]+)"?\s*(?:%}|}})/i;
3232

3333
dispose() {
34-
let e;
35-
36-
while (e = this.disposables.pop()) {
37-
e.dispose();
34+
for (const wathcer of this.watchers.values()) {
35+
wathcer.dispose();
3836
}
3937

4038
this.cache.clear();
4139
this.extends.clear();
40+
this.watchers.clear();
4241
}
4342

4443
watchFile(uri: Uri, listener: (e: Uri) => any) {
45-
const watcher = workspace.createFileSystemWatcher(uri.fsPath, true);
44+
const key = uri.toString();
45+
46+
if (!this.watchers.has(key)) {
47+
const watcher = workspace.createFileSystemWatcher(uri.fsPath, true);
4648

47-
this.disposables.push(
48-
watcher.onDidChange(listener),
49-
watcher.onDidDelete(listener),
50-
watcher);
49+
watcher.onDidChange(listener);
50+
watcher.onDidDelete(listener);
51+
52+
this.watchers.set(key, watcher);
53+
}
5154
}
5255

5356
getStyleSheets(uri: Uri): string[] {
@@ -253,7 +256,7 @@ export class ClassCompletionItemProvider implements CompletionItemProvider, Disp
253256
const canComplete = this.canComplete.exec(text);
254257

255258
if (canComplete) {
256-
const type = canComplete[1] === "id"
259+
const kind = canComplete[1] === "id"
257260
? CompletionItemKind.Value
258261
: CompletionItemKind.Enum;
259262

@@ -264,7 +267,7 @@ export class ClassCompletionItemProvider implements CompletionItemProvider, Disp
264267
this.findDocumentLinks(uri, text),
265268
this.findDocumentStyles(uri, text),
266269
this.findExtendedStyles(uri, text)
267-
]).then(keys => resolve(this.buildItems(keys, type)));
270+
]).then(keys => resolve(this.buildItems(keys, kind)));
268271
} else {
269272
reject();
270273
}

0 commit comments

Comments
 (0)