replace_function
Replace an entire function or method symbol, including decorators, signature, and body, with new source content in a file while preserving the symbol's structure.
Instructions
Replace a whole symbol (decorators, signature and body) with new content.
The replaced span is what read_symbol returns: decorators, a JS/TS
export, a C++ template <...> header and code that only wraps the
symbol are part of it, so keep them in content. read_symbol's text,
edited or not, goes in as it is, and may become several members;
content written from column 0 is re-indented to the symbol's level. A
symbol that shares a line with other code has only its own text
replaced. For one name of int a, b; the content must keep the others.
Refused in JSON, YAML and TOML files (use replace_value).
Use this when: rewriting a symbol top to bottom (name, parameters and body). Don't use this when: only the body changes (replace_function_body), only the signature (replace_signature), or a few lines (replace_in_body).
Example: target="LRUCache.get" content='def get(self, key, default=None):\n return self.items.get(key, default)'
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target | Yes | Function or method name as list_symbols lists it, dotted for nesting ('LRUCache.get'); overloads take parameter types ('A.m(int)'). | |
| content | Yes | Complete new source of the symbol, decorators included, in read_symbol's shape or written from column 0. | |
| file_path | Yes | Absolute path to the source or config file. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |