Skip to content

Commit 675720d

Browse files
authored
Fix random failures when adding or removing workspace folders (#10665)
* Fix random failures when adding/removing workspace folders. * Update changelog.
1 parent 646d9cf commit 675720d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Extension/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Fix uncaught exception with some configuration providers. [PR #10629](https://github.com/microsoft/vscode-cpptools/pull/10629)
2222
* Fix bugs with the "You do not have IntelliSense configured" prompt. [#10658](https://github.com/microsoft/vscode-cpptools/issues/10658), [#10659](https://github.com/microsoft/vscode-cpptools/issues/10659)
2323
* Fix `__GXX_RTTI` incorrectly being defined by IntelliSense with clang and `-fms-compatibility`.
24+
* Fix random failures when adding or removing workspace folders.
2425
* Reduce the likelihood of an `onWillSaveWaitUntil` timeout.
2526
* Fix an IntelliSense crash with C++20 concepts.
2627
* Stop querying clang-cl.exe as C.

Extension/src/LanguageServer/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ export interface Client {
791791
dispose(): void;
792792
addFileAssociations(fileAssociations: string, languageId: string): void;
793793
sendDidChangeSettings(): void;
794+
isInitialized(): boolean;
794795
}
795796

796797
export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
@@ -848,6 +849,7 @@ export class DefaultClient implements Client {
848849
public get ReferencesCommandModeChanged(): vscode.Event<refs.ReferencesCommandMode> { return this.model.referencesCommandMode.ValueChanged; }
849850
public get TagParserStatusChanged(): vscode.Event<string> { return this.model.parsingWorkspaceStatus.ValueChanged; }
850851
public get ActiveConfigChanged(): vscode.Event<string> { return this.model.activeConfigName.ValueChanged; }
852+
public isInitialized(): boolean { return this.innerLanguageClient !== undefined; }
851853

852854
/**
853855
* don't use this.rootFolder directly since it can be undefined
@@ -908,6 +910,10 @@ export class DefaultClient implements Client {
908910
clients.forEach(client => {
909911
if (client instanceof DefaultClient) {
910912
const defaultClient: DefaultClient = <DefaultClient>client;
913+
if (!client.isInitialized()) {
914+
// This can randomly get hit when adding/removing workspace folders.
915+
return;
916+
}
911917
defaultClient.configuration.CompilerDefaults = compilerDefaults;
912918
defaultClient.configuration.handleConfigurationChange();
913919
}
@@ -3551,4 +3557,5 @@ class NullClient implements Client {
35513557
}
35523558
addFileAssociations(fileAssociations: string, languageId: string): void { }
35533559
sendDidChangeSettings(): void { }
3560+
isInitialized(): boolean { return true; }
35543561
}

Extension/src/LanguageServer/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ export async function processDelayedDidOpen(document: vscode.TextDocument): Prom
332332
if (!client.TrackedDocuments.has(document)) {
333333
// If not yet tracked, process as a newly opened file. (didOpen is sent to server in client.takeOwnership()).
334334
clients.timeTelemetryCollector.setDidOpenTime(document.uri);
335+
if (!client.isInitialized()) {
336+
// This can randomly get hit when adding/removing workspace folders.
337+
await client.awaitUntilLanguageClientReady();
338+
}
335339
client.TrackedDocuments.add(document);
336340
// Work around vscode treating ".C" or ".H" as c, by adding this file name to file associations as cpp
337341
if (document.languageId === "c" && shouldChangeFromCToCpp(document)) {

0 commit comments

Comments
 (0)