make SlashCommandService location aware, scope /clear and /help to panel location

This commit is contained in:
Johannes
2024-06-28 11:42:01 +02:00
parent e4fa43f168
commit 375d8c8beb
5 changed files with 16 additions and 13 deletions
@@ -176,7 +176,8 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
command: 'clear',
detail: nls.localize('clear', "Start a new chat"),
sortText: 'z2_clear',
executeImmediately: true
executeImmediately: true,
locations: [ChatAgentLocation.Panel]
}, async () => {
commandService.executeCommand(ACTION_ID_NEW_CHAT);
}));
@@ -184,7 +185,8 @@ class ChatSlashStaticSlashCommandsContribution extends Disposable {
command: 'help',
detail: '',
sortText: 'z1_help',
executeImmediately: true
executeImmediately: true,
locations: [ChatAgentLocation.Panel]
}, async (prompt, progress) => {
const defaultAgent = chatAgentService.getDefaultAgent(ChatAgentLocation.Panel);
const agents = chatAgentService.getAgents();
@@ -56,7 +56,7 @@ class SlashCommandCompletions extends Disposable {
return;
}
const slashCommands = this.chatSlashCommandService.getCommands();
const slashCommands = this.chatSlashCommandService.getCommands(widget.location);
if (!slashCommands) {
return null;
}
@@ -194,7 +194,7 @@ export class ChatRequestParser {
return new ChatRequestAgentSubcommandPart(slashRange, slashEditorRange, subCommand);
}
} else {
const slashCommands = this.slashCommandService.getCommands();
const slashCommands = this.slashCommandService.getCommands(location);
const slashCommand = slashCommands.find(c => c.command === command);
if (slashCommand) {
// Valid standalone slash command
@@ -617,7 +617,7 @@ export class ChatService extends Disposable implements IChatService {
const message = parsedRequest.text;
const commandResult = await this.chatSlashCommandService.executeCommand(commandPart.slashCommand.command, message.substring(commandPart.slashCommand.command.length + 1).trimStart(), new Progress<IChatProgress>(p => {
progressCallback(p);
}), history, token);
}), history, location, token);
agentOrCommandFollowups = Promise.resolve(commandResult?.followUp);
rawResult = {};
@@ -11,6 +11,7 @@ import { IProgress } from 'vs/platform/progress/common/progress';
import { IChatMessage } from 'vs/workbench/contrib/chat/common/languageModels';
import { IChatFollowup, IChatProgress, IChatResponseProgressFileTreeData } from 'vs/workbench/contrib/chat/common/chatService';
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
import { ChatAgentLocation } from 'vs/workbench/contrib/chat/common/chatAgents';
//#region slash service, commands etc
@@ -18,18 +19,18 @@ export interface IChatSlashData {
command: string;
detail: string;
sortText?: string;
/**
* Whether the command should execute as soon
* as it is entered. Defaults to `false`.
*/
executeImmediately?: boolean;
locations: ChatAgentLocation[];
}
export interface IChatSlashFragment {
content: string | { treeData: IChatResponseProgressFileTreeData };
}
export type IChatSlashCallback = { (prompt: string, progress: IProgress<IChatProgress>, history: IChatMessage[], token: CancellationToken): Promise<{ followUp: IChatFollowup[] } | void> };
export type IChatSlashCallback = { (prompt: string, progress: IProgress<IChatProgress>, history: IChatMessage[], location: ChatAgentLocation, token: CancellationToken): Promise<{ followUp: IChatFollowup[] } | void> };
export const IChatSlashCommandService = createDecorator<IChatSlashCommandService>('chatSlashCommandService');
@@ -40,8 +41,8 @@ export interface IChatSlashCommandService {
_serviceBrand: undefined;
readonly onDidChangeCommands: Event<void>;
registerSlashCommand(data: IChatSlashData, command: IChatSlashCallback): IDisposable;
executeCommand(id: string, prompt: string, progress: IProgress<IChatProgress>, history: IChatMessage[], token: CancellationToken): Promise<{ followUp: IChatFollowup[] } | void>;
getCommands(): Array<IChatSlashData>;
executeCommand(id: string, prompt: string, progress: IProgress<IChatProgress>, history: IChatMessage[], location: ChatAgentLocation, token: CancellationToken): Promise<{ followUp: IChatFollowup[] } | void>;
getCommands(location: ChatAgentLocation): Array<IChatSlashData>;
hasCommand(id: string): boolean;
}
@@ -80,15 +81,15 @@ export class ChatSlashCommandService extends Disposable implements IChatSlashCom
});
}
getCommands(): Array<IChatSlashData> {
return Array.from(this._commands.values(), v => v.data);
getCommands(location: ChatAgentLocation): Array<IChatSlashData> {
return Array.from(this._commands.values(), v => v.data).filter(c => c.locations.includes(location));
}
hasCommand(id: string): boolean {
return this._commands.has(id);
}
async executeCommand(id: string, prompt: string, progress: IProgress<IChatProgress>, history: IChatMessage[], token: CancellationToken): Promise<{ followUp: IChatFollowup[] } | void> {
async executeCommand(id: string, prompt: string, progress: IProgress<IChatProgress>, history: IChatMessage[], location: ChatAgentLocation, token: CancellationToken): Promise<{ followUp: IChatFollowup[] } | void> {
const data = this._commands.get(id);
if (!data) {
throw new Error('No command with id ${id} NOT registered');
@@ -100,6 +101,6 @@ export class ChatSlashCommandService extends Disposable implements IChatSlashCom
throw new Error(`No command with id ${id} NOT resolved`);
}
return await data.command(prompt, progress, history, token);
return await data.command(prompt, progress, history, location, token);
}
}