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:
parent
17b1d547fd
commit
1c6e002373
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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))
|
||||||
};
|
};
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user