Add args property to Command interface and update regCommandList

- Added args property to Command interface in commandManager.ts and customCommand.ts.
- Updated regCommandList handler to convert command patterns with args.
- Replaced {{prompt}} with an array of empty strings based on the args count.
This commit is contained in:
bobo.yang 2023-06-02 13:45:12 +08:00
parent 17b1d547fd
commit 1c6e002373
3 changed files with 14 additions and 1 deletions

View File

@ -4,6 +4,7 @@ export interface Command {
name: string; name: string;
pattern: string; pattern: string;
description: string; description: string;
args: number;
handler: (commandName: string, userInput: string) => Promise<string>; handler: (commandName: string, userInput: string) => Promise<string>;
} }
@ -35,6 +36,7 @@ class CommandManager {
name: command.name, name: command.name,
pattern: command.pattern, pattern: command.pattern,
description: command.description, description: command.description,
args: command.args,
handler: async (commandName: string, userInput: string) => { handler: async (commandName: string, userInput: string) => {
return CustomCommands.getInstance().handleCommand(commandName, userInput); return CustomCommands.getInstance().handleCommand(commandName, userInput);
} }

View File

@ -9,6 +9,7 @@ export interface Command {
message: string; message: string;
default: boolean; default: boolean;
show: boolean; show: boolean;
args: number;
instructions: string[]; instructions: string[];
} }
@ -51,6 +52,7 @@ class CustomCommands {
description: settings.description, description: settings.description,
message: settings.message, message: settings.message,
default: settings.default, default: settings.default,
args: settings.args === undefined ? 0 : settings.args,
show: settings.show === undefined ? "true" : settings.show, show: settings.show === undefined ? "true" : settings.show,
instructions: settings.instructions.map((instruction: string) => path.join(commandDir, commandSubDir, instruction)) instructions: settings.instructions.map((instruction: string) => path.join(commandDir, commandSubDir, instruction))
}; };

View File

@ -8,7 +8,16 @@ regInMessage({command: 'regCommandList'});
regOutMessage({command: 'regCommandList', result: [{name: '', pattern: '', description: ''}]}); regOutMessage({command: 'regCommandList', result: [{name: '', pattern: '', description: ''}]});
export async function regCommandList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> { export async function regCommandList(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
const commandList = CommandManager.getInstance().getCommandList(); const commandList = CommandManager.getInstance().getCommandList();
MessageHandler.sendMessage(panel, { command: 'regCommandList', result: commandList }); const commandCovertedList = commandList.map(command => {
if (command.args > 0) {
// replace {{prompt}} with {{["",""]}}, count of "" is args
const prompt = Array.from({length: command.args}, () => "");
command.pattern = command.pattern.replace('{{prompt}}', '{{' + JSON.stringify(prompt) + '}}');
}
return command;
});
MessageHandler.sendMessage(panel, { command: 'regCommandList', result: commandCovertedList });
return; return;
} }