Skip to content
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

Avoid creating multiple clients per project #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ export class ClangdContext implements vscode.Disposable {
const oldActiveProject = this._activeProjectOverride;
this._activeProjectOverride = project;
if (oldActiveProject) {
this.disposeClient(oldActiveProject.id);
this.createClient(oldActiveProject, this.serverOptions!)
}
if (project) {
this.disposeClient(project.id);
this.createClient(project, this.serverOptions!)
}
}
Expand Down Expand Up @@ -162,7 +160,6 @@ export class ClangdContext implements vscode.Disposable {
this.clients.get(this._activeProjectOverride.id)?.dispose();
this._activeProjectOverride = undefined;
} else if (change.updated?.includes(this._activeProjectOverride)) {
this.clients.get(this._activeProjectOverride.id)?.dispose();
this.createClient(this._activeProjectOverride, this.serverOptions!);
}
})
Expand Down Expand Up @@ -317,7 +314,7 @@ export class ClangdContext implements vscode.Disposable {
}
this.disposeClient(activeProject?.id ?? fallbackProjectId);
this.createClient(activeProject, serverOptions);
} else {
} else if (!this.clients.has(project.id)) {
this.createClient(project, serverOptions);
}
}
Expand All @@ -331,7 +328,9 @@ export class ClangdContext implements vscode.Disposable {
// max restart count
config.get<boolean>('restartAfterCrash') ? /*default*/ 4 : 0);
client.registerFeature(new EnableEditsNearCursorFeature);
this.clients.set(project?.id ?? fallbackProjectId, client);
let client_key = project?.id ?? fallbackProjectId;
this.clients.get(client_key)?.dispose();
this.clients.set(client_key, client);
client.start()
return client;
}
Expand Down