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 {