mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Add support for controlling followup command visibility with when
clauses (#190615)
Add support for controlling followup command visibility with when clauses
This commit is contained in:
parent
a08322ae0a
commit
df7dbc4174
|
@ -2152,6 +2152,7 @@ export namespace ChatFollowup {
|
|||
kind: 'command',
|
||||
title: followup.title ?? '',
|
||||
commandId: followup.commandId ?? '',
|
||||
when: followup.when ?? '',
|
||||
args: followup.args
|
||||
};
|
||||
} else {
|
||||
|
|
|
@ -7,6 +7,7 @@ import * as dom from 'vs/base/browser/dom';
|
|||
import { Button, IButtonStyles } from 'vs/base/browser/ui/button/button';
|
||||
import { MarkdownString } from 'vs/base/common/htmlContent';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IChatFollowup } from 'vs/workbench/contrib/chat/common/chatService';
|
||||
|
||||
const $ = dom.$;
|
||||
|
@ -17,6 +18,7 @@ export class ChatFollowups<T extends IChatFollowup> extends Disposable {
|
|||
followups: T[],
|
||||
private readonly options: IButtonStyles | undefined,
|
||||
private readonly clickHandler: (followup: T) => void,
|
||||
private readonly contextService: IContextKeyService,
|
||||
) {
|
||||
super();
|
||||
|
||||
|
@ -25,6 +27,11 @@ export class ChatFollowups<T extends IChatFollowup> extends Disposable {
|
|||
}
|
||||
|
||||
private renderFollowup(container: HTMLElement, followup: T): void {
|
||||
|
||||
if (followup.kind === 'command' && followup.when && !this.contextService.contextMatchesRules(ContextKeyExpr.deserialize(followup.when))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tooltip = 'tooltip' in followup ? followup.tooltip : undefined;
|
||||
const button = this._register(new Button(container, { ...this.options, supportIcons: true, title: tooltip }));
|
||||
if (followup.kind === 'reply') {
|
||||
|
|
|
@ -269,7 +269,7 @@ export class ChatInputPart extends Disposable implements IHistoryNavigationWidge
|
|||
dom.clearNode(this.followupsContainer);
|
||||
|
||||
if (items && items.length > 0) {
|
||||
this.followupsDisposables.add(new ChatFollowups(this.followupsContainer, items, undefined, followup => this._onDidAcceptFollowup.fire(followup)));
|
||||
this.followupsDisposables.add(new ChatFollowups(this.followupsContainer, items, undefined, followup => this._onDidAcceptFollowup.fire(followup), this.contextKeyService));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -349,7 +349,8 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
|
|||
}
|
||||
});
|
||||
return this.commandService.executeCommand(followup.commandId, ...(followup.args ?? []));
|
||||
}));
|
||||
},
|
||||
templateData.contextKeyService));
|
||||
}
|
||||
|
||||
element.currentRenderedHeight = templateData.rowContainer.offsetHeight;
|
||||
|
@ -365,7 +366,8 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer<Ch
|
|||
templateData.value,
|
||||
item,
|
||||
undefined,
|
||||
followup => this._onDidClickFollowup.fire(followup)));
|
||||
followup => this._onDidClickFollowup.fire(followup),
|
||||
templateData.contextKeyService));
|
||||
} else {
|
||||
const result = this.renderMarkdown(item as IMarkdownString, element, templateData.elementDisposables, templateData);
|
||||
for (const codeElement of result.element.querySelectorAll('code')) {
|
||||
|
|
|
@ -104,6 +104,7 @@ export interface IChatResponseCommandFollowup {
|
|||
commandId: string;
|
||||
args?: any[];
|
||||
title: string; // supports codicon strings
|
||||
when?: string;
|
||||
}
|
||||
|
||||
export type IChatFollowup = IChatReplyFollowup | IChatResponseCommandFollowup;
|
||||
|
|
|
@ -149,6 +149,7 @@ declare module 'vscode' {
|
|||
commandId: string;
|
||||
args?: any[];
|
||||
title: string; // supports codicon strings
|
||||
when?: string;
|
||||
}
|
||||
|
||||
export interface InteractiveSessionSlashCommand {
|
||||
|
|
Loading…
Reference in a new issue