safe_delete_symbol
Delete a symbol's declaration only when no references remain, preventing accidental removal of in-use code. If references exist, the deletion is rejected and referencing locations are listed.
Instructions
Delete a symbol's declaration only if it has no remaining references.
Calls LSP textDocument/references first. If any reference outside the declaration itself is found, the deletion is rejected with the list of referencing locations so the caller can decide what to do. This prevents accidental deletion of code that's still in use.
Set include_doc_comment=true to also delete any contiguous doc comment above the symbol — otherwise the comment is left orphaned, pointing at whatever ends up next in the file.
The response includes a unified diff of the deletion — a preview in dry-run, the applied change otherwise — unless show_write_diff is disabled.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uri | No | Absolute path, file:// URI, or workspace-relative path. | |
| dry_run | No | If true (default), preview only; do not write. | |
| dirty_ok | No | Allow editing a file with uncommitted changes. Default false — review/commit first, or pass true to proceed. | |
| name_path | Yes | Slash-separated symbol path within the file (e.g. "ClassName/methodName", or just "funcName" for top-level). | |
| include_doc_comment | No | If true, extend the operation to cover any contiguous comment lines (//, #, /*, *) directly above the symbol declaration. Lets you replace/delete a function together with its doc comment, or insert a new block above an existing doc comment instead of between the comment and its symbol. A WRAPPED declaration (an exported ES declaration under its export statement, a decorated Python def under its @decorator) keeps its doc comment above the wrapper, so WHEN SUCH A COMMENT EXISTS insert_before_symbol and replace_symbol_body extend past the wrapper — replacement content must then reproduce the export keyword or the decorator, or it is dropped. With no doc comment above the wrapper the range starts at the declaration and the wrapper is untouched; safe_delete_symbol never extends past the declaration at all. |