Skip to content

Commit

Permalink
save files on accept when alwaysSaveWithGeneratedChanges in on (#23…
Browse files Browse the repository at this point in the history
…7482)

* chore - cleanup, use observable-config

* save files on accept when `alwaysSaveWithGeneratedChanges` in on

microsoft/vscode-copilot#11498
  • Loading branch information
jrieken authored Jan 8, 2025
1 parent 2569d71 commit cfe07a3
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/vs/workbench/contrib/chat/browser/chatEditorSaving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { IStorageService, StorageScope, StorageTarget } from '../../../../platfo
import { IWorkbenchContribution } from '../../../common/contributions.js';
import { IEditorIdentifier, SaveReason } from '../../../common/editor.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { IFilesConfigurationService } from '../../../services/filesConfiguration/common/filesConfigurationService.js';
import { AutoSaveMode, IFilesConfigurationService } from '../../../services/filesConfiguration/common/filesConfigurationService.js';
import { ILifecycleService } from '../../../services/lifecycle/common/lifecycle.js';
import { ITextFileService } from '../../../services/textfile/common/textfiles.js';
import { ChatAgentLocation, IChatAgentService } from '../common/chatAgents.js';
Expand Down Expand Up @@ -116,6 +116,7 @@ export class ChatEditorSaving extends Disposable implements IWorkbenchContributi
@IConfigurationService configService: IConfigurationService,
@IChatEditingService chatEditingService: IChatEditingService,
@IChatAgentService chatAgentService: IChatAgentService,
@IFilesConfigurationService fileConfigService: IFilesConfigurationService,
@ITextFileService textFileService: ITextFileService,
@ILabelService labelService: ILabelService,
@IDialogService dialogService: IDialogService,
Expand All @@ -141,13 +142,11 @@ export class ChatEditorSaving extends Disposable implements IWorkbenchContributi
}));
}));

const store = this._store.add(new DisposableStore());

const update = () => {
const alwaysSaveConfig = observableConfigValue<boolean>(ChatEditorSaving._config, false, configService);
this._store.add(autorunWithStore((r, store) => {

store.clear();
const alwaysSave = alwaysSaveConfig.read(r);

const alwaysSave = configService.getValue<boolean>(ChatEditorSaving._config);
if (alwaysSave) {
return;
}
Expand Down Expand Up @@ -235,14 +234,27 @@ export class ChatEditorSaving extends Disposable implements IWorkbenchContributi
return saveJobs.add(entry.modifiedURI);
}
}));
};
}));

configService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration(ChatEditorSaving._config)) {
update();
// autosave: OFF & alwaysSaveWithAIChanges - save files after accept
this._store.add(autorun(r => {
const saveConfig = fileConfigService.getAutoSaveMode(undefined);
if (saveConfig.mode !== AutoSaveMode.OFF) {
return;
}
});
update();
if (!alwaysSaveConfig.read(r)) {
return;
}
const session = chatEditingService.currentEditingSessionObs.read(r);
if (!session) {
return;
}
for (const entry of session.entries.read(r)) {
if (entry.state.read(r) === WorkingSetEntryState.Accepted) {
textFileService.save(entry.modifiedURI);
}
}
}));
}

private _reportSaved(entry: IModifiedFileEntry) {
Expand Down Expand Up @@ -277,13 +289,11 @@ export class ChatEditorSaving extends Disposable implements IWorkbenchContributi

export class ChatEditingSaveAllAction extends Action2 {
static readonly ID = 'chatEditing.saveAllFiles';
static readonly LABEL = localize('save.allFiles', 'Save All');

constructor() {
super({
id: ChatEditingSaveAllAction.ID,
title: ChatEditingSaveAllAction.LABEL,
tooltip: ChatEditingSaveAllAction.LABEL,
title: localize('save.allFiles', 'Save All'),
precondition: ContextKeyExpr.and(ChatContextKeys.requestInProgress.negate(), hasUndecidedChatEditingResourceContextKey),
icon: Codicon.saveAll,
menu: [
Expand Down

0 comments on commit cfe07a3

Please sign in to comment.