diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts index 595b522cf2f4129d63c9889089f7f49d8c662842..c3e6175e88e83293c40e107c48481f1a6b33b856 100644 --- a/src/vs/workbench/electron-browser/window.ts +++ b/src/vs/workbench/electron-browser/window.ts @@ -635,7 +635,7 @@ export class NativeWindow extends Disposable { private async trackClosedWaitFiles(waitMarkerFile: URI, resourcesToWaitFor: URI[]): Promise { // Wait for the resources to be closed in the editor... - await this.editorService.whenClosed(resourcesToWaitFor, { waitForSaved: true }); + await this.editorService.whenClosed(resourcesToWaitFor.map(resource => ({ resource })), { waitForSaved: true }); // ...before deleting the wait marker file await this.fileService.del(waitMarkerFile); diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 61f5979ec139845d797318d9d55900ee897f2c99..f317a3837fb5b7eb8939c74c2a4e6ba0f12d8fed 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -1164,8 +1164,8 @@ export class EditorService extends Disposable implements EditorServiceImpl { //#region Editor Tracking - whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise { - let remainingResources = [...resources]; + whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise { + let remainingEditors = [...editors]; return new Promise(resolve => { const listener = this.onDidCloseEditor(async event => { @@ -1174,8 +1174,8 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Remove from resources to wait for being closed based on the // resources from editors that got closed - remainingResources = remainingResources.filter(resource => { - if (isEqual(resource, masterResource) || isEqual(resource, detailsResource)) { + remainingEditors = remainingEditors.filter(({ resource }) => { + if (this.uriIdentitiyService.extUri.isEqual(resource, masterResource) || this.uriIdentitiyService.extUri.isEqual(resource, detailsResource)) { return false; // remove - the closing editor matches this resource } @@ -1183,15 +1183,15 @@ export class EditorService extends Disposable implements EditorServiceImpl { }); // All resources to wait for being closed are closed - if (remainingResources.length === 0) { + if (remainingEditors.length === 0) { if (options?.waitForSaved) { // If auto save is configured with the default delay (1s) it is possible // to close the editor while the save still continues in the background. As such - // we have to also check if the files to track for are dirty and if so wait + // we have to also check if the editors to track for are dirty and if so wait // for them to get saved. - const dirtyFiles = resources.filter(resource => this.workingCopyService.isDirty(resource)); - if (dirtyFiles.length > 0) { - await Promise.all(dirtyFiles.map(async dirtyFile => await this.whenSaved(dirtyFile))); + const dirtyResources = editors.filter(({ resource }) => this.workingCopyService.isDirty(resource)).map(({ resource }) => resource); + if (dirtyResources.length > 0) { + await Promise.all(dirtyResources.map(async resource => await this.whenSaved(resource))); } } @@ -1211,7 +1211,7 @@ export class EditorService extends Disposable implements EditorServiceImpl { // Otherwise resolve promise when resource is saved const listener = this.workingCopyService.onDidChangeDirty(workingCopy => { - if (!workingCopy.isDirty() && isEqual(resource, workingCopy.resource)) { + if (!workingCopy.isDirty() && this.uriIdentitiyService.extUri.isEqual(resource, workingCopy.resource)) { listener.dispose(); resolve(); @@ -1340,7 +1340,7 @@ export class DelegatingEditorService implements IEditorService { registerCustomEditorViewTypesHandler(source: string, handler: ICustomEditorViewTypesHandler): IDisposable { return this.editorService.registerCustomEditorViewTypesHandler(source, handler); } - whenClosed(resources: URI[]): Promise { return this.editorService.whenClosed(resources); } + whenClosed(editors: IResourceEditorInput[]): Promise { return this.editorService.whenClosed(editors); } //#endregion } diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index b097c437e58de6c35ed34cc7f0f31ee3c2c29e77..72d0841f72cea10ecba929c59c1ee5c7efbd1bc2 100644 --- a/src/vs/workbench/services/editor/common/editorService.ts +++ b/src/vs/workbench/services/editor/common/editorService.ts @@ -289,12 +289,11 @@ export interface IEditorService { revertAll(options?: IRevertAllEditorsOptions): Promise; /** - * Track the provided list of resources for being opened as editors - * and resolve once all have been closed. + * Track the provided editors until all have been closed. * * @param options use `waitForSaved: true` to wait for the resources * being saved. If auto-save is enabled, it may be possible to close * an editor while the save continues in the background. */ - whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise; + whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise; } diff --git a/src/vs/workbench/services/editor/test/browser/editorService.test.ts b/src/vs/workbench/services/editor/test/browser/editorService.test.ts index 7bdf7f8fc493938fb4b3973bd1233b9681b8c47f..31bbd1ebcc434aad399b64a8b7db700af26fc099 100644 --- a/src/vs/workbench/services/editor/test/browser/editorService.test.ts +++ b/src/vs/workbench/services/editor/test/browser/editorService.test.ts @@ -1084,7 +1084,7 @@ suite('EditorService', () => { const editor = await service.openEditor(input1, { pinned: true }); await service.openEditor(input2, { pinned: true }); - const whenClosed = service.whenClosed([input1.resource, input2.resource]); + const whenClosed = service.whenClosed([input1, input2]); editor?.group?.closeAllEditors(); diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts index e489920d71dd813a6dd94bcf134a44c965009458..5c79773a65b045ab18d48bee3b6ce0aaa2b7b109 100644 --- a/src/vs/workbench/services/host/browser/browserHostService.ts +++ b/src/vs/workbench/services/host/browser/browserHostService.ts @@ -224,7 +224,7 @@ export class BrowserHostService extends Disposable implements IHostService { (async () => { // Wait for the resources to be closed in the editor... - await this.editorService.whenClosed(fileOpenables.map(openable => openable.fileUri), { waitForSaved: true }); + await this.editorService.whenClosed(fileOpenables.map(openable => ({ resource: openable.fileUri })), { waitForSaved: true }); // ...before deleting the wait marker file await this.fileService.del(waitMarkerFileURI); diff --git a/src/vs/workbench/test/browser/workbenchTestServices.ts b/src/vs/workbench/test/browser/workbenchTestServices.ts index 59d7730727fe76bdef8458526f0162d5ab5fbdb4..923823a43a45a4909a11857e19b70229f0333ff8 100644 --- a/src/vs/workbench/test/browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/browser/workbenchTestServices.ts @@ -676,7 +676,7 @@ export class TestEditorService implements EditorServiceImpl { saveAll(options?: ISaveEditorsOptions): Promise { throw new Error('Method not implemented.'); } revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise { throw new Error('Method not implemented.'); } revertAll(options?: IRevertAllEditorsOptions): Promise { throw new Error('Method not implemented.'); } - whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise { throw new Error('Method not implemented.'); } + whenClosed(editors: IResourceEditorInput[], options?: { waitForSaved: boolean }): Promise { throw new Error('Method not implemented.'); } } export class TestFileService implements IFileService {