rename_symbol
Rename Svelte symbols across your workspace with automatic file updates. Change variable, function, or component names while maintaining consistency throughout your project.
Instructions
Rename a symbol across the workspace. Applies changes to disk.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the file | |
| symbolName | Yes | Name of the symbol to rename | |
| newName | Yes | New name for the symbol | |
| symbolKind | No | Kind of symbol |
Implementation Reference
- src/tools/editing.ts:21-73 (handler)The `rename_symbol` tool is registered and implemented in this block, using LSP `textDocument/prepareRename` and `textDocument/rename` requests, and then applying the changes via `applyWorkspaceEdit`.
server.registerTool( "rename_symbol", { title: "Rename Symbol", description: "Rename a symbol across the workspace. Applies changes to disk.", inputSchema: z.object({ filePath: z.string().describe("Absolute path to the file"), symbolName: z.string().describe("Name of the symbol to rename"), newName: z.string().describe("New name for the symbol"), symbolKind: z.string().optional().describe("Kind of symbol"), }), }, async ({ filePath, symbolName, newName, symbolKind, }): Promise<ToolResult> => { try { const prep = await prepareSymbolRequest(lsp, filePath, symbolName, symbolKind); if ("error" in prep) return textResult(prep.error); // Prepare rename check const prepareResult = await lsp.request( "textDocument/prepareRename", makePositionParams(prep.ctx) ); if (!prepareResult) { return textResult(`Symbol '${symbolName}' cannot be renamed.`); } // Execute rename const renameParams = { ...makePositionParams(prep.ctx), newName, }; const result = await lsp.request("textDocument/rename", renameParams); if (!result) return textResult("Rename failed - no changes returned."); const applied = await applyWorkspaceEdit(lsp, result); const summary = formatRenameEdit(result, symbolName, newName); return textResult( applied ? summary : `(dry-run, edits NOT applied to disk)\n\n${summary}` ); } catch (ex) { return textResult(formatError(ex)); } } );