Skip to content

Commit f05f54e

Browse files
authored
Support command in inline chat followup (microsoft#202634)
1 parent 80f7da8 commit f05f54e

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ export type IInlineChatResponseDto = Dto<IInlineChatEditResponse | Omit<IInlineC
12331233
export interface ExtHostInlineChatShape {
12341234
$prepareSession(handle: number, uri: UriComponents, range: ISelection, token: CancellationToken): Promise<IInlineChatSession | undefined>;
12351235
$provideResponse(handle: number, session: IInlineChatSession, request: IInlineChatRequest, token: CancellationToken): Promise<IInlineChatResponseDto | undefined>;
1236-
$provideFollowups(handle: number, sessionId: number, responseId: number, token: CancellationToken): Promise<IChatReplyFollowup[] | undefined>;
1236+
$provideFollowups(handle: number, sessionId: number, responseId: number, token: CancellationToken): Promise<IChatFollowup[] | undefined>;
12371237
$handleFeedback(handle: number, sessionId: number, responseId: number, kind: InlineChatResponseFeedbackKind): void;
12381238
$releaseSession(handle: number, sessionId: number): void;
12391239
}

src/vs/workbench/api/common/extHostInlineChat.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ApiCommand, ApiCommandArgument, ApiCommandResult, ExtHostCommands } fro
1919
import { IRange } from 'vs/editor/common/core/range';
2020
import { IPosition } from 'vs/editor/common/core/position';
2121
import { raceCancellation } from 'vs/base/common/async';
22-
import { IChatReplyFollowup } from 'vs/workbench/contrib/chat/common/chatService';
22+
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
2323

2424
class ProviderWrapper {
2525

@@ -227,14 +227,14 @@ export class ExtHostInteractiveEditor implements ExtHostInlineChatShape {
227227
}
228228
}
229229

