Address issue with `Attempting to use languageClient before initialized` (#12959)

This commit is contained in:
Colen Garoutte-Carson 2024-11-12 16:25:04 -08:00 коммит произвёл GitHub
Родитель 911c39d054
Коммит 9646722501
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 7 добавлений и 13 удалений

Просмотреть файл

@ -1285,6 +1285,12 @@ export class DefaultClient implements Client {
// Listen for messages from the language server.
this.registerNotifications();
// If a file is already open when we activate, sometimes we don't get any notifications about visible
// or active text editors, visible ranges, or text selection. As a workaround, we trigger
// onDidChangeVisibleTextEditors here.
const cppEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => util.isCpp(e.document));
await this.onDidChangeVisibleTextEditors(cppEditors);
}
// update all client configurations

Просмотреть файл

@ -8,7 +8,6 @@ import * as path from 'path';
import * as vscode from 'vscode';
import { Middleware } from 'vscode-languageclient';
import * as util from '../common';
import { logAndReturn } from '../Utility/Async/returns';
import { Client } from './client';
import { clients } from './extension';
import { shouldChangeFromCToCpp } from './utils';
@ -16,8 +15,6 @@ import { shouldChangeFromCToCpp } from './utils';
export const RequestCancelled: number = -32800;
export const ServerCancelled: number = -32802;
let anyFileOpened: boolean = false;
export function createProtocolFilter(): Middleware {
return {
didOpen: async (document, sendMessage) => {
@ -43,16 +40,7 @@ export function createProtocolFilter(): Middleware {
// client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
client.onDidOpenTextDocument(document);
client.takeOwnership(document);
void sendMessage(document).then(() => {
// For a file already open when we activate, sometimes we don't get any notifications about visible
// or active text editors, visible ranges, or text selection. As a workaround, we trigger
// onDidChangeVisibleTextEditors here, only for the first file opened.
if (!anyFileOpened) {
anyFileOpened = true;
const cppEditors: vscode.TextEditor[] = vscode.window.visibleTextEditors.filter(e => util.isCpp(e.document));
client.onDidChangeVisibleTextEditors(cppEditors).catch(logAndReturn.undefined);
}
});
void sendMessage(document);
}
}
},