Replace a symbol's body by name (write)
replace_symbolReplace or insert code symbols by name, resolving locations via an index. Supports atomic batch edits, automatic re-indexing, and safe file snapshots.
Instructions
Write a symbol by NAME — you never re-send the old body to locate the edit. Two modes: REPLACE (name/path+line plus body) overwrites an existing definition; INSERT (after:"X" or before:"X" plus body) adds a NEW symbol next to an existing one, which is what you want for 'add a method beside the related ones' — the anchor's own span comes from the index, so after means after its closing brace, not its signature line. Insert puts body in verbatim: indent it for the file, and include a leading/trailing newline if you want a blank line. range comes from the index; the file is SNAPSHOTTED first (.slimdex/snapshots), re-indexed after, and the new line span is reported so you don't re-read to verify. Safe to mix with ordinary edit tools: if the file moved under the index, a NAME is re-resolved against a fresh parse automatically (an explicit path+line still refuses, since that coordinate is yours). Ambiguous/unknown names are refused, never guessed. body = the complete replacement definition, indented for the file. edits:[…] applies several at once (one snapshot, one re-index); the batch is refused before any write if a target is ambiguous, two edits overlap, or a file isn't writable, and a write that fails mid-batch rolls the earlier files back and says so.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| body | No | The complete new definition, replacing the old one verbatim. | |
| line | No | Definition line (use with path). | |
| name | No | Symbol to replace, resolved via the index. | |
| path | No | File path (use with line instead of name). | |
| after | No | INSERT mode: add `body` as a NEW symbol immediately after this existing symbol's closing brace. Pin which occurrence with path + line when the name repeats inside one file (normal for CSS). | |
| edits | No | Several replacements, applied atomically. Each entry takes name, or path+line, plus body. | |
| before | No | INSERT mode: add `body` as a NEW symbol immediately before this existing symbol. | |
| pathPrefix | No | Disambiguate the after/before anchor when the name exists in several files. |