Add RunVSCodeCommandAction to execute VSCode commands
- Created a new file runVSCodeCommand.ts to define the RunVSCodeCommandAction class. - This class implements the Action interface and provides a handlerAction method to execute VSCode commands. - Updated actionManager.ts to register the RunVSCodeCommandAction.
This commit is contained in:
parent
895e2435f9
commit
27bece07dc
@ -11,6 +11,7 @@ import { AskInputAction } from './askInputAction';
|
|||||||
import { SymbolInFileAction } from './symbolInFileAction';
|
import { SymbolInFileAction } from './symbolInFileAction';
|
||||||
import { CurrentDocumentAction } from './currentDocumentAction';
|
import { CurrentDocumentAction } from './currentDocumentAction';
|
||||||
import { SelectTextAction, SelectBlockAction } from './selectContextAction';
|
import { SelectTextAction, SelectBlockAction } from './selectContextAction';
|
||||||
|
import { RunVSCodeCommandAction } from './runVSCodeCommand';
|
||||||
|
|
||||||
|
|
||||||
// extend Action
|
// extend Action
|
||||||
@ -64,6 +65,7 @@ export default class ActionManager {
|
|||||||
ActionManager.instance.registerAction(new CurrentDocumentAction());
|
ActionManager.instance.registerAction(new CurrentDocumentAction());
|
||||||
ActionManager.instance.registerAction(new SelectTextAction());
|
ActionManager.instance.registerAction(new SelectTextAction());
|
||||||
ActionManager.instance.registerAction(new SelectBlockAction());
|
ActionManager.instance.registerAction(new SelectBlockAction());
|
||||||
|
ActionManager.instance.registerAction(new RunVSCodeCommandAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ActionManager.instance;
|
return ActionManager.instance;
|
||||||
|
53
src/action/runVSCodeCommand.ts
Normal file
53
src/action/runVSCodeCommand.ts
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
执行vscode command,类名:RunVSCommandAction
|
||||||
|
*/
|
||||||
|
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import { Action } from './customAction';
|
||||||
|
import { CommandResult } from '../util/commonUtil';
|
||||||
|
import { logger } from '../util/logger';
|
||||||
|
|
||||||
|
export class RunVSCodeCommandAction implements Action {
|
||||||
|
name: string;
|
||||||
|
description: string;
|
||||||
|
type: string[];
|
||||||
|
action: string;
|
||||||
|
handler: string[];
|
||||||
|
args: { "name": string, "description": string, "type": string, "as"?: string, "required": boolean, "from": string }[];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.name = 'run_vscode_command';
|
||||||
|
this.description = 'Run VSCode command';
|
||||||
|
this.type = ['command'];
|
||||||
|
this.action = 'run_vscode_command';
|
||||||
|
this.handler = [];
|
||||||
|
this.args = [
|
||||||
|
{
|
||||||
|
"name": "command",
|
||||||
|
"description": 'VSCode command to run.',
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"from": "content.content.command"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "args",
|
||||||
|
"description": 'Arguments for the command, separated by comma.',
|
||||||
|
"type": "string",
|
||||||
|
"required": false,
|
||||||
|
"from": "content.content.args"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
async handlerAction(args: {[key: string]: any}): Promise<CommandResult> {
|
||||||
|
try {
|
||||||
|
const commandArgs = args.args ? args.args.split(',') : [];
|
||||||
|
const result = await vscode.commands.executeCommand(args.command, ...commandArgs);
|
||||||
|
return {exitCode: 0, stdout: JSON.stringify(result), stderr: ""};
|
||||||
|
} catch (error) {
|
||||||
|
logger.channel()?.error(`Failed to run VSCode command: ${error}`);
|
||||||
|
logger.channel()?.show();
|
||||||
|
return {exitCode: -1, stdout: '', stderr: `Failed to run VSCode command: ${error}`};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user