Skip to content

Handle workspace folder removal for test watchers #481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { WorkspaceTracker } from "./project";
import { TaskProvider } from "./taskProvider";
import { configureTelemetry, reporter } from "./telemetry";
import { configureTerminalLinkProvider } from "./terminalLinkProvider";
import { configureTestController } from "./testController";
import {
configureTestController,
handleWorkspaceFolderRemoved as handleTestControllerWorkspaceFolderRemoved,
} from "./testController";
import { testElixir } from "./testElixir";

console.log("ElixirLS: Loading extension");
Expand Down Expand Up @@ -78,6 +81,7 @@ export function activate(context: vscode.ExtensionContext): ElixirLS {
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
for (const folder of event.removed) {
await languageClientManager.handleWorkspaceFolderRemoved(folder);
handleTestControllerWorkspaceFolderRemoved(folder);
}
// we might have closed client for some nested workspace folder child
// reopen all needed
Expand Down
15 changes: 15 additions & 0 deletions src/testController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import type { LanguageClientManager } from "./languageClientManager";
import { type WorkspaceTracker, getProjectDir } from "./project";
import { reporter } from "./telemetry";

const workspaceWatchers = new Map<string, vscode.FileSystemWatcher>();

export function handleWorkspaceFolderRemoved(folder: vscode.WorkspaceFolder) {
const watcher = workspaceWatchers.get(folder.uri.toString());
if (watcher) {
watcher.dispose();
workspaceWatchers.delete(folder.uri.toString());
}
}

export function configureTestController(
context: vscode.ExtensionContext,
languageClientManager: LanguageClientManager,
Expand Down Expand Up @@ -350,6 +360,9 @@ export function configureTestController(

await Promise.all(
outerMostWorkspaceFolders.map(async (workspaceFolder) => {
if (workspaceWatchers.has(workspaceFolder.uri.toString())) {
return workspaceWatchers.get(workspaceFolder.uri.toString());
}
const projectDir = getProjectDir(workspaceFolder);
console.log(
"ElixirLS: registering watcher in",
Expand All @@ -361,6 +374,8 @@ export function configureTestController(
const pattern = new vscode.RelativePattern(projectDir, "**/*_test.exs");
const watcher = vscode.workspace.createFileSystemWatcher(pattern);

workspaceWatchers.set(workspaceFolder.uri.toString(), watcher);

context.subscriptions.push(watcher);

// When files are created, make sure there's a corresponding "file" node in the tree
Expand Down
Loading