mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
* Added Enable Roo Code quick fixes setting to disable quick fixes. * Fix: Address PR review comments and failing tests for #4878 * Fix localization consistency and add test coverage - Add missing period to French translation for consistency - Add test case for disabled enableCodeActions setting - Fix existing test mock setup for proper configuration handling --------- Co-authored-by: hannesrudolph <hrudolph@gmail.com> Co-authored-by: RooCode <roocode@RooCodes-Virtual-Machine.local>
104 lines
2.9 KiB
TypeScript
104 lines
2.9 KiB
TypeScript
import * as vscode from "vscode"
|
|
|
|
import { CodeActionName, CodeActionId } from "@roo-code/types"
|
|
import { Package } from "../shared/package"
|
|
|
|
import { getCodeActionCommand } from "../utils/commands"
|
|
import { EditorUtils } from "../integrations/editor/EditorUtils"
|
|
|
|
export const TITLES: Record<CodeActionName, string> = {
|
|
EXPLAIN: "Explain with Roo Code",
|
|
FIX: "Fix with Roo Code",
|
|
IMPROVE: "Improve with Roo Code",
|
|
ADD_TO_CONTEXT: "Add to Roo Code",
|
|
NEW_TASK: "New Roo Code Task",
|
|
} as const
|
|
|
|
export class CodeActionProvider implements vscode.CodeActionProvider {
|
|
public static readonly providedCodeActionKinds = [
|
|
vscode.CodeActionKind.QuickFix,
|
|
vscode.CodeActionKind.RefactorRewrite,
|
|
]
|
|
|
|
private createAction(
|
|
title: string,
|
|
kind: vscode.CodeActionKind,
|
|
command: CodeActionId,
|
|
args: any[],
|
|
): vscode.CodeAction {
|
|
const action = new vscode.CodeAction(title, kind)
|
|
action.command = { command: getCodeActionCommand(command), title, arguments: args }
|
|
return action
|
|
}
|
|
|
|
public provideCodeActions(
|
|
document: vscode.TextDocument,
|
|
range: vscode.Range | vscode.Selection,
|
|
context: vscode.CodeActionContext,
|
|
): vscode.ProviderResult<(vscode.CodeAction | vscode.Command)[]> {
|
|
try {
|
|
if (!vscode.workspace.getConfiguration(Package.name).get<boolean>("enableCodeActions", true)) {
|
|
return []
|
|
}
|
|
|
|
const effectiveRange = EditorUtils.getEffectiveRange(document, range)
|
|
|
|
if (!effectiveRange) {
|
|
return []
|
|
}
|
|
|
|
const filePath = EditorUtils.getFilePath(document)
|
|
const actions: vscode.CodeAction[] = []
|
|
|
|
actions.push(
|
|
this.createAction(TITLES.ADD_TO_CONTEXT, vscode.CodeActionKind.QuickFix, "addToContext", [
|
|
filePath,
|
|
effectiveRange.text,
|
|
effectiveRange.range.start.line + 1,
|
|
effectiveRange.range.end.line + 1,
|
|
]),
|
|
)
|
|
|
|
if (context.diagnostics.length > 0) {
|
|
const relevantDiagnostics = context.diagnostics.filter((d) =>
|
|
EditorUtils.hasIntersectingRange(effectiveRange.range, d.range),
|
|
)
|
|
|
|
if (relevantDiagnostics.length > 0) {
|
|
actions.push(
|
|
this.createAction(TITLES.FIX, vscode.CodeActionKind.QuickFix, "fixCode", [
|
|
filePath,
|
|
effectiveRange.text,
|
|
effectiveRange.range.start.line + 1,
|
|
effectiveRange.range.end.line + 1,
|
|
relevantDiagnostics.map(EditorUtils.createDiagnosticData),
|
|
]),
|
|
)
|
|
}
|
|
} else {
|
|
actions.push(
|
|
this.createAction(TITLES.EXPLAIN, vscode.CodeActionKind.QuickFix, "explainCode", [
|
|
filePath,
|
|
effectiveRange.text,
|
|
effectiveRange.range.start.line + 1,
|
|
effectiveRange.range.end.line + 1,
|
|
]),
|
|
)
|
|
|
|
actions.push(
|
|
this.createAction(TITLES.IMPROVE, vscode.CodeActionKind.QuickFix, "improveCode", [
|
|
filePath,
|
|
effectiveRange.text,
|
|
effectiveRange.range.start.line + 1,
|
|
effectiveRange.range.end.line + 1,
|
|
]),
|
|
)
|
|
}
|
|
|
|
return actions
|
|
} catch (error) {
|
|
console.error("Error providing code actions:", error)
|
|
return []
|
|
}
|
|
}
|
|
}
|