Skip to content

Commit fce27d0

Browse files
Use a plain Set intead of custom FilePathSet
1 parent f7a72c6 commit fce27d0

3 files changed

Lines changed: 21 additions & 108 deletions

File tree

extensions/ql-vscode/src/common/file-path-set.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

extensions/ql-vscode/src/common/vscode/file-path-discovery.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
import { MultiFileSystemWatcher } from "./multi-file-system-watcher";
1010
import { AppEventEmitter } from "../events";
1111
import { extLogger } from "..";
12-
import { FilePathSet } from "../file-path-set";
1312
import { exists, lstat } from "fs-extra";
1413
import { containsPath } from "../../pure/files";
1514
import { getOnDiskWorkspaceFoldersObjects } from "./workspace-folders";
@@ -30,9 +29,23 @@ interface PathData {
3029
export abstract class FilePathDiscovery<T extends PathData> extends Discovery {
3130
/** The set of known paths we are tracking */
3231
protected paths: T[] = [];
32+
33+
/** Event that fires whenever the set of known paths changes */
3334
protected readonly onDidChangePathsEmitter: AppEventEmitter<void>;
3435

35-
private readonly changedFilePaths = new FilePathSet();
36+
/**
37+
* The set of file paths that may have changed on disk since the last time
38+
* refresh was run. Whenever a watcher reports some change to a file we add
39+
* it to this set, and then during the next refresh we will process all
40+
* file paths from this set and update our internal state to match whatever
41+
* we find on disk (i.e. the file exists, doesn't exist, computed data has
42+
* changed).
43+
*/
44+
private readonly changedFilePaths = new Set<string>();
45+
46+
/**
47+
* Watches for changes to files and directories in all workspace folders.
48+
*/
3649
private readonly watcher: MultiFileSystemWatcher = this.push(
3750
new MultiFileSystemWatcher(),
3851
);
@@ -76,7 +89,7 @@ export abstract class FilePathDiscovery<T extends PathData> extends Discovery {
7689
*/
7790
public async initialRefresh() {
7891
getOnDiskWorkspaceFoldersObjects().forEach((workspaceFolder) => {
79-
this.changedFilePaths.addPath(workspaceFolder.uri.fsPath);
92+
this.changedFilePaths.add(workspaceFolder.uri.fsPath);
8093
});
8194

8295
this.updateWatchers();
@@ -85,10 +98,10 @@ export abstract class FilePathDiscovery<T extends PathData> extends Discovery {
8598

8699
private workspaceFoldersChanged(event: WorkspaceFoldersChangeEvent) {
87100
event.added.forEach((workspaceFolder) => {
88-
this.changedFilePaths.addPath(workspaceFolder.uri.fsPath);
101+
this.changedFilePaths.add(workspaceFolder.uri.fsPath);
89102
});
90103
event.removed.forEach((workspaceFolder) => {
91-
this.changedFilePaths.addPath(workspaceFolder.uri.fsPath);
104+
this.changedFilePaths.add(workspaceFolder.uri.fsPath);
92105
});
93106

94107
this.updateWatchers();
@@ -108,14 +121,14 @@ export abstract class FilePathDiscovery<T extends PathData> extends Discovery {
108121
}
109122

110123
private fileChanged(uri: Uri) {
111-
this.changedFilePaths.addPath(uri.fsPath);
124+
this.changedFilePaths.add(uri.fsPath);
112125
void this.refresh();
113126
}
114127

115128
protected async discover() {
116129
let pathsUpdated = false;
117-
let path: string | undefined;
118-
while ((path = this.changedFilePaths.popPath()) !== undefined) {
130+
for (const path of this.changedFilePaths) {
131+
this.changedFilePaths.delete(path);
119132
if (await this.handledChangedPath(path)) {
120133
pathsUpdated = true;
121134
}

extensions/ql-vscode/test/unit-tests/common/file-path-set.test.ts

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)