Skip to content

Commit 4223929

Browse files
authored
Switch file watcher to stop use polling; bump vscode to 1.66.0 (#1945)
- Fixes #1808 - Fixes #1846 ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet
1 parent 3e0370a commit 4223929

File tree

6 files changed

+27
-63
lines changed

6 files changed

+27
-63
lines changed

packages/cursorless-vscode-e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@types/lodash": "4.14.181",
3030
"@types/mocha": "^8.0.4",
3131
"@types/sinon": "^10.0.2",
32-
"@types/vscode": "~1.61.0",
32+
"@types/vscode": "~1.66.0",
3333
"chai": "^4.3.6",
3434
"js-yaml": "^4.1.0",
3535
"mocha": "^10.2.0",

packages/cursorless-vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"homepage": "https://www.cursorless.org/",
3131
"engines": {
32-
"vscode": "^1.61.0"
32+
"vscode": "^1.66.0"
3333
},
3434
"extensionKind": [
3535
"ui",
@@ -1069,7 +1069,7 @@
10691069
"@types/sinon": "^10.0.2",
10701070
"@types/tinycolor2": "1.4.3",
10711071
"@types/uuid": "^8.3.4",
1072-
"@types/vscode": "~1.61.0",
1072+
"@types/vscode": "~1.66.0",
10731073
"chai": "^4.3.6",
10741074
"esbuild": "^0.17.11",
10751075
"fast-xml-parser": "^4.2.5",
Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,17 @@
1-
import {
2-
Disposable,
3-
FileSystem,
4-
PathChangeListener,
5-
walkFiles,
6-
} from "@cursorless/common";
7-
import { stat } from "fs/promises";
8-
import { max } from "lodash";
1+
import { Disposable, FileSystem, PathChangeListener } from "@cursorless/common";
2+
import { RelativePattern, workspace } from "vscode";
93

104
export class VscodeFileSystem implements FileSystem {
115
watchDir(path: string, onDidChange: PathChangeListener): Disposable {
12-
// Just poll for now; we can take advantage of VSCode's sophisticated
13-
// watcher later. Note that we would need to do a version check, as VSCode
14-
// file watcher is only available in more recent versions of VSCode.
15-
return new PollingFileSystemWatcher(path, onDidChange);
16-
}
17-
}
18-
19-
const CHECK_INTERVAL_MS = 1000;
6+
// FIXME: Support globs?
7+
const watcher = workspace.createFileSystemWatcher(
8+
new RelativePattern(path, "**"),
9+
);
2010

21-
class PollingFileSystemWatcher implements Disposable {
22-
private maxMtimeMs: number = -1;
23-
private timer: NodeJS.Timer;
24-
25-
constructor(
26-
private readonly path: string,
27-
private readonly onDidChange: PathChangeListener,
28-
) {
29-
this.checkForChanges = this.checkForChanges.bind(this);
30-
this.timer = setInterval(this.checkForChanges, CHECK_INTERVAL_MS);
31-
}
32-
33-
private async checkForChanges() {
34-
const paths = await walkFiles(this.path);
35-
36-
const maxMtime =
37-
max(
38-
(await Promise.all(paths.map((file) => stat(file)))).map(
39-
(stat) => stat.mtimeMs,
40-
),
41-
) ?? 0;
42-
43-
if (maxMtime > this.maxMtimeMs) {
44-
this.maxMtimeMs = maxMtime;
45-
this.onDidChange();
46-
}
47-
}
11+
watcher.onDidChange(onDidChange);
12+
watcher.onDidCreate(onDidChange);
13+
watcher.onDidDelete(onDidChange);
4814

49-
dispose() {
50-
clearInterval(this.timer);
15+
return watcher;
5116
}
5217
}

packages/cursorless-vscode/src/ide/vscode/hats/VscodeHatRenderer.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,9 @@ function watchDir(
414414
new vscode.RelativePattern(path, `**/*${CURSORLESS_HAT_SHAPES_SUFFIX}`),
415415
);
416416

417-
return vscode.Disposable.from(
418-
hatsDirWatcher,
419-
hatsDirWatcher.onDidChange(onDidChange),
420-
hatsDirWatcher.onDidCreate(onDidChange),
421-
hatsDirWatcher.onDidDelete(onDidChange),
422-
);
417+
hatsDirWatcher.onDidChange(onDidChange);
418+
hatsDirWatcher.onDidCreate(onDidChange);
419+
hatsDirWatcher.onDidDelete(onDidChange);
420+
421+
return hatsDirWatcher;
423422
}

packages/vscode-common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"@cursorless/common": "workspace:*"
1616
},
1717
"devDependencies": {
18-
"@types/vscode": "~1.61.0"
18+
"@types/vscode": "~1.66.0"
1919
},
2020
"types": "./out/index.d.ts",
2121
"exports": {

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)