Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function hasTrustedCompilerPaths(): boolean {

// Data shared by all clients.
let languageClient: LanguageClient;
let firstClientStarted: Promise<void>;
let firstClientStarted: Promise<{ wasShutdown: boolean }>;
let languageClientCrashedNeedsRestart: boolean = false;
const languageClientCrashTimes: number[] = [];
let compilerDefaults: configs.CompilerDefaults | undefined;
Expand Down Expand Up @@ -508,6 +508,10 @@ interface CppInitializationParams {
settings: SettingsParams;
}

interface CppInitializationResult {
shouldShutdown: boolean;
}

interface TagParseStatus {
localizeStringParams: LocalizeStringParams;
isPaused: boolean;
Expand Down Expand Up @@ -585,7 +589,7 @@ export interface CopilotCompletionContextParams {

// Requests
const PreInitializationRequest: RequestType<void, string, void> = new RequestType<void, string, void>('cpptools/preinitialize');
const InitializationRequest: RequestType<CppInitializationParams, void, void> = new RequestType<CppInitializationParams, void, void>('cpptools/initialize');
const InitializationRequest: RequestType<CppInitializationParams, CppInitializationResult, void> = new RequestType<CppInitializationParams, CppInitializationResult, void>('cpptools/initialize');
const QueryCompilerDefaultsRequest: RequestType<QueryDefaultCompilerParams, configs.CompilerDefaults, void> = new RequestType<QueryDefaultCompilerParams, configs.CompilerDefaults, void>('cpptools/queryCompilerDefaults');
const SwitchHeaderSourceRequest: RequestType<SwitchHeaderSourceParams, string, void> = new RequestType<SwitchHeaderSourceParams, string, void>('cpptools/didSwitchHeaderSource');
const GetDiagnosticsRequest: RequestType<void, GetDiagnosticsResult, void> = new RequestType<void, GetDiagnosticsResult, void>('cpptools/getDiagnostics');
Expand Down Expand Up @@ -1310,7 +1314,12 @@ export class DefaultClient implements Client {
private async init(rootUri: vscode.Uri | undefined, isFirstClient: boolean) {
ui = getUI();
ui.bind(this);
await firstClientStarted;
if ((await firstClientStarted).wasShutdown) {
this.isSupported = false;
DefaultClient.isStarted.resolve();
return;
}

try {
const workspaceFolder: vscode.WorkspaceFolder | undefined = this.rootFolder;
this.innerConfiguration = new configs.CppProperties(this, rootUri, workspaceFolder);
Expand Down Expand Up @@ -1574,7 +1583,7 @@ export class DefaultClient implements Client {
};
}

private async createLanguageClient(): Promise<void> {
private async createLanguageClient(): Promise<{ wasShutdown: boolean }> {
this.currentCaseSensitiveFileSupport = new PersistentWorkspaceState<boolean>("CPP.currentCaseSensitiveFileSupport", false);
let resetDatabase: boolean = false;
const serverModule: string = getLanguageServerFileName();
Expand Down Expand Up @@ -1707,7 +1716,15 @@ export class DefaultClient implements Client {
// Move initialization to a separate message, so we can see log output from it.
// A request is used in order to wait for completion and ensure that no subsequent
// higher priority message may be processed before the Initialization request.
await languageClient.sendRequest(InitializationRequest, cppInitializationParams);
const initializeResult = await languageClient.sendRequest(InitializationRequest, cppInitializationParams);

// If the server requested shutdown, then reload with the failsafe (null) client.
if (initializeResult.shouldShutdown) {
await languageClient.stop();
await clients.recreateClients(true);
}

return { wasShutdown: initializeResult.shouldShutdown };
}

public async sendDidChangeSettings(): Promise<void> {
Expand Down