Implement function to execute VSCode commands
- Added a new function 'doCommand' in 'doCommand.ts' to execute VSCode commands. - The function takes a message and a panel as arguments, and uses the 'executeCommand' method from the 'vscode' module. - Updated 'commandManager.ts' to return an empty string instead of undefined. - Registered the new 'doCommand' handler in 'loadHandlers.ts'.
This commit is contained in:
parent
6b96d911f0
commit
df679ea613
@ -23,7 +23,7 @@ class CommandManager {
|
|||||||
description: 'ask code',
|
description: 'ask code',
|
||||||
args: 0,
|
args: 0,
|
||||||
handler: async (commandName: string, userInput: string) => {
|
handler: async (commandName: string, userInput: string) => {
|
||||||
return;
|
return '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
21
src/handler/doCommand.ts
Normal file
21
src/handler/doCommand.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
execute vscode command
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import DtmWrapper from '../toolwrapper/dtm';
|
||||||
|
import { regInMessage, regOutMessage } from '../util/reg_messages';
|
||||||
|
import { runCommandAndWriteOutput } from '../util/commonUtil';
|
||||||
|
|
||||||
|
regInMessage({command: 'doCommand', content: ['command', 'arg1', 'arg2']});
|
||||||
|
export async function doCommand(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise<void> {
|
||||||
|
// execute vscode command
|
||||||
|
// message.content[0]: vscode command
|
||||||
|
// message.content[1:]: args for command
|
||||||
|
try {
|
||||||
|
await vscode.commands.executeCommand(message.content[0], ...message.content.slice(1));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to execute command ${message.content[0]}: ${error}`);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
@ -15,6 +15,7 @@ import { contextDetail } from './contextDetail';
|
|||||||
import { listAllMessages } from './listMessages';
|
import { listAllMessages } from './listMessages';
|
||||||
import { regActionList } from './regActionList';
|
import { regActionList } from './regActionList';
|
||||||
import { applyAction } from './applyAction';
|
import { applyAction } from './applyAction';
|
||||||
|
import { doCommand } from './doCommand';
|
||||||
|
|
||||||
|
|
||||||
// According to the context menu selected by the user, add the corresponding context file
|
// According to the context menu selected by the user, add the corresponding context file
|
||||||
@ -78,3 +79,6 @@ messageHandler.registerHandler('applyAction', applyAction);
|
|||||||
messageHandler.registerHandler('deleteChatMessage', deleteChatMessage);
|
messageHandler.registerHandler('deleteChatMessage', deleteChatMessage);
|
||||||
|
|
||||||
messageHandler.registerHandler('askCode', askCode);
|
messageHandler.registerHandler('askCode', askCode);
|
||||||
|
// Execute vscode command
|
||||||
|
// Response: none
|
||||||
|
messageHandler.registerHandler('doCommand', doCommand);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user