From 9c38d5a2bd8081946af2c50f679fec47c8f622a9 Mon Sep 17 00:00:00 2001 From: RajWorking Date: Sat, 16 Nov 2024 17:32:09 +0000 Subject: [PATCH 1/7] Added functionality for moving code block and deleting code block. --- .gitignore | 2 +- openhands_aci/editor/editor.py | 148 ++++++++++++++++++++++++++------- pyproject.toml | 2 +- 3 files changed, 118 insertions(+), 34 deletions(-) diff --git a/.gitignore b/.gitignore index 321b8aa..29a4fff 100644 --- a/.gitignore +++ b/.gitignore @@ -99,7 +99,7 @@ ipython_config.py # This is especially recommended for binary packages to ensure reproducibility, and is more # commonly ignored for libraries. # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock +poetry.lock # pdm # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. diff --git a/openhands_aci/editor/editor.py b/openhands_aci/editor/editor.py index 512f8d3..3eef798 100644 --- a/openhands_aci/editor/editor.py +++ b/openhands_aci/editor/editor.py @@ -19,7 +19,9 @@ 'create', 'str_replace', 'insert', + 'delete', 'undo_edit', + 'move_code_block', # 'jump_to_definition', TODO: # 'find_references' TODO: ] @@ -32,6 +34,7 @@ class OHEditor: - create - navigate - edit files + - refactor code The tool parameters are defined by Anthropic and are not editable. Original implementation: https://github.com/anthropics/anthropic-quickstarts/blob/main/computer-use-demo/computer_use_demo/tools/edit.py @@ -48,8 +51,9 @@ def __call__( *, command: Command, path: str, + dst_path: str | None = None, file_text: str | None = None, - view_range: list[int] | None = None, + lines_range: list[int] | None = None, old_str: str | None = None, new_str: str | None = None, insert_line: int | None = None, @@ -57,9 +61,11 @@ def __call__( **kwargs, ) -> ToolResult | CLIResult: _path = Path(path) + _new_path = Path(path) self.validate_path(command, _path) + self.validate_path(command, _new_path) if command == 'view': - return self.view(_path, view_range) + return self.view(_path, lines_range) elif command == 'create': if not file_text: raise @@ -82,6 +88,16 @@ def __call__( if not new_str: raise EditorToolParameterMissingError(command, 'new_str') return self.insert(_path, insert_line, new_str, enable_linting) + elif command == 'delete': + if not lines_range: + raise EditorToolParameterMissingError(command, 'lines_range') + return self.delete(_path, lines_range) + elif command == 'move_code_block': + if not lines_range: + raise EditorToolParameterMissingError(command, 'lines_range') + if insert_line is None: + raise EditorToolParameterMissingError(command, 'insert_line') + return self.move_code_block(_path, lines_range, _dst_file, insert_line) elif command == 'undo_edit': return self.undo_edit(_path) @@ -165,43 +181,18 @@ def view(self, path: Path, view_range: list[int] | None = None) -> CLIResult: return CLIResult(output=stdout, error=stderr) file_content = self.read_file(path) - start_line = 1 + file_content_lines = file_content.split('\n') + if not view_range: + start_line = 1 return CLIResult( output=self._make_output(file_content, str(path), start_line) ) - if len(view_range) != 2 or not all(isinstance(i, int) for i in view_range): - raise EditorToolParameterInvalidError( - 'view_range', - view_range, - 'It should be a list of two integers.', - ) - - file_content_lines = file_content.split('\n') num_lines = len(file_content_lines) - start_line, end_line = view_range - if start_line < 1 or start_line > num_lines: - raise EditorToolParameterInvalidError( - 'view_range', - view_range, - f'Its first element `{start_line}` should be within the range of lines of the file: {[1, num_lines]}.', - ) - - if end_line > num_lines: - raise EditorToolParameterInvalidError( - 'view_range', - view_range, - f'Its second element `{end_line}` should be smaller than the number of lines in the file: `{num_lines}`.', - ) - - if end_line != -1 and end_line < start_line: - raise EditorToolParameterInvalidError( - 'view_range', - view_range, - f'Its second element `{end_line}` should be greater than or equal to the first element `{start_line}`.', - ) + _validate_range(view_range, num_lines) + start_line, end_line = view_range if end_line == -1: file_content = '\n'.join(file_content_lines[start_line - 1 :]) else: @@ -275,6 +266,68 @@ def insert( success_message += 'Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.' return CLIResult(output=success_message) + def delete(self, path: Path, lines_range: list[int]) -> CLIResult: + """ + Deletes text content in file from the given range. + """ + try: + file_text = self.read_file(path) + except Exception as e: + raise ToolError(f'Ran into {e} while trying to read {path}') from None + + file_text = file_text.expandtabs() + + file_text_lines = file_text.split('\n') + num_lines = len(file_text_lines) + + _validate_range(lines_range, num_lines) + + start_line, end_line = lines_range # inclusive + + new_file_text_lines = ( + file_text_lines[:start_line] + + file_text_lines[end_line + 1:] + ) + snippet_lines = ( + file_text_lines[max(0, insert_line - SNIPPET_CONTEXT_WINDOW) : start_line] + + file_text_lines[ + end_line + 1 : min(num_lines, insert_line + SNIPPET_CONTEXT_WINDOW) + ] + ) + new_file_text = '\n'.join(new_file_text_lines) + snippet = '\n'.join(snippet_lines) + + self.write_file(path, new_file_text) + self._file_history[path].append(file_text) + + success_message = f'The file {path} has been edited. ' + success_message += self._make_output( + snippet, + 'a snippet of the edited file', + max(1, insert_line - SNIPPET_CONTEXT_WINDOW + 1), + ) + + if enable_linting: + # Run linting on the changes + lint_results = self._run_linting(file_text, new_file_text, path) + success_message += '\n' + lint_results + '\n' + + success_message += 'Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.' + return CLIResult(output=success_message) + + def move_code_block(from_file: Path, from_range: list[int], dst_file: Path, insert_line: int) -> CLIResult: + """ + Move a block of code from one file to another. + """ + file_content_lines = file_content.split('\n') + start_line, end_line = view_range + code_block = '\n'.join( + file_content_lines[start_line - 1 :] if end_line == -1 else + file_content_lines[start_line - 1 : end_line] + ) + self.delete(from_file, from_range) + self.insert(dst_file, insert_line, code_block, True) + def validate_path(self, command: Command, path: Path) -> None: """ Check that the path/command combination is valid. @@ -307,6 +360,37 @@ def validate_path(self, command: Command, path: Path) -> None: f'The path {path} is a directory and only the `view` command can be used on directories.', ) + def _validate_range(self, lines_range: list[int], num_lines): + if len(lines_range) != 2 or not all(isinstance(i, int) for i in lines_range): + raise EditorToolParameterInvalidError( + 'lines_range', + lines_range, + 'It should be a list of two integers.', + ) + + start_line, end_line = lines_range + + if start_line < 1 or start_line > num_lines: + raise EditorToolParameterInvalidError( + 'lines_range', + lines_range, + f'Its first element `{start_line}` should be within the range of lines of the file: {[1, num_lines]}.', + ) + + if end_line > num_lines: + raise EditorToolParameterInvalidError( + 'lines_range', + lines_range, + f'Its second element `{end_line}` should be smaller than the number of lines in the file: `{num_lines}`.', + ) + + if end_line != -1 and end_line < start_line: + raise EditorToolParameterInvalidError( + 'lines_range', + lines_range, + f'Its second element `{end_line}` should be greater than or equal to the first element `{start_line}`.', + ) + def undo_edit(self, path: Path) -> CLIResult: """ Implement the undo_edit command. diff --git a/pyproject.toml b/pyproject.toml index 16000c9..41510cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ packages = [ ] [tool.poetry.dependencies] -python = "^3.12" +python = "^3.11" numpy = "*" pandas = "*" scipy = "*" From a75945ee4a8be506def4d39da3a456d85c5c60be Mon Sep 17 00:00:00 2001 From: RajWorking Date: Sat, 16 Nov 2024 18:23:00 +0000 Subject: [PATCH 2/7] Minor bug fixes and added tests. --- openhands_aci/editor/editor.py | 40 ++++++++++++++------------- tests/integration/test_file_editor.py | 38 +++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/openhands_aci/editor/editor.py b/openhands_aci/editor/editor.py index 3eef798..f975299 100644 --- a/openhands_aci/editor/editor.py +++ b/openhands_aci/editor/editor.py @@ -61,9 +61,7 @@ def __call__( **kwargs, ) -> ToolResult | CLIResult: _path = Path(path) - _new_path = Path(path) self.validate_path(command, _path) - self.validate_path(command, _new_path) if command == 'view': return self.view(_path, lines_range) elif command == 'create': @@ -97,7 +95,11 @@ def __call__( raise EditorToolParameterMissingError(command, 'lines_range') if insert_line is None: raise EditorToolParameterMissingError(command, 'insert_line') - return self.move_code_block(_path, lines_range, _dst_file, insert_line) + if not dst_path: + raise EditorToolParameterMissingError(command, 'dst_path') + _dst_path = Path(dst_path) + self.validate_path(command, _dst_path) + return self.move_code_block(_path, lines_range, _dst_path, insert_line) elif command == 'undo_edit': return self.undo_edit(_path) @@ -190,7 +192,7 @@ def view(self, path: Path, view_range: list[int] | None = None) -> CLIResult: ) num_lines = len(file_content_lines) - _validate_range(view_range, num_lines) + self._validate_range(view_range, num_lines) start_line, end_line = view_range if end_line == -1: @@ -280,7 +282,7 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult: file_text_lines = file_text.split('\n') num_lines = len(file_text_lines) - _validate_range(lines_range, num_lines) + self._validate_range(lines_range, num_lines) start_line, end_line = lines_range # inclusive @@ -289,9 +291,9 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult: + file_text_lines[end_line + 1:] ) snippet_lines = ( - file_text_lines[max(0, insert_line - SNIPPET_CONTEXT_WINDOW) : start_line] + file_text_lines[max(0, start_line - SNIPPET_CONTEXT_WINDOW) : start_line] + file_text_lines[ - end_line + 1 : min(num_lines, insert_line + SNIPPET_CONTEXT_WINDOW) + end_line + 1 : min(num_lines, end_line + SNIPPET_CONTEXT_WINDOW) ] ) new_file_text = '\n'.join(new_file_text_lines) @@ -304,29 +306,29 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult: success_message += self._make_output( snippet, 'a snippet of the edited file', - max(1, insert_line - SNIPPET_CONTEXT_WINDOW + 1), + # max(1, start_line - SNIPPET_CONTEXT_WINDOW + 1), ) - if enable_linting: - # Run linting on the changes - lint_results = self._run_linting(file_text, new_file_text, path) - success_message += '\n' + lint_results + '\n' - success_message += 'Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.' return CLIResult(output=success_message) - def move_code_block(from_file: Path, from_range: list[int], dst_file: Path, insert_line: int) -> CLIResult: + def move_code_block(self, from_file: Path, from_range: list[int], dst_file: Path, insert_line: int) -> CLIResult: """ Move a block of code from one file to another. """ + file_content = self.read_file(from_file) file_content_lines = file_content.split('\n') - start_line, end_line = view_range + start_line, end_line = from_range code_block = '\n'.join( - file_content_lines[start_line - 1 :] if end_line == -1 else - file_content_lines[start_line - 1 : end_line] + file_content_lines[start_line:] if end_line == -1 else + file_content_lines[start_line: end_line + 1] + ) + delete_result = self.delete(from_file, from_range) + insert_result = self.insert(dst_file, insert_line, code_block, True) + + return CLIResult( + output=f'Code block moved from {from_file} to {dst_file}.\n{delete_result.output}\n{insert_result.output}' ) - self.delete(from_file, from_range) - self.insert(dst_file, insert_line, code_block, True) def validate_path(self, command: Command, path: Path) -> None: """ diff --git a/tests/integration/test_file_editor.py b/tests/integration/test_file_editor.py index 43cb441..546c3f0 100644 --- a/tests/integration/test_file_editor.py +++ b/tests/integration/test_file_editor.py @@ -159,6 +159,44 @@ def test_insert_with_linting(editor): Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" ) +def test_move_code_block(editor): + editor, test_file = editor + test_file.write_text('This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz') + + second_test_file = test_file.parent / 'second_test.txt' + second_test_file.write_text('This is also a test file.\nSome text should be added above this.') + + result = editor( + command='move_code_block', + path=str(test_file), + dst_path=str(second_test_file), + lines_range=[2, 3], + insert_line=1, + ) + assert isinstance(result, CLIResult) + assert 'foo' not in test_file.read_text() + assert 'bar' not in test_file.read_text() + assert 'foo' in second_test_file.read_text() + assert 'bar' in second_test_file.read_text() + print(result.output) + assert ( + result.output + == f"""Code block moved from {test_file} to {second_test_file}. +The file {test_file} has been edited. Here's the result of running `cat -n` on a snippet of the edited file: + 1\tThis is a test file. + 2\tThis file is for testing purposes. + 3\tbaz +Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary. +The file {second_test_file} has been edited. Here's the result of running `cat -n` on a snippet of the edited file: + 1\tThis is also a test file. + 2\tfoo + 3\tbar + 4\tSome text should be added above this. + +No linting issues found in the changes. +Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" + ) + def test_insert_invalid_line(editor): editor, test_file = editor From 57fba0966c727c620805ffda3f7cd9bec20861c8 Mon Sep 17 00:00:00 2001 From: RajWorking Date: Sat, 16 Nov 2024 18:57:27 +0000 Subject: [PATCH 3/7] . --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 41510cb..16000c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ packages = [ ] [tool.poetry.dependencies] -python = "^3.11" +python = "^3.12" numpy = "*" pandas = "*" scipy = "*" From 182079ccb0c268aa3959918fef69fd572e4857f2 Mon Sep 17 00:00:00 2001 From: RajWorking Date: Sat, 16 Nov 2024 19:01:54 +0000 Subject: [PATCH 4/7] lint --- openhands_aci/editor/editor.py | 14 ++++++++------ tests/integration/test_file_editor.py | 9 +++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/openhands_aci/editor/editor.py b/openhands_aci/editor/editor.py index f975299..ab583fc 100644 --- a/openhands_aci/editor/editor.py +++ b/openhands_aci/editor/editor.py @@ -284,11 +284,10 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult: self._validate_range(lines_range, num_lines) - start_line, end_line = lines_range # inclusive + start_line, end_line = lines_range # inclusive new_file_text_lines = ( - file_text_lines[:start_line] - + file_text_lines[end_line + 1:] + file_text_lines[:start_line] + file_text_lines[end_line + 1:] ) snippet_lines = ( file_text_lines[max(0, start_line - SNIPPET_CONTEXT_WINDOW) : start_line] @@ -312,7 +311,9 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult: success_message += 'Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.' return CLIResult(output=success_message) - def move_code_block(self, from_file: Path, from_range: list[int], dst_file: Path, insert_line: int) -> CLIResult: + def move_code_block( + self, from_file: Path, from_range: list[int], dst_file: Path, insert_line: int + ) -> CLIResult: """ Move a block of code from one file to another. """ @@ -320,8 +321,9 @@ def move_code_block(self, from_file: Path, from_range: list[int], dst_file: Path file_content_lines = file_content.split('\n') start_line, end_line = from_range code_block = '\n'.join( - file_content_lines[start_line:] if end_line == -1 else - file_content_lines[start_line: end_line + 1] + file_content_lines[start_line:] + if end_line == -1 + else file_content_lines[start_line: end_line + 1] ) delete_result = self.delete(from_file, from_range) insert_result = self.insert(dst_file, insert_line, code_block, True) diff --git a/tests/integration/test_file_editor.py b/tests/integration/test_file_editor.py index 546c3f0..de81037 100644 --- a/tests/integration/test_file_editor.py +++ b/tests/integration/test_file_editor.py @@ -159,12 +159,17 @@ def test_insert_with_linting(editor): Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" ) + def test_move_code_block(editor): editor, test_file = editor - test_file.write_text('This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz') + test_file.write_text( + 'This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz' + ) second_test_file = test_file.parent / 'second_test.txt' - second_test_file.write_text('This is also a test file.\nSome text should be added above this.') + second_test_file.write_text( + 'This is also a test file.\nSome text should be added above this.' + ) result = editor( command='move_code_block', From 6cd591bd3d4e04a90b9f1188bda8bae4ec9d027b Mon Sep 17 00:00:00 2001 From: RajWorking Date: Mon, 18 Nov 2024 18:50:12 +0000 Subject: [PATCH 5/7] Made some fixes --- .gitignore | 2 +- openhands_aci/editor/editor.py | 33 ++++++++++++--------------- tests/integration/test_file_editor.py | 22 ++++++++++++++++++ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 29a4fff..321b8aa 100644 --- a/.gitignore +++ b/.gitignore @@ -99,7 +99,7 @@ ipython_config.py # This is especially recommended for binary packages to ensure reproducibility, and is more # commonly ignored for libraries. # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -poetry.lock +#poetry.lock # pdm # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. diff --git a/openhands_aci/editor/editor.py b/openhands_aci/editor/editor.py index ab583fc..356f10c 100644 --- a/openhands_aci/editor/editor.py +++ b/openhands_aci/editor/editor.py @@ -87,12 +87,8 @@ def __call__( raise EditorToolParameterMissingError(command, 'new_str') return self.insert(_path, insert_line, new_str, enable_linting) elif command == 'delete': - if not lines_range: - raise EditorToolParameterMissingError(command, 'lines_range') return self.delete(_path, lines_range) elif command == 'move_code_block': - if not lines_range: - raise EditorToolParameterMissingError(command, 'lines_range') if insert_line is None: raise EditorToolParameterMissingError(command, 'insert_line') if not dst_path: @@ -268,20 +264,17 @@ def insert( success_message += 'Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.' return CLIResult(output=success_message) - def delete(self, path: Path, lines_range: list[int]) -> CLIResult: + def delete(self, path: Path, lines_range: list[int] | None = None) -> CLIResult: """ Deletes text content in file from the given range. """ - try: - file_text = self.read_file(path) - except Exception as e: - raise ToolError(f'Ran into {e} while trying to read {path}') from None - - file_text = file_text.expandtabs() - + file_text = self.read_file(path).expandtabs() file_text_lines = file_text.split('\n') num_lines = len(file_text_lines) + if not lines_range: + lines_range = [0, num_lines - 1] # Delete all lines + self._validate_range(lines_range, num_lines) start_line, end_line = lines_range # inclusive @@ -312,24 +305,28 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult: return CLIResult(output=success_message) def move_code_block( - self, from_file: Path, from_range: list[int], dst_file: Path, insert_line: int + self, path: Path, from_range: list[int] | None, dst_path: Path, insert_line: int ) -> CLIResult: """ Move a block of code from one file to another. """ - file_content = self.read_file(from_file) - file_content_lines = file_content.split('\n') + file_content_lines = self.read_file(path).expandtabs().split('\n') + num_lines = len(file_content_lines) + + if not from_range: + from_range = [0, num_lines - 1] # Delete all lines + start_line, end_line = from_range code_block = '\n'.join( file_content_lines[start_line:] if end_line == -1 else file_content_lines[start_line: end_line + 1] ) - delete_result = self.delete(from_file, from_range) - insert_result = self.insert(dst_file, insert_line, code_block, True) + delete_result = self.delete(path, from_range) + insert_result = self.insert(dst_path, insert_line, code_block, True) return CLIResult( - output=f'Code block moved from {from_file} to {dst_file}.\n{delete_result.output}\n{insert_result.output}' + output=f'Code block moved from {path} to {dst_path}.\n{delete_result.output}\n{insert_result.output}' ) def validate_path(self, command: Command, path: Path) -> None: diff --git a/tests/integration/test_file_editor.py b/tests/integration/test_file_editor.py index de81037..fccfa42 100644 --- a/tests/integration/test_file_editor.py +++ b/tests/integration/test_file_editor.py @@ -159,6 +159,28 @@ def test_insert_with_linting(editor): Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" ) +def test_delete_block(editor): + editor, test_file = editor + test_file.write_text( + 'This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz' + ) + result = editor( + command='delete', + path=str(test_file), + lines_range=[2, 3], + ) + assert isinstance(result, CLIResult) + assert 'foo' not in test_file.read_text() + assert 'bar' not in test_file.read_text() + print(result.output) + assert ( + result.output + == f"""The file {test_file} has been edited. Here's the result of running `cat -n` on a snippet of the edited file: + 1\tThis is a test file. + 2\tThis file is for testing purposes. + 3\tbaz +Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""") + def test_move_code_block(editor): editor, test_file = editor From 8aa3577963d88817cc41b513f33f211d38f9c279 Mon Sep 17 00:00:00 2001 From: RajWorking Date: Mon, 18 Nov 2024 18:52:33 +0000 Subject: [PATCH 6/7] lint errors --- openhands_aci/editor/editor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openhands_aci/editor/editor.py b/openhands_aci/editor/editor.py index 356f10c..3406734 100644 --- a/openhands_aci/editor/editor.py +++ b/openhands_aci/editor/editor.py @@ -280,7 +280,7 @@ def delete(self, path: Path, lines_range: list[int] | None = None) -> CLIResult: start_line, end_line = lines_range # inclusive new_file_text_lines = ( - file_text_lines[:start_line] + file_text_lines[end_line + 1:] + file_text_lines[:start_line] + file_text_lines[end_line + 1 :] ) snippet_lines = ( file_text_lines[max(0, start_line - SNIPPET_CONTEXT_WINDOW) : start_line] @@ -305,8 +305,8 @@ def delete(self, path: Path, lines_range: list[int] | None = None) -> CLIResult: return CLIResult(output=success_message) def move_code_block( - self, path: Path, from_range: list[int] | None, dst_path: Path, insert_line: int - ) -> CLIResult: + self, path: Path, from_range: list[int] | None, dst_path: Path, insert_line: int + ) -> CLIResult: """ Move a block of code from one file to another. """ @@ -320,7 +320,7 @@ def move_code_block( code_block = '\n'.join( file_content_lines[start_line:] if end_line == -1 - else file_content_lines[start_line: end_line + 1] + else file_content_lines[start_line : end_line + 1] ) delete_result = self.delete(path, from_range) insert_result = self.insert(dst_path, insert_line, code_block, True) From 68da3cd14629f3fd7c706b9a5b375504e9fe9ed8 Mon Sep 17 00:00:00 2001 From: RajWorking Date: Mon, 18 Nov 2024 18:54:09 +0000 Subject: [PATCH 7/7] lint errors --- tests/integration/test_file_editor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_file_editor.py b/tests/integration/test_file_editor.py index fccfa42..cffcf62 100644 --- a/tests/integration/test_file_editor.py +++ b/tests/integration/test_file_editor.py @@ -159,6 +159,7 @@ def test_insert_with_linting(editor): Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" ) + def test_delete_block(editor): editor, test_file = editor test_file.write_text( @@ -179,7 +180,8 @@ def test_delete_block(editor): 1\tThis is a test file. 2\tThis file is for testing purposes. 3\tbaz -Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""") +Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.""" + ) def test_move_code_block(editor):