rename_symbol
Rename a symbol across the workspace with LSP-aware refactoring that avoids unintended matches, previewing changes before applying.
Instructions
Rename a symbol throughout the workspace using LSP semantic refactoring.
The language server identifies every reference across all files and applies a precise edit set atomically. Safer than text find-and-replace: it understands scope, shadowing, and types, so it won't rename unrelated identifiers that share the name.
Prefer symbol_name to identify the symbol; plumb resolves it through the document-symbol tree and queries the language server at the exact identifier position. Raw line/character remains supported and recovers from narrow "no identifier" misses by snapping once to the enclosing symbol. Runs in dry_run mode by default; set dry_run=false to apply. The response appends a per-file unified diff (a preview in dry-run, the applied change otherwise), capped at 20 files, unless show_write_diff is disabled.
If the language server cannot compute the rename (an error, or an empty edit set — common with sourcekit-lsp before the build graph resolves), pass structural_fallback=true to attempt a best-effort identifier-boundary text rename via find_replace (still dry_run by default). The fallback is NOT scope-aware — it renames every whole-word occurrence in same-extension files — so review the preview before applying.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uri | No | Absolute path, file:// URI, or workspace-relative path. | |
| line | No | Zero-based line of the identifier. Required when symbol_name is not provided. | |
| dry_run | No | If true (default), preview changes only. | |
| dirty_ok | No | Allow editing target files with uncommitted changes. Default false — review/commit first, or pass true to proceed. | |
| new_name | Yes | Replacement identifier name. | |
| character | No | Zero-based character offset within the line. Required when symbol_name is not provided. | |
| symbol_name | No | Symbol name to rename instead of a raw position — PREFERRED over line/character. Accepts plain name or ReceiverType.MethodName form. When provided, line and character are not needed. | |
| structural_fallback | No | If true, and the language server cannot compute the rename, attempt a best-effort, identifier-boundary text rename via find_replace (NOT scope-aware; honours dry_run). Default false. |