Skip to content

Commit

Permalink
Save all dirty editors before storing edit session (microsoft#165246)
Browse files Browse the repository at this point in the history
  • Loading branch information
joyceerhl committed Nov 2, 2022
1 parent c36c93a commit 1b83b96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import * as Constants from 'vs/workbench/contrib/logs/common/logConstants';
import { sha1Hex } from 'vs/base/browser/hash';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { IActivityService, NumberBadge } from 'vs/workbench/services/activity/common/activity';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

registerSingleton(IEditSessionsLogService, EditSessionsLogService, InstantiationType.Delayed);
registerSingleton(IEditSessionsStorageService, EditSessionsWorkbenchService, InstantiationType.Delayed);
Expand Down Expand Up @@ -117,6 +118,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
@ILifecycleService private readonly lifecycleService: ILifecycleService,
@IStorageService private readonly storageService: IStorageService,
@IActivityService private readonly activityService: IActivityService,
@IEditorService private readonly editorService: IEditorService,
) {
super();

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

let uri = workspaceUri ?? await that.pickContinueEditSessionDestination();
Expand Down Expand Up @@ -408,7 +406,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
} else if (ref !== undefined) {
this.notificationService.warn(localize('no edit session content for ref', 'Could not resume edit session contents for ID {0}.', ref));
}
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`);
this.logService.info(`Aborting resuming edit session as no edit session content is available to be applied from ref ${ref}.`);
return;
}
const editSession = data.editSession;
Expand Down Expand Up @@ -562,6 +560,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
const folders: Folder[] = [];
let hasEdits = false;

// Save all saveable editors before building edit session contents
await this.editorService.saveAll();

for (const repository of this.scmService.repositories) {
// Look through all resource groups and compute which files were added/modified/deleted
const trackedUris = this.getChangedResources(repository); // A URI might appear in more than one resource group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { IViewDescriptorService } from 'vs/workbench/common/views';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { ILifecycleService } from 'vs/workbench/services/lifecycle/common/lifecycle';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IEditorService, ISaveAllEditorsOptions } from 'vs/workbench/services/editor/common/editorService';

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

editSessionsContribution = instantiationService.createInstance(EditSessionsContribution);
});
Expand Down

0 comments on commit 1b83b96

Please sign in to comment.