Skip to content

Commit 327a492

Browse files
Merge pull request #234 from laravel/performance-investigation
Dispose file watchers on deactivate
2 parents 0f0c343 + 9729104 commit 327a492

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { updateDiagnostics } from "./diagnostic/diagnostic";
1616
import { hoverProviders } from "./hover/HoverProvider";
1717
import { linkProviders } from "./link/LinkProvider";
1818
import { configAffected } from "./support/config";
19+
import { disposeWatchers } from "./support/fileWatcher";
1920
import { info } from "./support/logger";
2021
import { setParserBinaryPath } from "./support/parser";
2122
import { clearDefaultPhpCommand, initVendorWatchers } from "./support/php";
@@ -147,6 +148,8 @@ export function deactivate() {
147148
cleanUpTemp();
148149
}
149150

151+
disposeWatchers();
152+
150153
if (client) {
151154
client.stop();
152155
}

src/support/fileWatcher.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { leadingDebounce } from "./util";
44

55
type FileEvent = "change" | "create" | "delete";
66

7+
let watchers: vscode.FileSystemWatcher[] = [];
8+
79
export type WatcherPattern =
810
| string
911
| string[]
@@ -72,6 +74,17 @@ export const createFileWatcher = (
7274
watcher.onDidDelete(callback);
7375
}
7476

77+
registerWatcher(watcher);
78+
7579
return watcher;
7680
});
7781
};
82+
83+
export const registerWatcher = (watcher: vscode.FileSystemWatcher) => {
84+
watchers.push(watcher);
85+
};
86+
87+
export const disposeWatchers = () => {
88+
watchers.forEach((watcher) => watcher.dispose());
89+
watchers = [];
90+
};

src/support/php.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as cp from "child_process";
33
import * as fs from "fs";
44
import * as vscode from "vscode";
55
import { config, PhpEnvironment } from "./config";
6+
import { registerWatcher } from "./fileWatcher";
67
import { error, info } from "./logger";
78
import { showErrorPopup } from "./popup";
89
import {
@@ -78,6 +79,9 @@ export const initVendorWatchers = () => {
7879
autoloadWatcher.onDidDelete(() => {
7980
hasVendor = false;
8081
});
82+
83+
registerWatcher(watcher);
84+
registerWatcher(autoloadWatcher);
8185
};
8286

8387
const getPhpCommand = (): string => {

0 commit comments

Comments
 (0)