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:
Bhavya U 2023-08-21 15:30:42 -07:00 committed by GitHub
parent a08322ae0a
commit df7dbc4174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 15 additions and 3 deletions

View file

@ -2152,6 +2152,7 @@ export namespace ChatFollowup {
kind: 'command',
title: followup.title ?? '',
commandId: followup.commandId ?? '',
when: followup.when ?? '',
args: followup.args
};
} else {

View file

@ -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') {

View file

@ -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));
}
}

View file

@ -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')) {

View file

@ -104,6 +104,7 @@ export interface IChatResponseCommandFollowup {
commandId: string;
args?: any[];
title: string; // supports codicon strings
when?: string;
}
export type IChatFollowup = IChatReplyFollowup | IChatResponseCommandFollowup;

View file

@ -149,6 +149,7 @@ declare module 'vscode' {
commandId: string;
args?: any[];
title: string; // supports codicon strings
when?: string;
}
export interface InteractiveSessionSlashCommand {