Skip to content

Commit 6cc95c9

Browse files
committed
Added watcherEnabled config
1 parent a4a062c commit 6cc95c9

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

package.json

Lines changed: 7 additions & 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": "1.1.4",
5+
"version": "1.1.5",
66
"publisher": "ecmel",
77
"license": "MIT",
88
"homepage": "https://github.com/ecmel/vscode-html-css",
@@ -53,6 +53,12 @@
5353
"**/node_modules/**"
5454
],
5555
"scope": "window"
56+
},
57+
"css.watcherEnabled": {
58+
"type": "boolean",
59+
"description": "Whether workspace scanning is enabled.",
60+
"default": true,
61+
"scope": "window"
5662
}
5763
}
5864
}

src/extension.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -226,38 +226,42 @@ export function activate(context: ExtensionContext) {
226226
provider,
227227
...triggerCharacters));
228228

229-
const glob = "**/*.css";
230-
const folders = workspace.workspaceFolders?.map(folder => `${folder.uri.fsPath}/${glob}`);
231-
232-
if (folders) {
233-
const ignored = config.get<string[]>("ignoredFolders", ["**/node_modules/**"]);
234-
235-
const watcher = watch(folders, {
236-
ignored,
237-
ignoreInitial: false,
238-
ignorePermissionErrors: true,
239-
useFsEvents: true,
240-
followSymlinks: false
241-
})
242-
.on("add", key => provider.files.add(key))
243-
.on("unlink", key => provider.files.delete(key))
244-
.on("change", key => provider.cache.delete(key));
245-
246-
const changes = workspace.onDidChangeWorkspaceFolders(e => {
247-
e.removed.forEach(folder => {
248-
watcher.unwatch(`${folder.uri.fsPath}/${glob}`);
249-
250-
for (const key of provider.files) {
251-
if (key.startsWith(folder.uri.fsPath)) {
252-
provider.files.delete(key);
229+
const watcherEnabled = config.get<boolean>("watcherEnabled", true);
230+
231+
if (watcherEnabled) {
232+
const glob = "**/*.css";
233+
const folders = workspace.workspaceFolders?.map(folder => `${folder.uri.fsPath}/${glob}`);
234+
235+
if (folders) {
236+
const ignored = config.get<string[]>("ignoredFolders", ["**/node_modules/**"]);
237+
238+
const watcher = watch(folders, {
239+
ignored,
240+
ignoreInitial: false,
241+
ignorePermissionErrors: true,
242+
useFsEvents: true,
243+
followSymlinks: false
244+
})
245+
.on("add", key => provider.files.add(key))
246+
.on("unlink", key => provider.files.delete(key))
247+
.on("change", key => provider.cache.delete(key));
248+
249+
const changes = workspace.onDidChangeWorkspaceFolders(e => {
250+
e.removed.forEach(folder => {
251+
watcher.unwatch(`${folder.uri.fsPath}/${glob}`);
252+
253+
for (const key of provider.files) {
254+
if (key.startsWith(folder.uri.fsPath)) {
255+
provider.files.delete(key);
256+
}
253257
}
254-
}
255-
});
258+
});
256259

257-
e.added.forEach(folder => watcher.add(`${folder.uri.fsPath}/${glob}`));
258-
});
260+
e.added.forEach(folder => watcher.add(`${folder.uri.fsPath}/${glob}`));
261+
});
259262

260-
context.subscriptions.push(changes, { dispose: watcher.close });
263+
context.subscriptions.push(changes, { dispose: watcher.close });
264+
}
261265
}
262266
}
263267

0 commit comments

Comments
 (0)