Skip to content

Commit 1b83b96

Browse files
authored
Save all dirty editors before storing edit session (#165246)
1 parent c36c93a commit 1b83b96

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
5656
import { sha1Hex } from 'vs/base/browser/hash';
5757
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
5858
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
59+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
5960

6061
registerSingleton(IEditSessionsLogService, EditSessionsLogService, InstantiationType.Delayed);
6162
registerSingleton(IEditSessionsStorageService, EditSessionsWorkbenchService, InstantiationType.Delayed);
@@ -117,6 +118,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
117118
@ILifecycleService private readonly lifecycleService: ILifecycleService,
118119
@IStorageService private readonly storageService: IStorageService,
119120
@IActivityService private readonly activityService: IActivityService,
121+
@IEditorService private readonly editorService: IEditorService,
120122
) {
121123
super();
122124

@@ -295,11 +297,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
295297
// Run the store action to get back a ref
296298
let ref: string | undefined;
297299
if (shouldStoreEditSession) {
298-
ref = await that.progressService.withProgress({
299-
location: ProgressLocation.Notification,
300-
type: 'syncing',
301-
title: localize('store your edit session', 'Storing your edit session...')
302-
}, async () => that.storeEditSession(false));
300+
ref = await that.storeEditSession(false);
303301
}
304302

305303
let uri = workspaceUri ?? await that.pickContinueEditSessionDestination();
@@ -408,7 +406,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
408406
} else if (ref !== undefined) {
409407
this.notificationService.warn(localize('no edit session content for ref', 'Could not resume edit session contents for ID {0}.', ref));
410408
}
411-
this.logService.info(ref !== undefined ? `Aborting resuming edit session as no edit session content is available to be applied from ref ${ref}.` : `Aborting resuming edit session as no edit session content is available to be applied`);
409+
this.logService.info(`Aborting resuming edit session as no edit session content is available to be applied from ref ${ref}.`);
412410
return;
413411
}
414412
const editSession = data.editSession;
@@ -562,6 +560,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
562560
const folders: Folder[] = [];
563561
let hasEdits = false;
564562

563+
// Save all saveable editors before building edit session contents
564+
await this.editorService.saveAll();
565+
565566
for (const repository of this.scmService.repositories) {
566567
// Look through all resource groups and compute which files were added/modified/deleted
567568
const trackedUris = this.getChangedResources(repository); // A URI might appear in more than one resource group

src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { IViewDescriptorService } from 'vs/workbench/common/views';
3636
import { ITextModelService } from 'vs/editor/common/services/resolverService';
3737
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
3838
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
39+
import { IEditorService, ISaveAllEditorsOptions } from 'vs/workbench/services/editor/common/editorService';
3940

4041
const folderName = 'test-folder';
4142
const folderUri = URI.file(`/${folderName}`);
@@ -109,6 +110,9 @@ suite('Edit session sync', () => {
109110
instantiationService.stub(ITextModelService, new class extends mock<ITextModelService>() {
110111
override registerTextModelContentProvider = () => ({ dispose: () => { } });
111112
});
113+
instantiationService.stub(IEditorService, new class extends mock<IEditorService>() {
114+
override saveAll = async (_options: ISaveAllEditorsOptions) => true;
115+
});
112116

113117
editSessionsContribution = instantiationService.createInstance(EditSessionsContribution);
114118
});

0 commit comments

Comments
 (0)