From 4076edd843708d35fcb1b7a285fd60097fa1dd1e Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Fri, 4 Jun 2021 14:49:30 -0700 Subject: [PATCH 1/3] Workaround for webViewPanel.postMessage getting dropped. (#7647) * Workaround for webViewPanel.postMessage getting dropped. --- .../src/LanguageServer/configurations.ts | 21 ++++++++++++------- Extension/src/LanguageServer/settingsPanel.ts | 8 +++++++ Extension/ui/settings.ts | 9 ++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Extension/src/LanguageServer/configurations.ts b/Extension/src/LanguageServer/configurations.ts index ad250170ef..4335878738 100644 --- a/Extension/src/LanguageServer/configurations.ts +++ b/Extension/src/LanguageServer/configurations.ts @@ -1025,14 +1025,21 @@ export class CppProperties { if (this.settingsPanel.selectedConfigIndex >= this.configurationJson.configurations.length) { this.settingsPanel.selectedConfigIndex = this.CurrentConfigurationIndex; } - setTimeout(() => { - if (this.settingsPanel && this.configurationJson) { - this.settingsPanel.updateConfigUI(configNames, - this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex], - this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex)); + const tryUpdate = () => { + if (!this.settingsPanel || !this.configurationJson || this.settingsPanel.firstUpdateReceived) { + return; } - }, - 500); // Need some delay or the UI can randomly be blank, particularly in the remote scenario. + this.settingsPanel.updateConfigUI(configNames, + this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex], + this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex)); + + // Need to queue another update due to a VS Code regression bug which may drop the initial update. + // It repros with a higher probability in cases that cause a slower load, such as after + // switching to a Chinese langauge pack or in the remote scenario. + setTimeout(tryUpdate, 500); + }; + this.settingsPanel.firstUpdateReceived = false; + tryUpdate(); } else { // Parse failed, open json file vscode.workspace.openTextDocument(this.propertiesFile); diff --git a/Extension/src/LanguageServer/settingsPanel.ts b/Extension/src/LanguageServer/settingsPanel.ts index c3338781ae..4ba43a463f 100644 --- a/Extension/src/LanguageServer/settingsPanel.ts +++ b/Extension/src/LanguageServer/settingsPanel.ts @@ -73,6 +73,9 @@ export class SettingsPanel { private static readonly viewType: string = 'settingsPanel'; private static readonly title: string = 'C/C++ Configurations'; + // Used to workaround a VS Code bug in which webviewPanel.postMessage calls sometimes get dropped. + public firstUpdateReceived: boolean = false; + constructor() { this.disposable = vscode.Disposable.from( this.settingsPanelActivated, @@ -108,6 +111,8 @@ export class SettingsPanel { } ); + this.firstUpdateReceived = false; + this.panel.iconPath = vscode.Uri.file(util.getExtensionFilePath("LanguageCCPP_color_128x.png")); this.disposablesPanel = vscode.Disposable.from( @@ -250,6 +255,9 @@ export class SettingsPanel { case 'knownCompilerSelect': this.knownCompilerSelect(); break; + case 'firstUpdateReceived': + this.firstUpdateReceived = true; + break; } } diff --git a/Extension/ui/settings.ts b/Extension/ui/settings.ts index 8451859da1..b58123516d 100644 --- a/Extension/ui/settings.ts +++ b/Extension/ui/settings.ts @@ -64,6 +64,9 @@ class SettingsApp { private readonly vsCodeApi: VsCodeApi; private updating: boolean = false; + // Used to workaround a VS Code bug in which webviewPanel.postMessage calls sometimes get dropped. + private firstUpdateReceived: boolean = false; + constructor() { this.vsCodeApi = acquireVsCodeApi(); @@ -232,6 +235,12 @@ class SettingsApp { switch (message.command) { case 'updateConfig': this.updateConfig(message.config); + + if (!this.firstUpdateReceived) { + this.vsCodeApi.postMessage({ + command: "firstUpdateReceived" + }); + } break; case 'updateErrors': this.updateErrors(message.errors); From 623029cc6216cd294436347b7fa0aa3a057ec0db Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 7 Jun 2021 16:02:55 -0700 Subject: [PATCH 2/3] Better fix for settings UI not getting updated. (#7656) * Better fix for settings UI not getting updated. --- .../src/LanguageServer/configurations.ts | 24 +++++++------------ Extension/src/LanguageServer/settingsPanel.ts | 18 ++++++++------ Extension/ui/settings.ts | 12 +++------- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/Extension/src/LanguageServer/configurations.ts b/Extension/src/LanguageServer/configurations.ts index 4335878738..106def41e4 100644 --- a/Extension/src/LanguageServer/configurations.ts +++ b/Extension/src/LanguageServer/configurations.ts @@ -975,7 +975,11 @@ export class CppProperties { const settings: CppSettings = new CppSettings(this.rootUri); this.settingsPanel = new SettingsPanel(); this.settingsPanel.setKnownCompilers(this.knownCompilers, settings.preferredPathSeparator); - this.settingsPanel.SettingsPanelActivated(() => this.onSettingsPanelActivated()); + this.settingsPanel.SettingsPanelActivated(() => { + if (this.settingsPanel?.initialized) { + this.onSettingsPanelActivated(); + } + }); this.settingsPanel.ConfigValuesChanged(() => this.saveConfigurationUI()); this.settingsPanel.ConfigSelectionChanged(() => this.onConfigSelectionChanged()); this.settingsPanel.AddConfigRequested((e) => this.onAddConfigRequested(e)); @@ -1025,21 +1029,9 @@ export class CppProperties { if (this.settingsPanel.selectedConfigIndex >= this.configurationJson.configurations.length) { this.settingsPanel.selectedConfigIndex = this.CurrentConfigurationIndex; } - const tryUpdate = () => { - if (!this.settingsPanel || !this.configurationJson || this.settingsPanel.firstUpdateReceived) { - return; - } - this.settingsPanel.updateConfigUI(configNames, - this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex], - this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex)); - - // Need to queue another update due to a VS Code regression bug which may drop the initial update. - // It repros with a higher probability in cases that cause a slower load, such as after - // switching to a Chinese langauge pack or in the remote scenario. - setTimeout(tryUpdate, 500); - }; - this.settingsPanel.firstUpdateReceived = false; - tryUpdate(); + this.settingsPanel.updateConfigUI(configNames, + this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex], + this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex)); } else { // Parse failed, open json file vscode.workspace.openTextDocument(this.propertiesFile); diff --git a/Extension/src/LanguageServer/settingsPanel.ts b/Extension/src/LanguageServer/settingsPanel.ts index 4ba43a463f..1dc68e5817 100644 --- a/Extension/src/LanguageServer/settingsPanel.ts +++ b/Extension/src/LanguageServer/settingsPanel.ts @@ -73,8 +73,11 @@ export class SettingsPanel { private static readonly viewType: string = 'settingsPanel'; private static readonly title: string = 'C/C++ Configurations'; - // Used to workaround a VS Code bug in which webviewPanel.postMessage calls sometimes get dropped. - public firstUpdateReceived: boolean = false; + // Used to workaround a VS Code 1.56 regression in which webViewPanel.onDidChangeViewState + // gets called before the SettingsApp constructor is finished running. + // It repros with a higher probability in cases that cause a slower load, + // such as after switching to a Chinese language pack or in the remote scenario. + public initialized: boolean = false; constructor() { this.disposable = vscode.Disposable.from( @@ -94,6 +97,8 @@ export class SettingsPanel { return; } + this.initialized = false; + // Create new panel this.panel = vscode.window.createWebviewPanel( SettingsPanel.viewType, @@ -111,8 +116,6 @@ export class SettingsPanel { } ); - this.firstUpdateReceived = false; - this.panel.iconPath = vscode.Uri.file(util.getExtensionFilePath("LanguageCCPP_color_128x.png")); this.disposablesPanel = vscode.Disposable.from( @@ -216,7 +219,7 @@ export class SettingsPanel { private updateWebview(configSelection: string[], configuration: config.Configuration, errors: config.ConfigurationErrors | null): void { this.configValues = {...configuration}; // Copy configuration values this.isIntelliSenseModeDefined = (this.configValues.intelliSenseMode !== undefined); - if (this.panel) { + if (this.panel && this.initialized) { this.panel.webview.postMessage({ command: 'setKnownCompilers', compilers: this.compilerPaths }); this.panel.webview.postMessage({ command: 'updateConfigSelection', selections: configSelection, selectedIndex: this.configIndexSelected }); this.panel.webview.postMessage({ command: 'updateConfig', config: this.configValues }); @@ -255,8 +258,9 @@ export class SettingsPanel { case 'knownCompilerSelect': this.knownCompilerSelect(); break; - case 'firstUpdateReceived': - this.firstUpdateReceived = true; + case "initialized": + this.initialized = true; + this.settingsPanelActivated.fire(); break; } } diff --git a/Extension/ui/settings.ts b/Extension/ui/settings.ts index b58123516d..e184af6097 100644 --- a/Extension/ui/settings.ts +++ b/Extension/ui/settings.ts @@ -64,9 +64,6 @@ class SettingsApp { private readonly vsCodeApi: VsCodeApi; private updating: boolean = false; - // Used to workaround a VS Code bug in which webviewPanel.postMessage calls sometimes get dropped. - private firstUpdateReceived: boolean = false; - constructor() { this.vsCodeApi = acquireVsCodeApi(); @@ -84,6 +81,9 @@ class SettingsApp { document.getElementById(elementId.advancedSection).style.display = advancedShown ? "block" : "none"; document.getElementById(elementId.showAdvanced).classList.toggle(advancedShown ? "collapse" : "expand", true); document.getElementById(elementId.showAdvanced).addEventListener("click", this.onShowAdvanced.bind(this)); + this.vsCodeApi.postMessage({ + command: "initialized" + }); } private addEventsToInputValues(): void { @@ -235,12 +235,6 @@ class SettingsApp { switch (message.command) { case 'updateConfig': this.updateConfig(message.config); - - if (!this.firstUpdateReceived) { - this.vsCodeApi.postMessage({ - command: "firstUpdateReceived" - }); - } break; case 'updateErrors': this.updateErrors(message.errors); From ecfe50be26450691059c1a914882ed6571f3ad41 Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Mon, 7 Jun 2021 17:32:43 -0700 Subject: [PATCH 3/3] Update changelog for 1.4.1. (#7657) * Update changelog for 1.4.1. --- Extension/CHANGELOG.md | 3 +++ Extension/package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Extension/CHANGELOG.md b/Extension/CHANGELOG.md index 36915cfa6a..513fc9dfa7 100644 --- a/Extension/CHANGELOG.md +++ b/Extension/CHANGELOG.md @@ -1,5 +1,8 @@ # C/C++ for Visual Studio Code Change Log +## Version 1.4.1: June 8, 2021 +* Fix the configuration UI sometimes not populating initially with VS Code 1.56 or later. [#7641](https://github.com/microsoft/vscode-cpptools/issues/7641) + ## Version 1.4.0: May 27, 2021 ### New Features * Add a C++ walkthrough to the "Getting Started" page. [#7273](https://github.com/microsoft/vscode-cpptools/issues/7273) diff --git a/Extension/package.json b/Extension/package.json index 5082264a4d..3a1343468c 100644 --- a/Extension/package.json +++ b/Extension/package.json @@ -2,7 +2,7 @@ "name": "cpptools", "displayName": "C/C++", "description": "C/C++ IntelliSense, debugging, and code browsing.", - "version": "1.4.0-main", + "version": "1.4.1-main", "publisher": "ms-vscode", "icon": "LanguageCCPP_color_128x.png", "readme": "README.md",