Skip to content

Commit

Permalink
Fix bug with multiroot persistent folder states. (#5042)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-mcmanus authored Mar 3, 2020
1 parent e0253a5 commit 8f79cfa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,7 @@ export class DefaultClient implements Client {
}
}

private registeredProviders: CustomConfigurationProvider1[] = [];
public onRegisterCustomConfigurationProvider(provider: CustomConfigurationProvider1): Thenable<void> {
let onRegistered: () => void = () => {
// version 2 providers control the browse.path. Avoid thrashing the tag parser database by pausing parsing until
Expand All @@ -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.
}
Expand Down
15 changes: 14 additions & 1 deletion Extension/src/LanguageServer/persistentState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import * as util from '../common';
import * as vscode from 'vscode';
import * as path from 'path';

class PersistentStateBase<T> {
private key: string;
Expand Down Expand Up @@ -51,7 +52,19 @@ export class PersistentWorkspaceState<T> extends PersistentStateBase<T> {

export class PersistentFolderState<T> extends PersistentWorkspaceState<T> {
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;
}
}
}

0 comments on commit 8f79cfa

Please sign in to comment.