refactor: wave 1 - extract leaf modules, rename catch-all files, split index.ts hooks
- Split 25+ index.ts files into hook.ts + extracted modules - Rename all catch-all utils.ts/helpers.ts to domain-specific names - Split src/tools/lsp/ into ~15 focused modules - Split src/tools/delegate-task/ into ~18 focused modules - Separate shared types from implementation - 155 files changed, 60+ new files created - All typecheck clean, 61 tests pass
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { tool, type ToolDefinition } from "@opencode-ai/plugin/tool"
|
||||
|
||||
import { formatApplyResult, formatPrepareRenameResult } from "./lsp-formatters"
|
||||
import { withLspClient } from "./lsp-client-wrapper"
|
||||
import { applyWorkspaceEdit } from "./workspace-edit"
|
||||
import type { PrepareRenameDefaultBehavior, PrepareRenameResult, WorkspaceEdit } from "./types"
|
||||
|
||||
export const lsp_prepare_rename: ToolDefinition = tool({
|
||||
description: "Check if rename is valid. Use BEFORE lsp_rename.",
|
||||
args: {
|
||||
filePath: tool.schema.string(),
|
||||
line: tool.schema.number().min(1).describe("1-based"),
|
||||
character: tool.schema.number().min(0).describe("0-based"),
|
||||
},
|
||||
execute: async (args, context) => {
|
||||
try {
|
||||
const result = await withLspClient(args.filePath, async (client) => {
|
||||
return (await client.prepareRename(args.filePath, args.line, args.character)) as
|
||||
| PrepareRenameResult
|
||||
| PrepareRenameDefaultBehavior
|
||||
| null
|
||||
})
|
||||
const output = formatPrepareRenameResult(result)
|
||||
return output
|
||||
} catch (e) {
|
||||
const output = `Error: ${e instanceof Error ? e.message : String(e)}`
|
||||
return output
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const lsp_rename: ToolDefinition = tool({
|
||||
description: "Rename symbol across entire workspace. APPLIES changes to all files.",
|
||||
args: {
|
||||
filePath: tool.schema.string(),
|
||||
line: tool.schema.number().min(1).describe("1-based"),
|
||||
character: tool.schema.number().min(0).describe("0-based"),
|
||||
newName: tool.schema.string().describe("New symbol name"),
|
||||
},
|
||||
execute: async (args, context) => {
|
||||
try {
|
||||
const edit = await withLspClient(args.filePath, async (client) => {
|
||||
return (await client.rename(args.filePath, args.line, args.character, args.newName)) as WorkspaceEdit | null
|
||||
})
|
||||
const result = applyWorkspaceEdit(edit)
|
||||
const output = formatApplyResult(result)
|
||||
return output
|
||||
} catch (e) {
|
||||
const output = `Error: ${e instanceof Error ? e.message : String(e)}`
|
||||
return output
|
||||
}
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user