Skip to content

Commit 07b6ccb

Browse files
committed
Address issue with Attempting to use languageClient before initialized
1 parent c9cae0b commit 07b6ccb

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,12 @@ export class DefaultClient implements Client {
16041604
// A request is used in order to wait for completion and ensure that no subsequent
16051605
// higher priority message may be processed before the Initialization request.
16061606
await languageClient.sendRequest(InitializationRequest, cppInitializationParams);
1607+
1608+
// If a file is already open when we activate, sometimes we don't get any notifications about visible
1609+
// or active text editors, visible ranges, or text selection. As a workaround, we trigger
1610+
// onDidChangeVisibleTextEditors here.
1611+
const cppEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => util.isCpp(e.document));
1612+
await this.onDidChangeVisibleTextEditors(cppEditors);
16071613
}
16081614

16091615
public async sendDidChangeSettings(): Promise<void> {

Extension/src/LanguageServer/protocolFilter.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ import * as path from 'path';
88
import * as vscode from 'vscode';
99
import { Middleware } from 'vscode-languageclient';
1010
import * as util from '../common';
11-
import { logAndReturn } from '../Utility/Async/returns';
1211
import { Client } from './client';
1312
import { clients } from './extension';
1413
import { shouldChangeFromCToCpp } from './utils';
1514

1615
export const RequestCancelled: number = -32800;
1716
export const ServerCancelled: number = -32802;
1817

19-
let anyFileOpened: boolean = false;
20-
2118
export function createProtocolFilter(): Middleware {
2219
return {
2320
didOpen: async (document, sendMessage) => {
@@ -43,16 +40,7 @@ export function createProtocolFilter(): Middleware {
4340
// client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
4441
client.onDidOpenTextDocument(document);
4542
client.takeOwnership(document);
46-
void sendMessage(document).then(() => {
47-
// For a file already open when we activate, sometimes we don't get any notifications about visible
48-
// or active text editors, visible ranges, or text selection. As a workaround, we trigger
49-
// onDidChangeVisibleTextEditors here, only for the first file opened.
50-
if (!anyFileOpened) {
51-
anyFileOpened = true;
52-
const cppEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => util.isCpp(e.document));
53-
client.onDidChangeVisibleTextEditors(cppEditors).catch(logAndReturn.undefined);
54-
}
55-
});
43+
void sendMessage(document);
5644
}
5745
}
5846
},

0 commit comments

Comments
 (0)