11import * as vscode from "vscode"
22
3+ import { CodeActionName , CodeActionId } from "../schemas"
4+ import { getCodeActionCommand } from "../utils/commands"
35import { EditorUtils } from "../integrations/editor/EditorUtils"
46
5- export type CodeActionName = "EXPLAIN" | "FIX" | "IMPROVE" | "ADD_TO_CONTEXT" | "NEW_TASK"
6-
7- export type CodeActionId =
8- | "roo-cline.explainCode"
9- | "roo-cline.fixCode"
10- | "roo-cline.improveCode"
11- | "roo-cline.addToContext"
12- | "roo-cline.newTask"
13-
14- export const ACTION_TITLES : Record < CodeActionName , string > = {
7+ export const TITLES : Record < CodeActionName , string > = {
158 EXPLAIN : "Explain with Roo Code" ,
169 FIX : "Fix with Roo Code" ,
1710 IMPROVE : "Improve with Roo Code" ,
1811 ADD_TO_CONTEXT : "Add to Roo Code" ,
1912 NEW_TASK : "New Roo Code Task" ,
2013} as const
2114
22- export const COMMAND_IDS : Record < CodeActionName , CodeActionId > = {
23- EXPLAIN : "roo-cline.explainCode" ,
24- FIX : "roo-cline.fixCode" ,
25- IMPROVE : "roo-cline.improveCode" ,
26- ADD_TO_CONTEXT : "roo-cline.addToContext" ,
27- NEW_TASK : "roo-cline.newTask" ,
28- } as const
29-
3015export class CodeActionProvider implements vscode . CodeActionProvider {
3116 public static readonly providedCodeActionKinds = [
3217 vscode . CodeActionKind . QuickFix ,
@@ -40,7 +25,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
4025 args : any [ ] ,
4126 ) : vscode . CodeAction {
4227 const action = new vscode . CodeAction ( title , kind )
43- action . command = { command, title, arguments : args }
28+ action . command = { command : getCodeActionCommand ( command ) , title, arguments : args }
4429 return action
4530 }
4631
@@ -60,17 +45,12 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
6045 const actions : vscode . CodeAction [ ] = [ ]
6146
6247 actions . push (
63- this . createAction (
64- ACTION_TITLES . ADD_TO_CONTEXT ,
65- vscode . CodeActionKind . QuickFix ,
66- COMMAND_IDS . ADD_TO_CONTEXT ,
67- [
68- filePath ,
69- effectiveRange . text ,
70- effectiveRange . range . start . line + 1 ,
71- effectiveRange . range . end . line + 1 ,
72- ] ,
73- ) ,
48+ this . createAction ( TITLES . ADD_TO_CONTEXT , vscode . CodeActionKind . QuickFix , "addToContext" , [
49+ filePath ,
50+ effectiveRange . text ,
51+ effectiveRange . range . start . line + 1 ,
52+ effectiveRange . range . end . line + 1 ,
53+ ] ) ,
7454 )
7555
7656 if ( context . diagnostics . length > 0 ) {
@@ -80,7 +60,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
8060
8161 if ( relevantDiagnostics . length > 0 ) {
8262 actions . push (
83- this . createAction ( ACTION_TITLES . FIX , vscode . CodeActionKind . QuickFix , COMMAND_IDS . FIX , [
63+ this . createAction ( TITLES . FIX , vscode . CodeActionKind . QuickFix , "fixCode" , [
8464 filePath ,
8565 effectiveRange . text ,
8666 effectiveRange . range . start . line + 1 ,
@@ -91,7 +71,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
9171 }
9272 } else {
9373 actions . push (
94- this . createAction ( ACTION_TITLES . EXPLAIN , vscode . CodeActionKind . QuickFix , COMMAND_IDS . EXPLAIN , [
74+ this . createAction ( TITLES . EXPLAIN , vscode . CodeActionKind . QuickFix , "explainCode" , [
9575 filePath ,
9676 effectiveRange . text ,
9777 effectiveRange . range . start . line + 1 ,
@@ -100,7 +80,7 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
10080 )
10181
10282 actions . push (
103- this . createAction ( ACTION_TITLES . IMPROVE , vscode . CodeActionKind . QuickFix , COMMAND_IDS . IMPROVE , [
83+ this . createAction ( TITLES . IMPROVE , vscode . CodeActionKind . QuickFix , "improveCode" , [
10484 filePath ,
10585 effectiveRange . text ,
10686 effectiveRange . range . start . line + 1 ,
0 commit comments