move_symbol
Move a top-level function, type, const, or var from one file to another in the same package. Atomic operation with doc-comment preservation and automatic rollback on failure.
Instructions
Move a top-level declaration (function, method, type, const, or var) from one file to another within the SAME directory/package, atomically.
The symbol's full source — its declaration and, by default, its contiguous leading doc comment (include_doc_comment, default true) — is removed from source_uri and appended to destination_uri in a single all-or-nothing operation: if the destination write fails, the source is rolled back, so the declaration is never duplicated or lost. Locates the symbol via the LSP document-symbol tree, falling back to a fresh tree-sitter parse when the language server is cold or unavailable.
Scope (v1, conservative): source and destination must be in the SAME directory. plumb does NOT rewrite references or imports, so a move that would change a symbol's package or import path — a different directory, or (for Go) a different package clause — is REFUSED rather than applied half-correctly. Move within a package where references resolve unchanged; relocate across packages by hand.
destination_uri must already exist unless create_destination=true (a newly created Go file is seeded with the source file's package clause). Refuses when the symbol is not found, the name is ambiguous (disambiguate with a slash-separated name_path), the destination is missing without create_destination, or either path is outside the workspace. For Go, also refuses when source and destination carry different build constraints — explicit (//go:build or legacy +build comments) or implicit (the _GOOS/_GOARCH/_GOOS_GOARCH and _test filename-suffix conventions, e.g. handlers_linux.go or foo_test.go) — since moving a declaration between them would silently change what compiles per platform/tag, or drop it from the production build entirely.
Dry-run by default (dry_run=true): previews the unified diff of both files without writing. Set dry_run=false to apply.
Undo is per-file: reverting a move takes two undo_edit calls, one for source and one for destination, and the state between them is a transient duplicate of the moved declaration in both files.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dry_run | No | If true (default), preview the diff of both files only; do not write. | |
| dirty_ok | No | Allow moving when either file has uncommitted changes. Default false — review/commit first, or pass true to proceed. | |
| name_path | Yes | Slash-separated symbol path within the source file (e.g. "ClassName/methodName", or just "funcName" for a top-level declaration). | |
| source_uri | Yes | Absolute path, file:// URI, or workspace-relative path of the file currently holding the symbol. | |
| destination_uri | Yes | Absolute path, file:// URI, or workspace-relative path of the file to move the declaration into. Must be in the SAME directory (package) as source_uri. | |
| create_destination | No | Create destination_uri if it does not exist. Default false (the destination must already exist). A newly created Go file is seeded with the source file's package clause. | |
| include_doc_comment | No | Move the symbol's contiguous leading doc comment along with it. Default true — a relocated declaration should keep its documentation. Where the declaration is WRAPPED (an exported ES declaration under its export statement, a decorated Python def under its @decorator) its doc comment sits above the wrapper, so the moved range covers the wrapper too — which is what keeps @property with the method it decorates. |