Skip to content

Commit

Permalink
fix: listener leak when closing files
Browse files Browse the repository at this point in the history
Fixes #428
  • Loading branch information
connor4312 committed Feb 2, 2024
1 parent e8335bc commit 0a35ffa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
{
"name": "Run Extension",
"type": "extensionHost",
"trace": false,
"request": "launch",
"runtimeExecutable": "${execPath}",
"debugWebviews": true,
Expand All @@ -19,7 +18,7 @@
}
},
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"]
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Run Web Extension",
Expand Down
20 changes: 12 additions & 8 deletions src/fileSystemAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export const accessFile = async (uri: vscode.Uri, untitledDocumentData?: Uint8Ar
// eslint-disable @typescript-eslint/no-var-requires
const fs = require("fs");
const os = require("os");
// eslint-enable @typescript-eslint/no-var-requires
// eslint-enable @typescript-eslint/no-var-requires

const fileStats = await fs.promises.stat(uri.fsPath);
const { uid, gid } = os.userInfo();

const isReadonly: boolean = (uid === -1 || uid === fileStats.uid) ? !(fileStats.mode & 0o200) : // owner
(gid === fileStats.gid) ? !(fileStats.mode & 0o020) : // group
!(fileStats.mode & 0o002); // other
const isReadonly: boolean = (uid === -1 || uid === fileStats.uid) ? !(fileStats.mode & 0o200) : // owner
(gid === fileStats.gid) ? !(fileStats.mode & 0o020) : // group
!(fileStats.mode & 0o002); // other

if (fileStats.isFile()) {
return new NativeFileAccessor(uri, isReadonly, fs);
Expand Down Expand Up @@ -379,13 +379,17 @@ class DebugFileAccessor implements FileAccessor {
}
}

const watchWorkspaceFile = (uri: string, onDidChange: () => void, onDidDelete: () => void) => {
const watchWorkspaceFile = (uri: string, onDidChange: () => void, onDidDelete: () => void): vscode.Disposable => {
const base = uri.split("/");
const fileName = base.pop()!;
const pattern = new vscode.RelativePattern(vscode.Uri.parse(base.join("/")), fileName);

const watcher = vscode.workspace.createFileSystemWatcher(pattern);
watcher.onDidChange(onDidChange);
watcher.onDidDelete(onDidDelete);
return watcher;
const l1 = watcher.onDidChange(onDidChange);
const l2 = watcher.onDidDelete(onDidDelete);
return new vscode.Disposable(() => {
l1.dispose();
l2.dispose();
watcher.dispose();
});
};

0 comments on commit 0a35ffa

Please sign in to comment.