From 8f79cfae66c81c1582cdf2b1902b209fe65467bb Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 2 Mar 2020 18:26:16 -0800 Subject: [PATCH] Fix bug with multiroot persistent folder states. (#5042) --- Extension/CHANGELOG.md | 2 +- Extension/src/LanguageServer/client.ts | 5 +++++ Extension/src/LanguageServer/persistentState.ts | 15 ++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index 6c54ab3a09..f744ad0580 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -1,6 +1,6 @@ # C/C++ for Visual Studio Code Change Log -## Version 0.27.0-insiders: March 2, 2019 +## Version 0.27.0-insiders: March 3, 2019 ### Enhancements * Improved multi-root implementation with a single language server process and database for the entire workspace (shared between workspace folders). Fixes most [multi-root bugs](https://github.com/microsoft/vscode-cpptools/issues?q=is%3Aopen+is%3Aissue+label%3A%22Feature%3A+Multiroot%22+label%3A%22fixed+%28release+pending%29%22+milestone%3A0.27.0). * Update to clang-format 9.0.1 (and without shared library dependencies). [#2887](https://github.com/microsoft/vscode-cpptools/issues/2887), [#3174](https://github.com/microsoft/vscode-cpptools/issues/3174) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index e9168c2a10..5caa55049e 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -1336,6 +1336,7 @@ export class DefaultClient implements Client { } } + private registeredProviders: CustomConfigurationProvider1[] = []; public onRegisterCustomConfigurationProvider(provider: CustomConfigurationProvider1): Thenable { let onRegistered: () => void = () => { // version 2 providers control the browse.path. Avoid thrashing the tag parser database by pausing parsing until @@ -1345,6 +1346,10 @@ export class DefaultClient implements Client { } }; return this.notifyWhenReady(() => { + if (this.registeredProviders.includes(provider)) { + return; // Prevent duplicate processing. + } + this.registeredProviders.push(provider); if (!this.RootPath) { return; // There is no c_cpp_properties.json to edit because there is no folder open. } diff --git a/Extension/src/LanguageServer/persistentState.ts b/Extension/src/LanguageServer/persistentState.ts index 2e0b4f0937..0aefeca120 100644 --- a/Extension/src/LanguageServer/persistentState.ts +++ b/Extension/src/LanguageServer/persistentState.ts @@ -6,6 +6,7 @@ import * as util from '../common'; import * as vscode from 'vscode'; +import * as path from 'path'; class PersistentStateBase { private key: string; @@ -51,7 +52,19 @@ export class PersistentWorkspaceState extends PersistentStateBase { export class PersistentFolderState extends PersistentWorkspaceState { constructor(key: string, defaultValue: T, folder: vscode.WorkspaceFolder) { - let newKey: string = key + (folder ? `-${util.getUniqueWorkspaceName(folder)}` : "-untitled"); + // Check for the old (buggy) key. If found, remove it and update the new key with the old value. + let old_key: string = key + (folder ? `-${path.basename(folder.uri.fsPath)}` : "-untitled"); + let old_val: T; + if (util.extensionContext) { + old_val = util.extensionContext.workspaceState.get(old_key); + if (old_val !== undefined) { + util.extensionContext.workspaceState.update(old_key, undefined); + } + } + let newKey: string = key + (folder ? `-${folder.uri.fsPath}` : "-untitled"); super(newKey, defaultValue); + if (old_val !== undefined) { + this.Value = old_val; + } } }