From 8e8482b52715453def38e7bb644e1259691128e1 Mon Sep 17 00:00:00 2001 From: Colen Garoutte-Carson <49173979+Colengms@users.noreply.github.com> Date: Thu, 14 Jan 2021 18:21:09 -0800 Subject: [PATCH] Fix issue with multiple didOpen (#6784) --- Extension/src/LanguageServer/extension.ts | 2 +- .../src/LanguageServer/protocolFilter.ts | 58 ++++++++++--------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index bc26fe0a27..943f5e5f9b 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -432,10 +432,10 @@ export function processDelayedDidOpen(document: vscode.TextDocument): void { const client: Client = clients.getClientFor(document.uri); if (client) { // Log warm start. - clients.timeTelemetryCollector.setDidOpenTime(document.uri); if (clients.checkOwnership(client, document)) { if (!client.TrackedDocuments.has(document)) { // If not yet tracked, process as a newly opened file. (didOpen is sent to server in client.takeOwnership()). + clients.timeTelemetryCollector.setDidOpenTime(document.uri); client.TrackedDocuments.add(document); const finishDidOpen = (doc: vscode.TextDocument) => { client.provideCustomConfiguration(doc.uri, undefined); diff --git a/Extension/src/LanguageServer/protocolFilter.ts b/Extension/src/LanguageServer/protocolFilter.ts index b76697df40..433d6bdab6 100644 --- a/Extension/src/LanguageServer/protocolFilter.ts +++ b/Extension/src/LanguageServer/protocolFilter.ts @@ -26,40 +26,42 @@ export function createProtocolFilter(clients: ClientCollection): Middleware { didOpen: (document, sendMessage) => { const editor: vscode.TextEditor | undefined = vscode.window.visibleTextEditors.find(e => e.document === document); if (editor) { - // Log warm start. - clients.timeTelemetryCollector.setDidOpenTime(document.uri); // If the file was visible editor when we were activated, we will not get a call to // onDidChangeVisibleTextEditors, so immediately open any file that is visible when we receive didOpen. // Otherwise, we defer opening the file until it's actually visible. const me: Client = clients.getClientFor(document.uri); - if (clients.checkOwnership(me, document)) { - me.TrackedDocuments.add(document); - const finishDidOpen = (doc: vscode.TextDocument) => { - me.provideCustomConfiguration(doc.uri, undefined); - me.notifyWhenReady(() => { - sendMessage(doc); - me.onDidOpenTextDocument(doc); - if (editor && editor === vscode.window.activeTextEditor) { - onDidChangeActiveTextEditor(editor); - } - }); - }; - let languageChanged: boolean = false; - if ((document.uri.path.endsWith(".C") || document.uri.path.endsWith(".H")) && document.languageId === "c") { - const cppSettings: CppSettings = new CppSettings(); - if (cppSettings.autoAddFileAssociations) { - const fileName: string = path.basename(document.uri.fsPath); - const mappingString: string = fileName + "@" + document.uri.fsPath; - me.addFileAssociations(mappingString, false); - me.sendDidChangeSettings({ files: { associations: new OtherSettings().filesAssociations }}); - vscode.languages.setTextDocumentLanguage(document, "cpp").then((newDoc: vscode.TextDocument) => { - finishDidOpen(newDoc); + if (!me.TrackedDocuments.has(document)) { + // Log warm start. + clients.timeTelemetryCollector.setDidOpenTime(document.uri); + if (clients.checkOwnership(me, document)) { + me.TrackedDocuments.add(document); + const finishDidOpen = (doc: vscode.TextDocument) => { + me.provideCustomConfiguration(doc.uri, undefined); + me.notifyWhenReady(() => { + sendMessage(doc); + me.onDidOpenTextDocument(doc); + if (editor && editor === vscode.window.activeTextEditor) { + onDidChangeActiveTextEditor(editor); + } }); - languageChanged = true; + }; + let languageChanged: boolean = false; + if ((document.uri.path.endsWith(".C") || document.uri.path.endsWith(".H")) && document.languageId === "c") { + const cppSettings: CppSettings = new CppSettings(); + if (cppSettings.autoAddFileAssociations) { + const fileName: string = path.basename(document.uri.fsPath); + const mappingString: string = fileName + "@" + document.uri.fsPath; + me.addFileAssociations(mappingString, false); + me.sendDidChangeSettings({ files: { associations: new OtherSettings().filesAssociations }}); + vscode.languages.setTextDocumentLanguage(document, "cpp").then((newDoc: vscode.TextDocument) => { + finishDidOpen(newDoc); + }); + languageChanged = true; + } + } + if (!languageChanged) { + finishDidOpen(document); } - } - if (!languageChanged) { - finishDidOpen(document); } } } else {