11import * as vscode from "vscode"
2+
23import { EditorUtils } from "./EditorUtils"
34
4- export const ACTION_NAMES = {
5- EXPLAIN : "Roo Code: Explain Code" ,
6- FIX : "Roo Code: Fix Code" ,
7- FIX_LOGIC : "Roo Code: Fix Logic" ,
8- IMPROVE : "Roo Code: Improve Code" ,
9- ADD_TO_CONTEXT : "Roo Code: Add to Context" ,
10- NEW_TASK : "Roo Code: New Task" ,
5+ type CodeActionName = "FIX" | "ADD_TO_CONTEXT" | "NEW_TASK"
6+
7+ export const ACTION_NAMES : Record < CodeActionName , string > = {
8+ FIX : "Fix in Roo Code" ,
9+ ADD_TO_CONTEXT : "Add to Roo Code" ,
10+ NEW_TASK : "New Roo Code Task" ,
1111} as const
1212
13- export const COMMAND_IDS = {
14- EXPLAIN : "roo-cline.explainCode" ,
13+ export const COMMAND_IDS : Record < CodeActionName , string > = {
1514 FIX : "roo-cline.fixCode" ,
16- IMPROVE : "roo-cline.improveCode" ,
1715 ADD_TO_CONTEXT : "roo-cline.addToContext" ,
1816 NEW_TASK : "roo-cline.newTask" ,
1917} as const
@@ -30,25 +28,14 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
3028 return action
3129 }
3230
33- private createActionPair (
34- baseTitle : string ,
35- kind : vscode . CodeActionKind ,
36- baseCommand : string ,
37- args : any [ ] ,
38- ) : vscode . CodeAction [ ] {
39- return [
40- this . createAction ( `${ baseTitle } in New Task` , kind , baseCommand , args ) ,
41- this . createAction ( `${ baseTitle } in Current Task` , kind , `${ baseCommand } InCurrentTask` , args ) ,
42- ]
43- }
44-
4531 public provideCodeActions (
4632 document : vscode . TextDocument ,
4733 range : vscode . Range | vscode . Selection ,
4834 context : vscode . CodeActionContext ,
4935 ) : vscode . ProviderResult < ( vscode . CodeAction | vscode . Command ) [ ] > {
5036 try {
5137 const effectiveRange = EditorUtils . getEffectiveRange ( document , range )
38+
5239 if ( ! effectiveRange ) {
5340 return [ ]
5441 }
@@ -70,57 +57,24 @@ export class CodeActionProvider implements vscode.CodeActionProvider {
7057 ) ,
7158 )
7259
73- actions . push (
74- ...this . createActionPair ( ACTION_NAMES . EXPLAIN , vscode . CodeActionKind . QuickFix , COMMAND_IDS . EXPLAIN , [
75- filePath ,
76- effectiveRange . text ,
77- effectiveRange . range . start . line + 1 ,
78- effectiveRange . range . end . line + 1 ,
79- ] ) ,
80- )
81-
8260 if ( context . diagnostics . length > 0 ) {
8361 const relevantDiagnostics = context . diagnostics . filter ( ( d ) =>
8462 EditorUtils . hasIntersectingRange ( effectiveRange . range , d . range ) ,
8563 )
8664
8765 if ( relevantDiagnostics . length > 0 ) {
88- const diagnosticMessages = relevantDiagnostics . map ( EditorUtils . createDiagnosticData )
8966 actions . push (
90- ... this . createActionPair ( ACTION_NAMES . FIX , vscode . CodeActionKind . QuickFix , COMMAND_IDS . FIX , [
67+ this . createAction ( ACTION_NAMES . FIX , vscode . CodeActionKind . QuickFix , COMMAND_IDS . FIX , [
9168 filePath ,
9269 effectiveRange . text ,
9370 effectiveRange . range . start . line + 1 ,
9471 effectiveRange . range . end . line + 1 ,
95- diagnosticMessages ,
72+ relevantDiagnostics . map ( EditorUtils . createDiagnosticData ) ,
9673 ] ) ,
9774 )
9875 }
99- } else {
100- actions . push (
101- ...this . createActionPair ( ACTION_NAMES . FIX_LOGIC , vscode . CodeActionKind . QuickFix , COMMAND_IDS . FIX , [
102- filePath ,
103- effectiveRange . text ,
104- effectiveRange . range . start . line + 1 ,
105- effectiveRange . range . end . line + 1 ,
106- ] ) ,
107- )
10876 }
10977
110- actions . push (
111- ...this . createActionPair (
112- ACTION_NAMES . IMPROVE ,
113- vscode . CodeActionKind . RefactorRewrite ,
114- COMMAND_IDS . IMPROVE ,
115- [
116- filePath ,
117- effectiveRange . text ,
118- effectiveRange . range . start . line + 1 ,
119- effectiveRange . range . end . line + 1 ,
120- ] ,
121- ) ,
122- )
123-
12478 return actions
12579 } catch ( error ) {
12680 console . error ( "Error providing code actions:" , error )
0 commit comments