Skip to content

Commit 4076edd

Browse files
committed
Workaround for webViewPanel.postMessage getting dropped. (#7647)
* Workaround for webViewPanel.postMessage getting dropped.
1 parent 1ad52f9 commit 4076edd

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Extension/src/LanguageServer/configurations.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,14 +1025,21 @@ export class CppProperties {
10251025
if (this.settingsPanel.selectedConfigIndex >= this.configurationJson.configurations.length) {
10261026
this.settingsPanel.selectedConfigIndex = this.CurrentConfigurationIndex;
10271027
}
1028-
setTimeout(() => {
1029-
if (this.settingsPanel && this.configurationJson) {
1030-
this.settingsPanel.updateConfigUI(configNames,
1031-
this.configurationJson.configurations[this.settingsPanel.selectedConfigIndex],
1032-
this.getErrorsForConfigUI(this.settingsPanel.selectedConfigIndex));
1028+
const tryUpdate = () => {
1029+
if (!this.settingsPanel || !this.configurationJson || this.settingsPanel.firstUpdateReceived) {
1030+
return;
10331031
}
1034-
},
1035-
500); // Need some delay or the UI can randomly be blank, particularly in the remote scenario.
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();
10361043
} else {
10371044
// Parse failed, open json file
10381045
vscode.workspace.openTextDocument(this.propertiesFile);

Extension/src/LanguageServer/settingsPanel.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ 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;
78+
7679
constructor() {
7780
this.disposable = vscode.Disposable.from(
7881
this.settingsPanelActivated,
@@ -108,6 +111,8 @@ export class SettingsPanel {
108111
}
109112
);
110113

114+
this.firstUpdateReceived = false;
115+
111116
this.panel.iconPath = vscode.Uri.file(util.getExtensionFilePath("LanguageCCPP_color_128x.png"));
112117

113118
this.disposablesPanel = vscode.Disposable.from(
@@ -250,6 +255,9 @@ export class SettingsPanel {
250255
case 'knownCompilerSelect':
251256
this.knownCompilerSelect();
252257
break;
258+
case 'firstUpdateReceived':
259+
this.firstUpdateReceived = true;
260+
break;
253261
}
254262
}
255263

Extension/ui/settings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ 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+
6770
constructor() {
6871
this.vsCodeApi = acquireVsCodeApi();
6972

@@ -232,6 +235,12 @@ class SettingsApp {
232235
switch (message.command) {
233236
case 'updateConfig':
234237
this.updateConfig(message.config);
238+
239+
if (!this.firstUpdateReceived) {
240+
this.vsCodeApi.postMessage({
241+
command: "firstUpdateReceived"
242+
});
243+
}
235244
break;
236245
case 'updateErrors':
237246
this.updateErrors(message.errors);

0 commit comments

Comments
 (0)