Skip to content

Commit 623029c

Browse files
committed
Better fix for settings UI not getting updated. (#7656)
* Better fix for settings UI not getting updated.
1 parent 4076edd commit 623029c

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,11 @@ export class CppProperties {
975975
const settings: CppSettings = new CppSettings(this.rootUri);
976976
this.settingsPanel = new SettingsPanel();
977977
this.settingsPanel.setKnownCompilers(this.knownCompilers, settings.preferredPathSeparator);
978-
this.settingsPanel.SettingsPanelActivated(() => this.onSettingsPanelActivated());
978+
this.settingsPanel.SettingsPanelActivated(() => {
979+
if (this.settingsPanel?.initialized) {
980+
this.onSettingsPanelActivated();
981+
}
982+
});
979983
this.settingsPanel.ConfigValuesChanged(() => this.saveConfigurationUI());
980984
this.settingsPanel.ConfigSelectionChanged(() => this.onConfigSelectionChanged());
981985
this.settingsPanel.AddConfigRequested((e) => this.onAddConfigRequested(e));
@@ -1025,21 +1029,9 @@ export class CppProperties {
10251029
if (this.settingsPanel.selectedConfigIndex >= this.configurationJson.configurations.length) {
10261030
this.settingsPanel.selectedConfigIndex = this.CurrentConfigurationIndex;
10271031
}
1028-
const tryUpdate = () => {
1029-
if (!this.settingsPanel || !this.configurationJson || this.settingsPanel.firstUpdateReceived) {
1030-
return;
1031-
}
1032-
this.settingsPanel.updateConfigUI(configNames,
1033-
this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex],
1034-
this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex));
1035-
1036-
// Need to queue another update due to a VS Code regression bug which may drop the initial update.
1037-
// It repros with a higher probability in cases that cause a slower load, such as after
1038-
// switching to a Chinese langauge pack or in the remote scenario.
1039-
setTimeout(tryUpdate, 500);
1040-
};
1041-
this.settingsPanel.firstUpdateReceived = false;
1042-
tryUpdate();
1032+
this.settingsPanel.updateConfigUI(configNames,
1033+
this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex],
1034+
this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex));
10431035
} else {
10441036
// Parse failed, open json file
10451037
vscode.workspace.openTextDocument(this.propertiesFile);

Extension/src/LanguageServer/settingsPanel.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,11 @@ export class SettingsPanel {
7373
private static readonly viewType: string = 'settingsPanel';
7474
private static readonly title: string = 'C/C++ Configurations';
7575

76-
// Used to workaround a VS Code bug in which webviewPanel.postMessage calls sometimes get dropped.
77-
public firstUpdateReceived: boolean = false;
76+
// Used to workaround a VS Code 1.56 regression in which webViewPanel.onDidChangeViewState
77+
// gets called before the SettingsApp constructor is finished running.
78+
// It repros with a higher probability in cases that cause a slower load,
79+
// such as after switching to a Chinese language pack or in the remote scenario.
80+
public initialized: boolean = false;
7881

7982
constructor() {
8083
this.disposable = vscode.Disposable.from(
@@ -94,6 +97,8 @@ export class SettingsPanel {
9497
return;
9598
}
9699

100+
this.initialized = false;
101+
97102
// Create new panel
98103
this.panel = vscode.window.createWebviewPanel(
99104
SettingsPanel.viewType,
@@ -111,8 +116,6 @@ export class SettingsPanel {
111116
}
112117
);
113118

114-
this.firstUpdateReceived = false;
115-
116119
this.panel.iconPath = vscode.Uri.file(util.getExtensionFilePath("LanguageCCPP_color_128x.png"));
117120

118121
this.disposablesPanel = vscode.Disposable.from(
@@ -216,7 +219,7 @@ export class SettingsPanel {
216219
private updateWebview(configSelection: string[], configuration: config.Configuration, errors: config.ConfigurationErrors | null): void {
217220
this.configValues = {...configuration}; // Copy configuration values
218221
this.isIntelliSenseModeDefined = (this.configValues.intelliSenseMode !== undefined);
219-
if (this.panel) {
222+
if (this.panel && this.initialized) {
220223
this.panel.webview.postMessage({ command: 'setKnownCompilers', compilers: this.compilerPaths });
221224
this.panel.webview.postMessage({ command: 'updateConfigSelection', selections: configSelection, selectedIndex: this.configIndexSelected });
222225
this.panel.webview.postMessage({ command: 'updateConfig', config: this.configValues });
@@ -255,8 +258,9 @@ export class SettingsPanel {
255258
case 'knownCompilerSelect':
256259
this.knownCompilerSelect();
257260
break;
258-
case 'firstUpdateReceived':
259-
this.firstUpdateReceived = true;
261+
case "initialized":
262+
this.initialized = true;
263+
this.settingsPanelActivated.fire();
260264
break;
261265
}
262266
}

Extension/ui/settings.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ class SettingsApp {
6464
private readonly vsCodeApi: VsCodeApi;
6565
private updating: boolean = false;
6666

67-
// Used to workaround a VS Code bug in which webviewPanel.postMessage calls sometimes get dropped.
68-
private firstUpdateReceived: boolean = false;
69-
7067
constructor() {
7168
this.vsCodeApi = acquireVsCodeApi();
7269

@@ -84,6 +81,9 @@ class SettingsApp {
8481
document.getElementById(elementId.advancedSection).style.display = advancedShown ? "block" : "none";
8582
document.getElementById(elementId.showAdvanced).classList.toggle(advancedShown ? "collapse" : "expand", true);
8683
document.getElementById(elementId.showAdvanced).addEventListener("click", this.onShowAdvanced.bind(this));
84+
this.vsCodeApi.postMessage({
85+
command: "initialized"
86+
});
8787
}
8888

8989
private addEventsToInputValues(): void {
@@ -235,12 +235,6 @@ class SettingsApp {
235235
switch (message.command) {
236236
case 'updateConfig':
237237
this.updateConfig(message.config);
238-
239-
if (!this.firstUpdateReceived) {
240-
this.vsCodeApi.postMessage({
241-
command: "firstUpdateReceived"
242-
});
243-
}
244238
break;
245239
case 'updateErrors':
246240
this.updateErrors(message.errors);

0 commit comments

Comments
 (0)