insert_at_line
Insert content at a specific line in a file to make targeted code edits without replacing entire sections, using line-based positioning for precise modifications.
Instructions
Inserts the given content at the given line in the file, pushing existing content of the line down. In general, symbolic insert operations like insert_after_symbol or insert_before_symbol should be preferred if you know which symbol you are looking for. However, this can also be useful for small targeted edits of the body of a longer symbol (without replacing the entire body).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relative_path | Yes | The relative path to the file. | |
| line | Yes | The 0-based index of the line to insert content at. | |
| content | Yes | The content to be inserted. |
Implementation Reference
- src/serena/symbol.py:862-871 (handler)Handler function for the 'insert_at_line' tool in SymbolManager class. Inserts content at a specified line (0-based) in the given relative_path file using the language server's insert_text_at_position.def insert_at_line(self, relative_path: str, line: int, content: str) -> None: """ Inserts content at the given line in the given file. :param line: the 0-based index of the line to insert content at :param content: the content to insert """ with self._edited_file(relative_path): self._lang_server.insert_text_at_position(relative_path, line, 0, content)