Skip to content

Commit 7730a7c

Browse files
Bring code actions back
1 parent c7892d5 commit 7730a7c

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

packages/ai-chat/src/browser/change-set-file-element.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { ChangeSetDecoratorService } from './change-set-decorator-service';
3838
import { createChangeSetFileUri } from './change-set-file-resource';
3939
import { ChangeSetFileService } from './change-set-file-service';
4040
import { Deferred } from '@theia/core/lib/common/promise-util';
41+
import { MonacoCodeActionService } from '@theia/monaco/lib/browser';
4142

4243
export const ChangeSetFileElementFactory = Symbol('ChangeSetFileElementFactory');
4344
export type ChangeSetFileElementFactory = (elementProps: ChangeSetElementArgs) => ChangeSetFileElement;
@@ -97,6 +98,9 @@ export class ChangeSetFileElement implements ChangeSetElement {
9798
@inject(FileSystemPreferences)
9899
protected readonly fileSystemPreferences: FileSystemPreferences;
99100

101+
@inject(MonacoCodeActionService)
102+
protected readonly codeActionService: MonacoCodeActionService;
103+
100104
protected readonly toDispose = new DisposableCollection();
101105
protected _state: ChangeSetElementState;
102106

@@ -295,7 +299,9 @@ export class ChangeSetFileElement implements ChangeSetElement {
295299

296300
// Get language and URI for preference lookup
297301
const languageId = tempModel.object.languageId;
298-
const uriStr = tempModel.object.uri.toString();
302+
const uriStr = this.uri.toString();
303+
304+
await this.codeActionService.applyOnSaveCodeActions(tempModel.object.textEditorModel, languageId, uriStr, CancellationToken.None);
299305

300306
const formatOnSave = this.editorPreferences.get({ preferenceName: 'editor.formatOnSave', overrideIdentifier: languageId }, undefined, uriStr);
301307
if (formatOnSave) {

packages/ai-chat/src/common/chat-session-summary-agent-prompt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const CHAT_SESSION_SUMMARY_PROMPT = {
2323
'Ensure that the summary is sufficiently comprehensive to allow seamless continuation of the workflow. ' +
2424
'The summary will primarily be used by other AI agents, so tailor your response for use by AI agents. ' +
2525
'Also consider the system message. ' +
26-
'Make sure you include all necessary context information and use unique references(such as URIs, file paths, etc.). ' +
26+
'Make sure you include all necessary context information and use unique references (such as URIs, file paths, etc.). ' +
2727
'If the conversation was about a task, describe the state of the task, i.e.what has been completed and what is open. ' +
2828
'If a changeset is open in the session, describe the state of the suggested changes. ' +
2929
`\n\n{{${CHANGE_SET_SUMMARY_VARIABLE_ID}}}`,

packages/monaco/src/browser/monaco-code-action-save-participant.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import { SaveOptions, SaveReason } from '@theia/core/lib/browser';
1919
import { MonacoEditor } from './monaco-editor';
2020
import { SaveParticipant, SAVE_PARTICIPANT_DEFAULT_ORDER } from './monaco-editor-provider';
2121
import { inject, injectable } from '@theia/core/shared/inversify';
22-
2322
import { MonacoCodeActionService } from './monaco-code-action-service';
23+
2424
/*---------------------------------------------------------------------------------------------
2525
* Copyright (c) Microsoft Corporation. All rights reserved.
2626
* Licensed under the MIT License. See License.txt in the project root for license information.
@@ -38,22 +38,12 @@ export class MonacoCodeActionSaveParticipant implements SaveParticipant {
3838
return undefined;
3939
}
4040

41-
const codeActionSets = await this.codeActionService.getAllCodeActionsOnSave(
41+
await this.codeActionService.applyOnSaveCodeActions(
4242
editor.document.textEditorModel,
4343
editor.document.textEditorModel.getLanguageId(),
4444
editor.document.textEditorModel.uri.toString(),
4545
cancellationToken
4646
);
47-
48-
if (!codeActionSets) {
49-
return;
50-
}
51-
52-
await this.codeActionService.applyCodeActions(
53-
editor.document.textEditorModel,
54-
codeActionSets,
55-
cancellationToken
56-
);
5747
}
5848

5949
}

packages/monaco/src/browser/monaco-code-action-service.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,33 @@ export interface MonacoCodeActionService {
5353
* @param token Cancellation token
5454
*/
5555
applyCodeActions(model: ITextModel, codeActionSets: CodeActionSet[], token: CancellationToken): Promise<void>;
56+
57+
/**
58+
* Applies all code actions that should be run on save for the given model and language identifier.
59+
* This is a convenience method that retrieves all on-save code actions and applies them.
60+
* @param model The text model to apply code actions to
61+
* @param languageId The language identifier for preference lookup
62+
* @param uri The URI string for preference scoping
63+
* @param token Cancellation token
64+
*/
65+
applyOnSaveCodeActions(model: ITextModel, languageId: string, uri: string, token: CancellationToken): Promise<void>;
5666
}
5767

5868
@injectable()
5969
export class MonacoCodeActionServiceImpl implements MonacoCodeActionService {
6070
@inject(EditorPreferences)
6171
protected readonly editorPreferences: EditorPreferences;
6272

73+
async applyOnSaveCodeActions(model: ITextModel, languageId: string, uri: string, token: CancellationToken): Promise<void> {
74+
const codeActionSets = await this.getAllCodeActionsOnSave(model, languageId, uri, token);
75+
76+
if (!codeActionSets || token.isCancellationRequested) {
77+
return;
78+
}
79+
80+
await this.applyCodeActions(model, codeActionSets, token);
81+
}
82+
6383
async getAllCodeActionsOnSave(model: ITextModel, languageId: string, uri: string, token: CancellationToken): Promise<CodeActionSet[] | undefined> {
6484
const setting = this.editorPreferences.get({
6585
preferenceName: 'editor.codeActionsOnSave',

0 commit comments

Comments
 (0)