Skip to content

Commit c5327e5

Browse files
authored
Show variables in help text (microsoft#205553)
1 parent 84ba0e1 commit c5327e5

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ class ExtHostChatAgent {
340340
private _iconPath: vscode.Uri | { light: vscode.Uri; dark: vscode.Uri } | vscode.ThemeIcon | undefined;
341341
private _isDefault: boolean | undefined;
342342
private _helpTextPrefix: string | vscode.MarkdownString | undefined;
343+
private _helpTextVariablesPrefix: string | vscode.MarkdownString | undefined;
343344
private _helpTextPostfix: string | vscode.MarkdownString | undefined;
344345
private _sampleRequest?: string;
345346
private _isSecondary: boolean | undefined;
@@ -470,6 +471,7 @@ class ExtHostChatAgent {
470471
isDefault: this._isDefault,
471472
isSecondary: this._isSecondary,
472473
helpTextPrefix: (!this._helpTextPrefix || typeof this._helpTextPrefix === 'string') ? this._helpTextPrefix : typeConvert.MarkdownString.from(this._helpTextPrefix),
474+
helpTextVariablesPrefix: (!this._helpTextVariablesPrefix || typeof this._helpTextVariablesPrefix === 'string') ? this._helpTextVariablesPrefix : typeConvert.MarkdownString.from(this._helpTextVariablesPrefix),
473475
helpTextPostfix: (!this._helpTextPostfix || typeof this._helpTextPostfix === 'string') ? this._helpTextPostfix : typeConvert.MarkdownString.from(this._helpTextPostfix),
474476
sampleRequest: this._sampleRequest,
475477
supportIssueReporting: this._supportIssueReporting,
@@ -548,6 +550,19 @@ class ExtHostChatAgent {
548550
that._helpTextPrefix = v;
549551
updateMetadataSoon();
550552
},
553+
get helpTextVariablesPrefix() {
554+
checkProposedApiEnabled(that.extension, 'defaultChatParticipant');
555+
return that._helpTextVariablesPrefix;
556+
},
557+
set helpTextVariablesPrefix(v) {
558+
checkProposedApiEnabled(that.extension, 'defaultChatParticipant');
559+
if (!that._isDefault) {
560+
throw new Error('helpTextVariablesPrefix is only available on the default chat agent');
561+
}
562+
563+
that._helpTextVariablesPrefix = v;
564+
updateMetadataSoon();
565+
},
551566
get helpTextPostfix() {
552567
checkProposedApiEnabled(that.extension, 'defaultChatParticipant');
553568
return that._helpTextPostfix;

src/vs/workbench/contrib/chat/browser/chat.contribution.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import { registerChatFileTreeActions } from 'vs/workbench/contrib/chat/browser/a
5656
import { QuickChatService } from 'vs/workbench/contrib/chat/browser/chatQuick';
5757
import { ChatAgentService, IChatAgentService } from 'vs/workbench/contrib/chat/common/chatAgents';
5858
import { ChatVariablesService } from 'vs/workbench/contrib/chat/browser/chatVariables';
59-
import { chatAgentLeader, chatSubcommandLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
59+
import { chatAgentLeader, chatSubcommandLeader, chatVariableLeader } from 'vs/workbench/contrib/chat/common/chatParserTypes';
6060
import { CancellationToken } from 'vs/base/common/cancellation';
6161
import { IVoiceChatService, VoiceChatService } from 'vs/workbench/contrib/chat/common/voiceChat';
6262

@@ -228,6 +228,7 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
228228
@IChatSlashCommandService slashCommandService: IChatSlashCommandService,
229229
@ICommandService commandService: ICommandService,
230230
@IChatAgentService chatAgentService: IChatAgentService,
231+
@IChatVariablesService chatVariablesService: IChatVariablesService,
231232
) {
232233
super();
233234
this._store.add(slashCommandService.registerSlashCommand({
@@ -246,6 +247,8 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
246247
}, async (prompt, progress) => {
247248
const defaultAgent = chatAgentService.getDefaultAgent();
248249
const agents = chatAgentService.getAgents();
250+
251+
// Report prefix
249252
if (defaultAgent?.metadata.helpTextPrefix) {
250253
if (isMarkdownString(defaultAgent.metadata.helpTextPrefix)) {
251254
progress.report({ content: defaultAgent.metadata.helpTextPrefix, kind: 'markdownContent' });
@@ -255,6 +258,7 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
255258
progress.report({ content: '\n\n', kind: 'content' });
256259
}
257260

261+
// Report agent list
258262
const agentText = (await Promise.all(agents
259263
.filter(a => a.id !== defaultAgent?.id)
260264
.map(async a => {
@@ -272,6 +276,23 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
272276
return (agentLine + '\n' + commandText).trim();
273277
}))).join('\n');
274278
progress.report({ content: new MarkdownString(agentText, { isTrusted: { enabledCommands: [SubmitAction.ID] } }), kind: 'markdownContent' });
279+
280+
// Report variables
281+
if (defaultAgent?.metadata.helpTextVariablesPrefix) {
282+
progress.report({ content: '\n\n', kind: 'content' });
283+
if (isMarkdownString(defaultAgent.metadata.helpTextVariablesPrefix)) {
284+
progress.report({ content: defaultAgent.metadata.helpTextVariablesPrefix, kind: 'markdownContent' });
285+
} else {
286+
progress.report({ content: defaultAgent.metadata.helpTextVariablesPrefix, kind: 'content' });
287+
}
288+
289+
const variableText = Array.from(chatVariablesService.getVariables())
290+
.map(v => `* \`${chatVariableLeader}${v.name}\` - ${v.description}`)
291+
.join('\n');
292+
progress.report({ content: '\n' + variableText, kind: 'content' });
293+
}
294+
295+
// Report help text ending
275296
if (defaultAgent?.metadata.helpTextPostfix) {
276297
progress.report({ content: '\n\n', kind: 'content' });
277298
if (isMarkdownString(defaultAgent.metadata.helpTextPostfix)) {

src/vs/workbench/contrib/chat/common/chatAgents.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface IChatAgentMetadata {
7070
description?: string;
7171
isDefault?: boolean; // The agent invoked when no agent is specified
7272
helpTextPrefix?: string | IMarkdownString;
73+
helpTextVariablesPrefix?: string | IMarkdownString;
7374
helpTextPostfix?: string | IMarkdownString;
7475
isSecondary?: boolean; // Invoked by ctrl/cmd+enter
7576
fullName?: string;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ declare module 'vscode' {
2929
*/
3030
helpTextPrefix?: string | MarkdownString;
3131

32+
/**
33+
* A string that will be added before the listing of chat variables in `/help`.
34+
*/
35+
helpTextVariablesPrefix?: string | MarkdownString;
36+
3237
/**
3338
* A string that will be appended after the listing of chat participants in `/help`.
3439
*/

0 commit comments

Comments
 (0)