-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathFileSystemRawTreeSitterQueryProvider.ts
More file actions
46 lines (40 loc) · 1.25 KB
/
FileSystemRawTreeSitterQueryProvider.ts
File metadata and controls
46 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {
Notifier,
type Disposable,
type FileSystem,
type IDE,
type RawTreeSitterQueryProvider,
} from "@cursorless/common";
import * as path from "node:path";
import { getCursorlessRepoRoot } from "./getCursorlessRepoRoot";
export class FileSystemRawTreeSitterQueryProvider implements RawTreeSitterQueryProvider {
private queryDir: string;
private notifier: Notifier = new Notifier();
private disposables: Disposable[] = [];
constructor(
ide: IDE,
private fileSystem: FileSystem,
) {
// Use the repo root as the root for development mode, so that we can make
// hot-reloading work for the queries
this.queryDir =
ide.runMode === "development"
? path.join(getCursorlessRepoRoot(), "queries")
: "queries";
if (ide.runMode === "development") {
this.disposables.push(
fileSystem.watchDir(this.queryDir, () => {
this.notifier.notifyListeners();
}),
);
}
}
onChanges = this.notifier.registerListener;
readQuery(filename: string): Promise<string | undefined> {
const queryPath = path.join(this.queryDir, filename);
return this.fileSystem.readBundledFile(queryPath);
}
dispose() {
this.disposables.forEach((disposable) => disposable.dispose());
}
}