mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
fix #207604
This commit is contained in:
parent
a29a83ddd4
commit
321bee3d6f
|
@ -19,7 +19,9 @@ export const enum TerminalChatCommandId {
|
|||
FeedbackUnhelpful = 'workbench.action.terminal.chat.feedbackUnhelpful',
|
||||
FeedbackReportIssue = 'workbench.action.terminal.chat.feedbackReportIssue',
|
||||
RunCommand = 'workbench.action.terminal.chat.runCommand',
|
||||
RunFirstCommand = 'workbench.action.terminal.chat.runFirstCommand',
|
||||
InsertCommand = 'workbench.action.terminal.chat.insertCommand',
|
||||
InsertFirstCommand = 'workbench.action.terminal.chat.insertFirstCommand',
|
||||
ViewInChat = 'workbench.action.terminal.chat.viewInChat',
|
||||
PreviousFromHistory = 'workbench.action.terminal.chat.previousFromHistory',
|
||||
NextFromHistory = 'workbench.action.terminal.chat.nextFromHistory',
|
||||
|
@ -39,6 +41,7 @@ export const enum TerminalChatContextKeyStrings {
|
|||
ChatAgentRegistered = 'terminalChatAgentRegistered',
|
||||
ChatResponseEditorFocused = 'terminalChatResponseEditorFocused',
|
||||
ChatResponseContainsCodeBlock = 'terminalChatResponseContainsCodeBlock',
|
||||
ChatResponseContainsMultipleCodeBlocks = 'terminalChatResponseContainsMultipleCodeBlocks',
|
||||
ChatResponseSupportsIssueReporting = 'terminalChatResponseSupportsIssueReporting',
|
||||
ChatSessionResponseVote = 'terminalChatSessionResponseVote',
|
||||
}
|
||||
|
@ -64,6 +67,9 @@ export namespace TerminalChatContextKeys {
|
|||
/** The type of chat response, if any */
|
||||
export const responseContainsCodeBlock = new RawContextKey<boolean>(TerminalChatContextKeyStrings.ChatResponseContainsCodeBlock, false, localize('chatResponseContainsCodeBlockContextKey', "Whether the chat response contains a code block."));
|
||||
|
||||
/** The type of chat response, if any */
|
||||
export const responseContainsMultipleCodeBlocks = new RawContextKey<boolean>(TerminalChatContextKeyStrings.ChatResponseContainsMultipleCodeBlocks, false, localize('chatResponseContainsMultipleCodeBlocksContextKey', "Whether the chat response contains multiple code blocks."));
|
||||
|
||||
/** Whether the response supports issue reporting */
|
||||
export const responseSupportsIssueReporting = new RawContextKey<boolean>(TerminalChatContextKeyStrings.ChatResponseSupportsIssueReporting, false, localize('chatResponseSupportsIssueReportingContextKey', "Whether the response supports issue reporting"));
|
||||
|
||||
|
|
|
@ -156,7 +156,8 @@ registerActiveXtermAction({
|
|||
ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
|
||||
TerminalChatContextKeys.requestActive.negate(),
|
||||
TerminalChatContextKeys.agentRegistered,
|
||||
TerminalChatContextKeys.responseContainsCodeBlock
|
||||
TerminalChatContextKeys.responseContainsCodeBlock,
|
||||
TerminalChatContextKeys.responseContainsMultipleCodeBlocks.negate()
|
||||
),
|
||||
icon: Codicon.play,
|
||||
keybinding: {
|
||||
|
@ -168,7 +169,39 @@ registerActiveXtermAction({
|
|||
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
group: '0_main',
|
||||
order: 0,
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate())
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.responseContainsMultipleCodeBlocks.negate(), TerminalChatContextKeys.requestActive.negate())
|
||||
},
|
||||
run: (_xterm, _accessor, activeInstance) => {
|
||||
if (isDetachedTerminalInstance(activeInstance)) {
|
||||
return;
|
||||
}
|
||||
const contr = TerminalChatController.activeChatWidget || TerminalChatController.get(activeInstance);
|
||||
contr?.acceptCommand(true);
|
||||
}
|
||||
});
|
||||
|
||||
registerActiveXtermAction({
|
||||
id: TerminalChatCommandId.RunFirstCommand,
|
||||
title: localize2('runFirstCommand', 'Run First Chat Command'),
|
||||
shortTitle: localize2('runFirst', 'Run First'),
|
||||
precondition: ContextKeyExpr.and(
|
||||
ContextKeyExpr.has(`config.${TerminalSettingId.ExperimentalInlineChat}`),
|
||||
ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
|
||||
TerminalChatContextKeys.requestActive.negate(),
|
||||
TerminalChatContextKeys.agentRegistered,
|
||||
TerminalChatContextKeys.responseContainsMultipleCodeBlocks
|
||||
),
|
||||
icon: Codicon.play,
|
||||
keybinding: {
|
||||
when: TerminalChatContextKeys.requestActive.negate(),
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyMod.CtrlCmd | KeyCode.Enter,
|
||||
},
|
||||
menu: {
|
||||
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
group: '0_main',
|
||||
order: 0,
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsMultipleCodeBlocks, TerminalChatContextKeys.requestActive.negate())
|
||||
},
|
||||
run: (_xterm, _accessor, activeInstance) => {
|
||||
if (isDetachedTerminalInstance(activeInstance)) {
|
||||
|
@ -188,7 +221,8 @@ registerActiveXtermAction({
|
|||
ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
|
||||
TerminalChatContextKeys.requestActive.negate(),
|
||||
TerminalChatContextKeys.agentRegistered,
|
||||
TerminalChatContextKeys.responseContainsCodeBlock
|
||||
TerminalChatContextKeys.responseContainsCodeBlock,
|
||||
TerminalChatContextKeys.responseContainsMultipleCodeBlocks.negate()
|
||||
),
|
||||
keybinding: {
|
||||
when: TerminalChatContextKeys.requestActive.negate(),
|
||||
|
@ -199,7 +233,38 @@ registerActiveXtermAction({
|
|||
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
group: '0_main',
|
||||
order: 1,
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.requestActive.negate())
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsCodeBlock, TerminalChatContextKeys.responseContainsMultipleCodeBlocks.negate(), TerminalChatContextKeys.requestActive.negate())
|
||||
},
|
||||
run: (_xterm, _accessor, activeInstance) => {
|
||||
if (isDetachedTerminalInstance(activeInstance)) {
|
||||
return;
|
||||
}
|
||||
const contr = TerminalChatController.activeChatWidget || TerminalChatController.get(activeInstance);
|
||||
contr?.acceptCommand(false);
|
||||
}
|
||||
});
|
||||
|
||||
registerActiveXtermAction({
|
||||
id: TerminalChatCommandId.InsertFirstCommand,
|
||||
title: localize2('insertFirstCommand', 'Insert First Chat Command'),
|
||||
shortTitle: localize2('insertFirst', 'Insert First'),
|
||||
precondition: ContextKeyExpr.and(
|
||||
ContextKeyExpr.has(`config.${TerminalSettingId.ExperimentalInlineChat}`),
|
||||
ContextKeyExpr.or(TerminalContextKeys.processSupported, TerminalContextKeys.terminalHasBeenCreated),
|
||||
TerminalChatContextKeys.requestActive.negate(),
|
||||
TerminalChatContextKeys.agentRegistered,
|
||||
TerminalChatContextKeys.responseContainsMultipleCodeBlocks
|
||||
),
|
||||
keybinding: {
|
||||
when: TerminalChatContextKeys.requestActive.negate(),
|
||||
weight: KeybindingWeight.WorkbenchContrib,
|
||||
primary: KeyMod.Alt | KeyCode.Enter,
|
||||
},
|
||||
menu: {
|
||||
id: MENU_TERMINAL_CHAT_WIDGET_STATUS,
|
||||
group: '0_main',
|
||||
order: 1,
|
||||
when: ContextKeyExpr.and(TerminalChatContextKeys.responseContainsMultipleCodeBlocks, TerminalChatContextKeys.requestActive.negate())
|
||||
},
|
||||
run: (_xterm, _accessor, activeInstance) => {
|
||||
if (isDetachedTerminalInstance(activeInstance)) {
|
||||
|
|
|
@ -63,6 +63,7 @@ export class TerminalChatController extends Disposable implements ITerminalContr
|
|||
private readonly _requestActiveContextKey: IContextKey<boolean>;
|
||||
private readonly _terminalAgentRegisteredContextKey: IContextKey<boolean>;
|
||||
private readonly _responseContainsCodeBlockContextKey: IContextKey<boolean>;
|
||||
private readonly _responseContainsMulitpleCodeBlocksContextKey: IContextKey<boolean>;
|
||||
private readonly _responseSupportsIssueReportingContextKey: IContextKey<boolean>;
|
||||
private readonly _sessionResponseVoteContextKey: IContextKey<string | undefined>;
|
||||
|
||||
|
@ -103,6 +104,7 @@ export class TerminalChatController extends Disposable implements ITerminalContr
|
|||
this._requestActiveContextKey = TerminalChatContextKeys.requestActive.bindTo(this._contextKeyService);
|
||||
this._terminalAgentRegisteredContextKey = TerminalChatContextKeys.agentRegistered.bindTo(this._contextKeyService);
|
||||
this._responseContainsCodeBlockContextKey = TerminalChatContextKeys.responseContainsCodeBlock.bindTo(this._contextKeyService);
|
||||
this._responseContainsMulitpleCodeBlocksContextKey = TerminalChatContextKeys.responseContainsMultipleCodeBlocks.bindTo(this._contextKeyService);
|
||||
this._responseSupportsIssueReportingContextKey = TerminalChatContextKeys.responseSupportsIssueReporting.bindTo(this._contextKeyService);
|
||||
this._sessionResponseVoteContextKey = TerminalChatContextKeys.sessionResponseVote.bindTo(this._contextKeyService);
|
||||
|
||||
|
@ -327,7 +329,10 @@ export class TerminalChatController extends Disposable implements ITerminalContr
|
|||
this._chatAccessibilityService.acceptResponse(responseContent, accessibilityRequestId);
|
||||
const containsCode = responseContent.includes('```');
|
||||
this._chatWidget?.value.inlineChatWidget.updateChatMessage({ message: new MarkdownString(responseContent), requestId: this._currentRequest.id, providerId: 'terminal' }, false, containsCode);
|
||||
this._responseContainsCodeBlockContextKey.set(containsCode);
|
||||
const firstCodeBlock = await this.chatWidget?.inlineChatWidget.getCodeBlockInfo(0);
|
||||
const secondCodeBlock = await this.chatWidget?.inlineChatWidget.getCodeBlockInfo(1);
|
||||
this._responseContainsCodeBlockContextKey.set(!!firstCodeBlock);
|
||||
this._responseContainsMulitpleCodeBlocksContextKey.set(!!secondCodeBlock);
|
||||
this._chatWidget?.value.inlineChatWidget.updateToolbar(true);
|
||||
}
|
||||
const supportIssueReporting = this._currentRequest?.response?.agent?.metadata?.supportIssueReporting;
|
||||
|
|
Loading…
Reference in a new issue