Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid side effects when parsing edit session payload #179479

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
}

try {
const { changes, conflictingChanges } = await this.generateChanges(editSession, ref, force);
if (changes.length === 0) {
const { changes, conflictingChanges, contributedStateHandlers } = await this.generateChanges(editSession, ref, force);
if (changes.length === 0 && contributedStateHandlers.length === 0) {
return;
}

Expand Down Expand Up @@ -519,6 +519,10 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
}
}

for (const handleContributedState of contributedStateHandlers) {
handleContributedState();
}

this.logService.info(`Deleting edit session with ref ${ref} after successfully applying it to current workspace...`);
await this.editSessionsStorageService.delete(ref);
this.logService.info(`Deleted edit session with ref ${ref}.`);
Expand All @@ -534,6 +538,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo

private async generateChanges(editSession: EditSession, ref: string, force = false) {
const changes: ({ uri: URI; type: ChangeType; contents: string | undefined })[] = [];
const contributedStateHandlers: (() => void)[] = [];
const conflictingChanges = [];
const workspaceFolders = this.contextService.getWorkspace().folders;

Expand Down Expand Up @@ -580,7 +585,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo

if (!folderRoot) {
this.logService.info(`Skipping applying ${folder.workingChanges.length} changes from edit session with ref ${ref} as no matching workspace folder was found.`);
return { changes: [], conflictingChanges: [] };
return { changes: [], conflictingChanges: [], contributedStateHandlers: [] };
}

const localChanges = new Set<string>();
Expand All @@ -604,18 +609,17 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo

const workspaceFolder = folderRoot;
if (workspaceFolder) {
// apply additional state from registered edit session contributors
// look through all registered contributions to gather additional state
EditSessionRegistry.getEditSessionContributions().forEach(([key, contrib]) => {
const state = folder[key];
if (state) {
contrib.resumeState(workspaceFolder, state);
contributedStateHandlers.push(() => contrib.resumeState(workspaceFolder, state));
}
});
}
}

return { changes, conflictingChanges };
return { changes, conflictingChanges, contributedStateHandlers };
}

private async willChangeLocalContents(localChanges: Set<string>, uriWithIncomingChanges: URI, incomingChange: Change) {
Expand Down