Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Pasero <benjpas@microsoft.com>2020-05-29 14:47:33 +0300
committerBenjamin Pasero <benjpas@microsoft.com>2020-05-29 14:47:33 +0300
commit2b177467e0de7c7c0aa2b33e34f8f8de0bd965f0 (patch)
treea0a2fa2dbb8454d61ea3823aacc27a9cfd22ab13
parent5721d63eb6169bcf8beb87d65aefa0f46431e0c4 (diff)
editors - add option to `whenClosed` for waiting for save too
-rw-r--r--src/vs/workbench/electron-browser/window.ts2
-rw-r--r--src/vs/workbench/services/editor/browser/editorService.ts21
-rw-r--r--src/vs/workbench/services/editor/common/editorService.ts6
-rw-r--r--src/vs/workbench/services/host/browser/browserHostService.ts2
-rw-r--r--src/vs/workbench/test/browser/workbenchTestServices.ts2
5 files changed, 20 insertions, 13 deletions
diff --git a/src/vs/workbench/electron-browser/window.ts b/src/vs/workbench/electron-browser/window.ts
index ca6880ab3ad..595b522cf2f 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<void> {
// Wait for the resources to be closed in the editor...
- await this.editorService.whenClosed(resourcesToWaitFor);
+ await this.editorService.whenClosed(resourcesToWaitFor, { 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 0bf83aaa84e..e59a86c0148 100644
--- a/src/vs/workbench/services/editor/browser/editorService.ts
+++ b/src/vs/workbench/services/editor/browser/editorService.ts
@@ -1157,7 +1157,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
//#region Editor Tracking
- whenClosed(resources: URI[]): Promise<void> {
+ whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise<void> {
let remainingResources = [...resources];
return new Promise(resolve => {
@@ -1175,14 +1175,17 @@ export class EditorService extends Disposable implements EditorServiceImpl {
return true; // keep - not yet closed
});
+ // All resources to wait for being closed are closed
if (remainingResources.length === 0) {
- // 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
- // 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.joinResourceSaved(dirtyFile)));
+ 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
+ // 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)));
+ }
}
listener.dispose();
@@ -1193,7 +1196,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
});
}
- private joinResourceSaved(resource: URI): Promise<void> {
+ private whenSaved(resource: URI): Promise<void> {
return new Promise(resolve => {
if (!this.workingCopyService.isDirty(resource)) {
return resolve(); // return early if resource is not dirty
diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts
index 8a83415835c..788ba75e0f7 100644
--- a/src/vs/workbench/services/editor/common/editorService.ts
+++ b/src/vs/workbench/services/editor/common/editorService.ts
@@ -291,6 +291,10 @@ export interface IEditorService {
/**
* Track the provided list of resources for being opened as editors
* and resolve once 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[]): Promise<void>;
+ whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise<void>;
}
diff --git a/src/vs/workbench/services/host/browser/browserHostService.ts b/src/vs/workbench/services/host/browser/browserHostService.ts
index 3be31c3eb30..e489920d71d 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));
+ await this.editorService.whenClosed(fileOpenables.map(openable => 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 d505f925890..e22fa8458ef 100644
--- a/src/vs/workbench/test/browser/workbenchTestServices.ts
+++ b/src/vs/workbench/test/browser/workbenchTestServices.ts
@@ -670,7 +670,7 @@ export class TestEditorService implements EditorServiceImpl {
saveAll(options?: ISaveEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revert(editors: IEditorIdentifier[], options?: IRevertOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean> { throw new Error('Method not implemented.'); }
- whenClosed(resources: URI[]): Promise<void> { throw new Error('Method not implemented.'); }
+ whenClosed(resources: URI[], options?: { waitForSaved: boolean }): Promise<void> { throw new Error('Method not implemented.'); }
}
export class TestFileService implements IFileService {