230-
async $provideFollowups(handle: number, sessionId: number, responseId: number, token: CancellationToken): Promise<IChatReplyFollowup[] | undefined> {
230+
async $provideFollowups(handle: number, sessionId: number, responseId: number, token: CancellationToken): Promise<IChatFollowup[] | undefined> {
231231
const entry = this._inputProvider.get(handle);
232232
const sessionData = this._inputSessions.get(sessionId);
233233
const response = sessionData?.responses[responseId];
234234
if (entry && response && entry.provider.provideFollowups) {
235235
const task = Promise.resolve(entry.provider.provideFollowups(sessionData.session, response, token));
236236
const followups = await raceCancellation(task, token);
237-
return followups?.map(typeConvert.ChatReplyFollowup.from);
237+
return followups?.map(typeConvert.ChatFollowup.from);
238238
}
239239
return undefined;
240240
}

src/vs/workbench/contrib/inlineChat/browser/inlineChatController.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { IInlineChatSessionService } from './inlineChatSessionService';
4545
import { EditModeStrategy, LivePreviewStrategy, LiveStrategy, PreviewStrategy, ProgressingEditsOptions } from 'vs/workbench/contrib/inlineChat/browser/inlineChatStrategies';
4646
import { IInlineChatMessageAppender, InlineChatZoneWidget } from 'vs/workbench/contrib/inlineChat/browser/inlineChatWidget';
4747
import { CTX_INLINE_CHAT_DID_EDIT, CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST, CTX_INLINE_CHAT_LAST_FEEDBACK, CTX_INLINE_CHAT_RESPONSE_TYPES, CTX_INLINE_CHAT_SUPPORT_ISSUE_REPORTING, CTX_INLINE_CHAT_USER_DID_EDIT, EditMode, IInlineChatProgressItem, IInlineChatRequest, IInlineChatResponse, INLINE_CHAT_ID, InlineChatConfigKeys, InlineChatResponseFeedbackKind, InlineChatResponseTypes } from 'vs/workbench/contrib/inlineChat/common/inlineChat';
48+
import { ICommandService } from 'vs/platform/commands/common/commands';
4849

4950
export const enum State {
5051
CREATE_SESSION = 'CREATE_SESSION',
@@ -143,6 +144,7 @@ export class InlineChatController implements IEditorContribution {
143144
@IChatAgentService private readonly _chatAgentService: IChatAgentService,
144145
@IBulkEditService private readonly _bulkEditService: IBulkEditService,
145146
@IStorageService private readonly _storageService: IStorageService,
147+
@ICommandService private readonly _commandService: ICommandService,
146148
) {
147149
this._ctxHasActiveRequest = CTX_INLINE_CHAT_HAS_ACTIVE_REQUEST.bindTo(contextKeyService);
148150
this._ctxDidEdit = CTX_INLINE_CHAT_DID_EDIT.bindTo(contextKeyService);
@@ -788,8 +790,12 @@ export class InlineChatController implements IEditorContribution {
788790
if (followupReply && this._session) {
789791
this._log('followup request received', this._session.provider.debugName, this._session.session, followupReply);
790792
this._zone.value.widget.updateFollowUps(followupReply, followup => {
791-
this.updateInput(followup.message);
792-
this.acceptInput();
793+
if (followup.kind === 'reply') {
794+
this.updateInput(followup.message);
795+
this.acceptInput();
796+
} else {
797+
this._commandService.executeCommand(followup.commandId, ...(followup.args ?? []));
798+
}
793799
});
794800
}
795801
}).finally(() => {

src/vs/workbench/contrib/inlineChat/browser/inlineChatWidget.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import { ILogService } from 'vs/platform/log/common/log';
6464
import { ChatListItemRenderer, IChatListItemRendererOptions, IChatRendererDelegate } from 'vs/workbench/contrib/chat/browser/chatListRenderer';
6565
import { IUntitledTextEditorModel } from 'vs/workbench/services/untitled/common/untitledTextEditorModel';
6666
import { ITextModelService } from 'vs/editor/common/services/resolverService';
67-
import { IChatReplyFollowup } from 'vs/workbench/contrib/chat/common/chatService';
67+
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
6868
import { IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
6969
import { ChatFollowups } from 'vs/workbench/contrib/chat/browser/chatFollowups';
7070

@@ -635,9 +635,9 @@ export class InlineChatWidget {
635635
return resultingAppender;
636636
}
637637

638-
updateFollowUps(items: IChatReplyFollowup[], onFollowup: (followup: IChatReplyFollowup) => void): void;
638+
updateFollowUps(items: IChatFollowup[], onFollowup: (followup: IChatFollowup) => void): void;
639639
updateFollowUps(items: undefined): void;
640-
updateFollowUps(items: IChatReplyFollowup[] | undefined, onFollowup?: ((followup: IChatReplyFollowup) => void)) {
640+
updateFollowUps(items: IChatFollowup[] | undefined, onFollowup?: ((followup: IChatFollowup) => void)) {
641641
this._followUpDisposables.clear();
642642
this._elements.followUps.classList.toggle('hidden', !items || items.length === 0);
643643
reset(this._elements.followUps);

src/vs/workbench/contrib/inlineChat/common/inlineChat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { IProgress } from 'vs/platform/progress/common/progress';
2020
import { Registry } from 'vs/platform/registry/common/platform';
2121
import { diffInserted, diffRemoved, editorHoverHighlight, editorWidgetBackground, editorWidgetBorder, focusBorder, inputBackground, inputPlaceholderForeground, registerColor, transparent, widgetShadow } from 'vs/platform/theme/common/colorRegistry';
2222
import { Extensions as ExtensionsMigration, IConfigurationMigrationRegistry } from 'vs/workbench/common/configuration';
23-
import { IChatReplyFollowup } from 'vs/workbench/contrib/chat/common/chatService';
23+
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
2424

2525
export interface IInlineChatSlashCommand {
2626
command: string;
@@ -106,7 +106,7 @@ export interface IInlineChatSessionProvider {
106106

107107
provideResponse(item: IInlineChatSession, request: IInlineChatRequest, progress: IProgress<IInlineChatProgressItem>, token: CancellationToken): ProviderResult<IInlineChatResponse>;
108108

109-
provideFollowups?(session: IInlineChatSession, response: IInlineChatResponse, token: CancellationToken): ProviderResult<IChatReplyFollowup[]>;
109+
provideFollowups?(session: IInlineChatSession, response: IInlineChatResponse, token: CancellationToken): ProviderResult<IChatFollowup[]>;
110110

111111
handleInlineChatResponseFeedback?(session: IInlineChatSession, response: IInlineChatResponse, kind: InlineChatResponseFeedbackKind): void;
112112
}

src/vscode-dts/vscode.proposed.interactive.d.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,23 @@ declare module 'vscode' {
8383
title?: string;
8484
}
8585

86+
export interface InteractiveEditorCommandFollowup {
87+
commandId: string;
88+
args?: any[];
89+
title: string;
90+
when?: string;
91+
}
92+
93+
export type InteractiveEditorFollowup = InteractiveEditorReplyFollowup | InteractiveEditorCommandFollowup;
94+
8695
export interface InteractiveEditorSessionProvider<S extends InteractiveEditorSession = InteractiveEditorSession, R extends InteractiveEditorResponse | InteractiveEditorMessageResponse = InteractiveEditorResponse | InteractiveEditorMessageResponse> {
8796

8897
// Create a session. The lifetime of this session is the duration of the editing session with the input mode widget.
8998
prepareInteractiveEditorSession(context: TextDocumentContext, token: CancellationToken): ProviderResult<S>;
9099

91100
provideInteractiveEditorResponse(session: S, request: InteractiveEditorRequest, progress: Progress<InteractiveEditorProgressItem>, token: CancellationToken): ProviderResult<R>;
92101

93-
provideFollowups?(session: S, response: R, token: CancellationToken): ProviderResult<InteractiveEditorReplyFollowup[]>;
102+
provideFollowups?(session: S, response: R, token: CancellationToken): ProviderResult<InteractiveEditorFollowup[]>;
94103

95104
// eslint-disable-next-line local/vscode-dts-provider-naming
96105
handleInteractiveEditorResponseFeedback?(session: S, response: R, kind: InteractiveEditorResponseFeedbackKind): void;

0 commit comments

Comments
 (0)