rename_symbol
Rename variables, functions, or classes across all files in a project. Update symbol names consistently throughout your codebase to maintain clarity and avoid errors.
Instructions
Rename a symbol (variable, function, class, etc.) across all files
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file | Yes | File containing the symbol | |
| line | Yes | Line number of the symbol | |
| character | No | Character position of the symbol | |
| newName | Yes | New name for the symbol | |
| language | No | Programming language | typescript |
Implementation Reference
- src/commands/renameSymbol.ts:6-49 (handler)The main handler function that executes the rename_symbol tool using LSP textDocument/rename request and applies the workspace edit.export async function renameSymbol(args: RenameSymbolArgs, clientManager: LSPClientManager) { const { file, line, character = 0, newName, language = 'typescript' } = args; const workspaceRoot = findWorkspaceRoot(file); try { const client = await clientManager.getOrCreateLSPClient(language, workspaceRoot); // Open the file const content = await fs.readFile(file, 'utf-8'); await clientManager.sendLSPNotification(client, 'textDocument/didOpen', { textDocument: { uri: `file://${file}`, languageId: language, version: 1, text: content, }, }); const workspaceEdit = await clientManager.sendLSPRequest(client, 'textDocument/rename', { textDocument: { uri: `file://${file}` }, position: { line: line - 1, character }, newName, }); if (workspaceEdit) { const edit = workspaceEdit as LSPWorkspaceEdit; await applyWorkspaceEdit(edit); const changedFiles = Object.keys(edit.changes || {}); return { content: [ { type: 'text', text: `Successfully renamed symbol to '${newName}' across ${changedFiles.length} files`, }, ], }; } else { throw new Error('No workspace edit returned from LSP server'); } } catch (error) { throw new Error(`Failed to rename symbol: ${error instanceof Error ? error.message : String(error)}`); } }
- src/server.ts:171-202 (registration)Registration of the 'rename_symbol' tool in the listTools response, including name, description, and input schema.{ name: 'rename_symbol', description: 'Rename a symbol (variable, function, class, etc.) across all files', inputSchema: { type: 'object', properties: { file: { type: 'string', description: 'File containing the symbol', }, line: { type: 'number', description: 'Line number of the symbol', }, character: { type: 'number', description: 'Character position of the symbol', default: 0, }, newName: { type: 'string', description: 'New name for the symbol', }, language: { type: 'string', description: 'Programming language', default: 'typescript', }, }, required: ['file', 'line', 'newName'], }, },
- src/server.ts:220-221 (registration)Handler dispatch in the switch statement for the 'rename_symbol' tool call.case 'rename_symbol': return await renameSymbol(args as unknown as RenameSymbolArgs, this.clientManager);
- src/types.ts:79-85 (schema)TypeScript interface defining the arguments for the rename_symbol tool.export interface RenameSymbolArgs { file: string; line: number; character?: number; newName: string; language?: string; }