mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
refactor: centralize editor utilities and unify command handling
- Create EditorUtils class to centralize shared editor functionality - Remove duplicated code between CodeActionProvider and command handlers - Improve command handling to work consistently for both code actions and direct commands - Add better type safety and error handling for editor operations
This commit is contained in:
@@ -6,6 +6,7 @@ import { ClineProvider } from "./core/webview/ClineProvider"
|
||||
import { createClineAPI } from "./exports"
|
||||
import "./utils/path" // necessary to have access to String.prototype.toPosix
|
||||
import { ACTION_NAMES, CodeActionProvider } from "./core/CodeActionProvider"
|
||||
import { EditorUtils } from "./core/EditorUtils"
|
||||
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
|
||||
|
||||
/*
|
||||
@@ -178,26 +179,37 @@ export function activate(context: vscode.ExtensionContext) {
|
||||
let userInput: string | undefined
|
||||
|
||||
context.subscriptions.push(
|
||||
vscode.commands.registerCommand(
|
||||
command,
|
||||
async (filePath: string, selectedText: string, diagnostics?: any[]) => {
|
||||
if (inputPrompt) {
|
||||
userInput = await vscode.window.showInputBox({
|
||||
prompt: inputPrompt,
|
||||
placeHolder: inputPlaceholder,
|
||||
})
|
||||
}
|
||||
vscode.commands.registerCommand(command, async (...args: any[]) => {
|
||||
if (inputPrompt) {
|
||||
userInput = await vscode.window.showInputBox({
|
||||
prompt: inputPrompt,
|
||||
placeHolder: inputPlaceholder,
|
||||
})
|
||||
}
|
||||
|
||||
const params = {
|
||||
filePath,
|
||||
selectedText,
|
||||
...(diagnostics ? { diagnostics } : {}),
|
||||
...(userInput ? { userInput } : {}),
|
||||
}
|
||||
// Handle both code action and direct command cases
|
||||
let filePath: string
|
||||
let selectedText: string
|
||||
let diagnostics: any[] | undefined
|
||||
|
||||
await ClineProvider.handleCodeAction(command, promptType, params)
|
||||
},
|
||||
),
|
||||
if (args.length > 1) {
|
||||
// Called from code action
|
||||
;[filePath, selectedText, diagnostics] = args
|
||||
} else {
|
||||
// Called directly from command palette
|
||||
const context = EditorUtils.getEditorContext()
|
||||
if (!context) return
|
||||
;({ filePath, selectedText, diagnostics } = context)
|
||||
}
|
||||
|
||||
const params = {
|
||||
...{ filePath, selectedText },
|
||||
...(diagnostics ? { diagnostics } : {}),
|
||||
...(userInput ? { userInput } : {}),
|
||||
}
|
||||
|
||||
await ClineProvider.handleCodeAction(command, promptType, params)
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user