From 324751c856a1418e95b47ca9140a6da6f30aa039 Mon Sep 17 00:00:00 2001 From: Beyang Liu Date: Fri, 2 Feb 2024 12:05:04 -0800 Subject: [PATCH] Don't add duplicate workspace folders (#3007) When we receive the initialization message from the client, only add the workspace folders if they don't already exist. Previously, when the agent service lived past the client lifespan, a subsequent client could add a duplicate workspace folder. --- agent/src/vscode-shim.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/agent/src/vscode-shim.ts b/agent/src/vscode-shim.ts index 48fed0c0fd89..c3726605d231 100644 --- a/agent/src/vscode-shim.ts +++ b/agent/src/vscode-shim.ts @@ -158,11 +158,17 @@ let workspaceDocuments: WorkspaceDocuments | undefined export function setWorkspaceDocuments(newWorkspaceDocuments: WorkspaceDocuments): void { workspaceDocuments = newWorkspaceDocuments if (newWorkspaceDocuments.workspaceRootUri) { - workspaceFolders.push({ - name: 'Workspace Root', - uri: newWorkspaceDocuments.workspaceRootUri, - index: 0, - }) + if ( + !workspaceFolders + .map(wf => wf.uri.toString()) + .includes(newWorkspaceDocuments.workspaceRootUri.toString()) + ) { + workspaceFolders.push({ + name: 'Workspace Root', + uri: newWorkspaceDocuments.workspaceRootUri, + index: 0, + }) + } } }