Skip to content

Commit cfa6986

Browse files
authored
Extension host veto is registered multiple times on restart (fix microsoft#183778) (microsoft#184127)
Extension host veto is registered multiple times on restart (microsoft#183778)
1 parent 35da3a2 commit cfa6986

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/vs/workbench/api/browser/mainThreadCustomEditors.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,26 +106,6 @@ export class MainThreadCustomEditors extends Disposable implements extHostProtoc
106106

107107
// Working copy operations
108108
this._register(workingCopyFileService.onWillRunWorkingCopyFileOperation(async e => this.onWillRunWorkingCopyFileOperation(e)));
109-
110-
this._register(extensionService.onWillStop(e => {
111-
const dirtyCustomEditors = workingCopyService.workingCopies.filter(workingCopy => {
112-
return workingCopy instanceof MainThreadCustomEditorModel && workingCopy.isDirty();
113-
});
114-
if (!dirtyCustomEditors.length) {
115-
return;
116-
}
117-
118-
e.veto((async () => {
119-
for (const dirtyCustomEditor of dirtyCustomEditors) {
120-
const didSave = await dirtyCustomEditor.save();
121-
if (!didSave) {
122-
// Veto
123-
return true;
124-
}
125-
}
126-
return false; // Don't veto
127-
})(), localize('vetoExtHostRestart', "One or more custom editors could not be saved."));
128-
}));
129109
}
130110

131111
public $registerTextEditorProvider(extensionData: extHostProtocol.WebviewExtensionDescription, viewType: string, options: extHostProtocol.IWebviewPanelOptions, capabilities: extHostProtocol.CustomTextEditorCapabilities, serializeBuffersForPostMessage: boolean): void {
@@ -399,13 +379,29 @@ class MainThreadCustomEditorModel extends ResourceWorkingCopy implements ICustom
399379
@IWorkbenchEnvironmentService private readonly _environmentService: IWorkbenchEnvironmentService,
400380
@IWorkingCopyService workingCopyService: IWorkingCopyService,
401381
@IPathService private readonly _pathService: IPathService,
382+
@IExtensionService extensionService: IExtensionService,
402383
) {
403384
super(MainThreadCustomEditorModel.toWorkingCopyResource(_viewType, _editorResource), fileService);
404385

405386
this._fromBackup = fromBackup;
406387

407388
if (_editable) {
408389
this._register(workingCopyService.registerWorkingCopy(this));
390+
391+
this._register(extensionService.onWillStop(e => {
392+
if (!this.isDirty()) {
393+
return;
394+
}
395+
396+
e.veto((async () => {
397+
const didSave = await this.save();
398+
if (!didSave) {
399+
// Veto
400+
return true;
401+
}
402+
return false; // Don't veto
403+
})(), localize('vetoExtHostRestart', "Custom editor '{0}' could not be saved.", this.name));
404+
}));
409405
}
410406

411407
// Normally means we're re-opening an untitled file

src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class SimpleNotebookEditorModel extends EditorModel implements INotebookE
7070
return true;
7171
}
7272
return false; // Don't veto
73-
})(), localize('vetoExtHostRestart', "Notebook could not be saved."));
73+
})(), localize('vetoExtHostRestart', "Notebook '{0}' could not be saved.", this._workingCopy?.name));
7474
}));
7575
}
7676

0 commit comments

Comments
 (0)