Skip to content

Re-registering file watchers with the same ID will leak the previous registration #1879

Closed

Description

I was updating some code of ours that uses LSP to register file watching dynamically, and was curious what the expected contract is if you register a new set of file watches with the same ID as the previous set of watches: does it give an error (the ID should be unique) or does it update the registration with the new list? It turns out the implementation (linked below) does accept the registration, and will create new watches, but still assumes the ID was unique, and will leak the previous disposables. This appears to be a bug.

The LSP spec seems silent on whether dynamic updates like this are allowed or not.

public register(data: RegistrationData<DidChangeWatchedFilesRegistrationOptions>): void {
if (!Array.isArray(data.registerOptions.watchers)) {
return;
}
const disposables: Disposable[] = [];
for (const watcher of data.registerOptions.watchers) {
const globPattern = this._client.protocol2CodeConverter.asGlobPattern(watcher.globPattern);
if (globPattern === undefined) {
continue;
}
let watchCreate: boolean = true, watchChange: boolean = true, watchDelete: boolean = true;
if (watcher.kind !== undefined && watcher.kind !== null) {
watchCreate = (watcher.kind & WatchKind.Create) !== 0;
watchChange = (watcher.kind & WatchKind.Change) !== 0;
watchDelete = (watcher.kind & WatchKind.Delete) !== 0;
}
const fileSystemWatcher: VFileSystemWatcher = Workspace.createFileSystemWatcher(globPattern, !watchCreate, !watchChange, !watchDelete);
this.hookListeners(fileSystemWatcher, watchCreate, watchChange, watchDelete, disposables);
disposables.push(fileSystemWatcher);
}
this._watchers.set(data.id, disposables);
}

Activity

  1. added this to the milestone on Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions