Skip to content

Commit 8f79cfa

Browse files
authored
Fix bug with multiroot persistent folder states. (#5042)
1 parent e0253a5 commit 8f79cfa

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

Extension/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# C/C++ for Visual Studio Code Change Log
22

3-
## Version 0.27.0-insiders: March 2, 2019
3+
## Version 0.27.0-insiders: March 3, 2019
44
### Enhancements
55
* 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).
66
* 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)

Extension/src/LanguageServer/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,7 @@ export class DefaultClient implements Client {
13361336
}
13371337
}
13381338

1339+
private registeredProviders: CustomConfigurationProvider1[] = [];
13391340
public onRegisterCustomConfigurationProvider(provider: CustomConfigurationProvider1): Thenable<void> {
13401341
let onRegistered: () => void = () => {
13411342
// 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 {
13451346
}
13461347
};
13471348
return this.notifyWhenReady(() => {
1349+
if (this.registeredProviders.includes(provider)) {
1350+
return; // Prevent duplicate processing.
1351+
}
1352+
this.registeredProviders.push(provider);
13481353
if (!this.RootPath) {
13491354
return; // There is no c_cpp_properties.json to edit because there is no folder open.
13501355
}

Extension/src/LanguageServer/persistentState.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import * as util from '../common';
88
import * as vscode from 'vscode';
9+
import * as path from 'path';
910

1011
class PersistentStateBase<T> {
1112
private key: string;
@@ -51,7 +52,19 @@ export class PersistentWorkspaceState<T> extends PersistentStateBase<T> {
5152

5253
export class PersistentFolderState<T> extends PersistentWorkspaceState<T> {
5354
constructor(key: string, defaultValue: T, folder: vscode.WorkspaceFolder) {
54-
let newKey: string = key + (folder ? `-${util.getUniqueWorkspaceName(folder)}` : "-untitled");
55+
// Check for the old (buggy) key. If found, remove it and update the new key with the old value.
56+
let old_key: string = key + (folder ? `-${path.basename(folder.uri.fsPath)}` : "-untitled");
57+
let old_val: T;
58+
if (util.extensionContext) {
59+
old_val = util.extensionContext.workspaceState.get(old_key);
60+
if (old_val !== undefined) {
61+
util.extensionContext.workspaceState.update(old_key, undefined);
62+
}
63+
}
64+
let newKey: string = key + (folder ? `-${folder.uri.fsPath}` : "-untitled");
5565
super(newKey, defaultValue);
66+
if (old_val !== undefined) {
67+
this.Value = old_val;
68+
}
5669
}
5770
}

0 commit comments

Comments
 (0)