From f18f3df52e5d7115af5c1406fa89fcef1b651cd5 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Tue, 25 Apr 2023 17:08:25 -0700 Subject: [PATCH 1/3] Prevent the status bar from flickering when switching docs. --- Extension/src/LanguageServer/extension.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 5b2ca2707..237259458 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -291,6 +291,8 @@ function onDidChangeSettings(event: vscode.ConfigurationChangeEvent): void { } } +let noActiveEditorTimeout: NodeJS.Timeout | undefined; + export function onDidChangeActiveTextEditor(editor?: vscode.TextEditor): void { /* need to notify the affected client(s) */ console.assert(clients !== undefined, "client should be available before active editor is changed"); @@ -298,7 +300,23 @@ export function onDidChangeActiveTextEditor(editor?: vscode.TextEditor): void { return; } - if (editor && util.isCppOrRelated(editor.document)) { + if (!editor) { + // When switching between 2 documents, VS Code is setting the active editor to undefined + // temporarily, so this prevents the status bar from flickering. + noActiveEditorTimeout = setTimeout(() => { + activeDocument = ""; + ui.activeDocumentChanged(); + noActiveEditorTimeout = undefined; + }, 100); + return; + } + + if (noActiveEditorTimeout) { + clearTimeout(noActiveEditorTimeout); + noActiveEditorTimeout = undefined; + } + + if (util.isCppOrRelated(editor.document)) { // This is required for the UI to update correctly. clients.activeDocumentChanged(editor.document); if (util.isCpp(editor.document)) { From ddc86d289f170c491b230a01e79519a0032f0255 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Tue, 25 Apr 2023 17:10:35 -0700 Subject: [PATCH 2/3] Update comment. --- Extension/src/LanguageServer/extension.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 237259458..1f361ca92 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -301,8 +301,8 @@ export function onDidChangeActiveTextEditor(editor?: vscode.TextEditor): void { } if (!editor) { - // When switching between 2 documents, VS Code is setting the active editor to undefined - // temporarily, so this prevents the status bar from flickering. + // When switching between documents, VS Code is setting the active editor to undefined + // temporarily, so this prevents the C++-related status bar items from flickering off/on. noActiveEditorTimeout = setTimeout(() => { activeDocument = ""; ui.activeDocumentChanged(); From fde2b3164c7599e4a08dda7999c38bb3ce32d59e Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Tue, 25 Apr 2023 17:23:18 -0700 Subject: [PATCH 3/3] Move code. Clear timers. --- Extension/src/LanguageServer/extension.ts | 10 +++++----- Extension/src/LanguageServer/ui_new.ts | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Extension/src/LanguageServer/extension.ts b/Extension/src/LanguageServer/extension.ts index 1f361ca92..528635b1f 100644 --- a/Extension/src/LanguageServer/extension.ts +++ b/Extension/src/LanguageServer/extension.ts @@ -300,6 +300,11 @@ export function onDidChangeActiveTextEditor(editor?: vscode.TextEditor): void { return; } + if (noActiveEditorTimeout) { + clearTimeout(noActiveEditorTimeout); + noActiveEditorTimeout = undefined; + } + if (!editor) { // When switching between documents, VS Code is setting the active editor to undefined // temporarily, so this prevents the C++-related status bar items from flickering off/on. @@ -311,11 +316,6 @@ export function onDidChangeActiveTextEditor(editor?: vscode.TextEditor): void { return; } - if (noActiveEditorTimeout) { - clearTimeout(noActiveEditorTimeout); - noActiveEditorTimeout = undefined; - } - if (util.isCppOrRelated(editor.document)) { // This is required for the UI to update correctly. clients.activeDocumentChanged(editor.document); diff --git a/Extension/src/LanguageServer/ui_new.ts b/Extension/src/LanguageServer/ui_new.ts index 58c5ba5f4..7fd91c245 100644 --- a/Extension/src/LanguageServer/ui_new.ts +++ b/Extension/src/LanguageServer/ui_new.ts @@ -189,6 +189,7 @@ export class NewUI implements UI { if (this.dbTimeout) { clearTimeout(this.dbTimeout); + this.dbTimeout = undefined; } } else { this.dbTimeout = setTimeout(() => { @@ -276,6 +277,7 @@ export class NewUI implements UI { if (this.dbTimeout) { clearTimeout(this.dbTimeout); + this.dbTimeout = undefined; } } else { this.dbTimeout = setTimeout(() => { @@ -314,6 +316,7 @@ export class NewUI implements UI { if (val) { this.intelliSenseStatusItem.text = "$(flame)"; this.intelliSenseStatusItem.detail = this.updatingIntelliSenseText; + this.flameTimeout = undefined; } else { this.flameTimeout = setTimeout(() => { if (this.intelliSenseStatusItem) {