Skip to content

Commit 4344057

Browse files
committed
CodeEditor: Remove unused management of edited files
Management was unnecessarily introduced by AI in 133e1be
1 parent 4c3479e commit 4344057

2 files changed

Lines changed: 2 additions & 49 deletions

File tree

src/serena/code_editor.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from solidlsp.ls_utils import PathUtils, TextUtils
1414

1515
from .project import Project
16-
from .util.ls_diagnostics import EditedFilePath
1716

1817
log = logging.getLogger(__name__)
1918
TSymbol = TypeVar("TSymbol", bound=Symbol)
@@ -24,7 +23,6 @@ def __init__(self, project: Project) -> None:
2423
self.project_root = project.project_root
2524
self.encoding = project.project_config.encoding
2625
self.newline = project.line_ending.newline_str
27-
self._last_edited_file_paths: list[EditedFilePath] = []
2826

2927
class EditedFile(ABC):
3028
def __init__(self, relative_path: str) -> None:
@@ -85,20 +83,6 @@ def _save_edited_file(self, edited_file: "CodeEditor.EditedFile") -> None:
8583
with open(abs_path, "w", encoding=self.encoding, newline=self.newline) as f:
8684
f.write(new_contents)
8785

88-
def _set_last_edited_file_paths(self, edited_file_paths: Iterable[EditedFilePath]) -> None:
89-
unique_paths: list[EditedFilePath] = []
90-
seen_keys: set[tuple[str, str]] = set()
91-
for edited_file_path in edited_file_paths:
92-
key = (edited_file_path.before_relative_path, edited_file_path.after_relative_path)
93-
if key in seen_keys:
94-
continue
95-
seen_keys.add(key)
96-
unique_paths.append(edited_file_path)
97-
self._last_edited_file_paths = unique_paths
98-
99-
def get_last_edited_file_paths(self) -> list[EditedFilePath]:
100-
return list(self._last_edited_file_paths)
101-
10286
@abstractmethod
10387
def _find_unique_symbol(self, name_path: str, relative_file_path: str) -> TSymbol:
10488
"""
@@ -130,8 +114,6 @@ def replace_body(self, name_path: str, relative_file_path: str, body: str) -> No
130114
edited_file.delete_text_between_positions(start_pos, end_pos)
131115
edited_file.insert_text_at_position(start_pos, body)
132116

133-
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
134-
135117
@staticmethod
136118
def _count_leading_newlines(text: Iterable) -> int:
137119
cnt = 0
@@ -189,8 +171,6 @@ def insert_after_symbol(self, name_path: str, relative_file_path: str, body: str
189171
with self.edited_file_context(relative_file_path) as edited_file:
190172
edited_file.insert_text_at_position(PositionInFile(line, col), body)
191173

192-
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
193-
194174
def insert_before_symbol(self, name_path: str, relative_file_path: str, body: str) -> None:
195175
"""
196176
Inserts content before the symbol with the given name in the given file.
@@ -219,8 +199,6 @@ def insert_before_symbol(self, name_path: str, relative_file_path: str, body: st
219199
with self.edited_file_context(relative_file_path) as edited_file:
220200
edited_file.insert_text_at_position(PositionInFile(line=line, col=col), body)
221201

222-
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
223-
224202
def insert_at_line(self, relative_path: str, line: int, content: str) -> None:
225203
"""
226204
Inserts content at the given line in the given file.
@@ -232,8 +210,6 @@ def insert_at_line(self, relative_path: str, line: int, content: str) -> None:
232210
with self.edited_file_context(relative_path) as edited_file:
233211
edited_file.insert_text_at_position(PositionInFile(line, 0), content)
234212

235-
self._set_last_edited_file_paths([EditedFilePath(relative_path, relative_path)])
236-
237213
def delete_lines(self, relative_path: str, start_line: int, end_line: int) -> None:
238214
"""
239215
Deletes lines in the given file.
@@ -250,8 +226,6 @@ def delete_lines(self, relative_path: str, start_line: int, end_line: int) -> No
250226
end_pos = PositionInFile(line=end_line_for_delete, col=end_col)
251227
edited_file.delete_text_between_positions(start_pos, end_pos)
252228

253-
self._set_last_edited_file_paths([EditedFilePath(relative_path, relative_path)])
254-
255229
def delete_symbol(self, name_path: str, relative_file_path: str) -> None:
256230
"""
257231
Deletes the symbol with the given name in the given file.
@@ -262,8 +236,6 @@ def delete_symbol(self, name_path: str, relative_file_path: str) -> None:
262236
with self.edited_file_context(relative_file_path) as edited_file:
263237
edited_file.delete_text_between_positions(start_pos, end_pos)
264238

265-
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
266-
267239
@abstractmethod
268240
def rename_symbol(self, name_path: str, relative_path: str, new_name: str) -> str:
269241
pass
@@ -320,10 +292,6 @@ class EditOperation(ABC):
320292
def apply(self) -> None:
321293
pass
322294

323-
@abstractmethod
324-
def get_edited_file_paths(self) -> list[EditedFilePath]:
325-
pass
326-
327295
class EditOperationFileTextEdits(EditOperation):
328296
def __init__(self, code_editor: "LanguageServerCodeEditor", file_uri: str, text_edits: list[ls_types.TextEdit]):
329297
self._code_editor = code_editor
@@ -335,9 +303,6 @@ def apply(self) -> None:
335303
edited_file = cast(LanguageServerCodeEditor.EditedFile, edited_file)
336304
edited_file.apply_text_edits(self._text_edits)
337305

338-
def get_edited_file_paths(self) -> list[EditedFilePath]:
339-
return [EditedFilePath(self._relative_path, self._relative_path)]
340-
341306
class EditOperationRenameFile(EditOperation):
342307
def __init__(self, code_editor: "LanguageServerCodeEditor", old_uri: str, new_uri: str):
343308
self._code_editor = code_editor
@@ -349,9 +314,6 @@ def apply(self) -> None:
349314
new_abs_path = os.path.join(self._code_editor.project_root, self._new_relative_path)
350315
os.rename(old_abs_path, new_abs_path)
351316

352-
def get_edited_file_paths(self) -> list[EditedFilePath]:
353-
return [EditedFilePath(self._old_relative_path, self._new_relative_path)]
354-
355317
def _workspace_edit_to_edit_operations(self, workspace_edit: ls_types.WorkspaceEdit) -> list["LanguageServerCodeEditor.EditOperation"]:
356318
operations: list[LanguageServerCodeEditor.EditOperation] = []
357319

@@ -381,15 +343,6 @@ def _apply_workspace_edit(self, workspace_edit: ls_types.WorkspaceEdit) -> int:
381343
:return: number of edit operations applied
382344
"""
383345
operations = self._workspace_edit_to_edit_operations(workspace_edit)
384-
385-
# recording the affected files
386-
edited_file_paths: list[EditedFilePath] = []
387-
for operation in operations:
388-
edited_file_paths.extend(operation.get_edited_file_paths())
389-
390-
self._set_last_edited_file_paths(edited_file_paths)
391-
392-
# applying the edit operations
393346
for operation in operations:
394347
operation.apply()
395348
return len(operations)

src/serena/tools/tools_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ def __init__(self, tool: "EditingToolWithDiagnostics", *edited_relative_paths: s
425425
self._before_edit_diagnostics_snapshot: PublishedDiagnosticsSnapshot | None = None
426426
self._symbol_retriever: Optional["LanguageServerSymbolRetriever"] | None = None
427427
if self._is_diagnostics_enabled:
428-
symbol_retriever = tool.create_language_server_symbol_retriever()
429-
self._before_edit_diagnostics_snapshot = PublishedDiagnosticsSnapshot(self._edited_files, symbol_retriever)
428+
self._symbol_retriever = tool.create_language_server_symbol_retriever()
429+
self._before_edit_diagnostics_snapshot = PublishedDiagnosticsSnapshot(self._edited_files, self._symbol_retriever)
430430

431431
def __enter__(self) -> Self:
432432
return self

0 commit comments

Comments
 (0)