Fix indentation in replace_body

This commit is contained in:
Michael Panchenko committed 2025-06-02 00:43:11 +02:00
1 parent 5392d37630
commit 37ee90ae41
2 files changed
+8 -5

No files matched your search

+6 -4
View File
@@ -1268,14 +1268,15 @@ class ReplaceSymbolBodyTool(Tool, ToolMarkerCanEdit):
relative_path: str,
body: str,
) -> str:
"""
r"""
Replaces the body of the symbol with the given `name_path`.
IMPORTANT:
Important:
You don't need to provide an adjusted indentation,
as the tool will automatically add the indentation of the original symbol to each line. For example,
for replacing a method in python, you can just write (using the standard python indentation):
body="def my_method_replacement(self, ...):\n first_line\n second_line...". So each line after the first line only has
an indentation of 4 (the indentation relative to the first characted),
an indentation of 4 (the indentation relative to the first characted),
since the additional indentation will be added by the tool. Same for more deeply nested
cases. You always only need to write the relative indentation to the first character of the first line, and that
in turn should not have any indentation.
@@ -1283,7 +1284,8 @@ class ReplaceSymbolBodyTool(Tool, ToolMarkerCanEdit):
:param name_path: for finding the symbol to replace, same logic as in the `find_symbol` tool.
:param relative_path: the relative path to the file containing the symbol
:param body: the new symbol body.
:param body: the new symbol body.
"""
self.symbol_manager.replace_body(
name_path,
+2 -1
View File
@@ -684,7 +684,8 @@ class SymbolManager:
start_line, start_col = start_pos["line"], start_pos["character"]
if use_same_indentation:
indent = " " * start_col
body = "\n".join(indent + line for line in body.splitlines())
body_lines = body.splitlines()
body = body_lines[0] + "\n" + "\n".join(indent + line for line in body_lines[1:])
# make sure body always ends with at least one newline
if not body.endswith("\n"):