mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-14 14:17:49 +00:00
CodeEditor: Remove unused management of edited files
Management was unnecessarily introduced by AI in 133e1be2a780ee875a9b7d739e076b85d81b29fd
This commit is contained in:
1 parent
061020ce22
commit
5ab912ca0b
2 files changed
+2
-49
No files matched your search
@@ -13,7 +13,6 @@ from solidlsp.ls import LSPFileBuffer
|
||||
from solidlsp.ls_utils import PathUtils, TextUtils
|
||||
|
||||
from .project import Project
|
||||
from .util.ls_diagnostics import EditedFilePath
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
TSymbol = TypeVar("TSymbol", bound=Symbol)
|
||||
@@ -24,7 +23,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
self.project_root = project.project_root
|
||||
self.encoding = project.project_config.encoding
|
||||
self.newline = project.line_ending.newline_str
|
||||
self._last_edited_file_paths: list[EditedFilePath] = []
|
||||
|
||||
class EditedFile(ABC):
|
||||
def __init__(self, relative_path: str) -> None:
|
||||
@@ -85,20 +83,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
with open(abs_path, "w", encoding=self.encoding, newline=self.newline) as f:
|
||||
f.write(new_contents)
|
||||
|
||||
def _set_last_edited_file_paths(self, edited_file_paths: Iterable[EditedFilePath]) -> None:
|
||||
unique_paths: list[EditedFilePath] = []
|
||||
seen_keys: set[tuple[str, str]] = set()
|
||||
for edited_file_path in edited_file_paths:
|
||||
key = (edited_file_path.before_relative_path, edited_file_path.after_relative_path)
|
||||
if key in seen_keys:
|
||||
continue
|
||||
seen_keys.add(key)
|
||||
unique_paths.append(edited_file_path)
|
||||
self._last_edited_file_paths = unique_paths
|
||||
|
||||
def get_last_edited_file_paths(self) -> list[EditedFilePath]:
|
||||
return list(self._last_edited_file_paths)
|
||||
|
||||
@abstractmethod
|
||||
def _find_unique_symbol(self, name_path: str, relative_file_path: str) -> TSymbol:
|
||||
"""
|
||||
@@ -130,8 +114,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
edited_file.delete_text_between_positions(start_pos, end_pos)
|
||||
edited_file.insert_text_at_position(start_pos, body)
|
||||
|
||||
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
|
||||
|
||||
@staticmethod
|
||||
def _count_leading_newlines(text: Iterable) -> int:
|
||||
cnt = 0
|
||||
@@ -189,8 +171,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
with self.edited_file_context(relative_file_path) as edited_file:
|
||||
edited_file.insert_text_at_position(PositionInFile(line, col), body)
|
||||
|
||||
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
|
||||
|
||||
def insert_before_symbol(self, name_path: str, relative_file_path: str, body: str) -> None:
|
||||
"""
|
||||
Inserts content before the symbol with the given name in the given file.
|
||||
@@ -219,8 +199,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
with self.edited_file_context(relative_file_path) as edited_file:
|
||||
edited_file.insert_text_at_position(PositionInFile(line=line, col=col), body)
|
||||
|
||||
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
|
||||
|
||||
def insert_at_line(self, relative_path: str, line: int, content: str) -> None:
|
||||
"""
|
||||
Inserts content at the given line in the given file.
|
||||
@@ -232,8 +210,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
with self.edited_file_context(relative_path) as edited_file:
|
||||
edited_file.insert_text_at_position(PositionInFile(line, 0), content)
|
||||
|
||||
self._set_last_edited_file_paths([EditedFilePath(relative_path, relative_path)])
|
||||
|
||||
def delete_lines(self, relative_path: str, start_line: int, end_line: int) -> None:
|
||||
"""
|
||||
Deletes lines in the given file.
|
||||
@@ -250,8 +226,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
end_pos = PositionInFile(line=end_line_for_delete, col=end_col)
|
||||
edited_file.delete_text_between_positions(start_pos, end_pos)
|
||||
|
||||
self._set_last_edited_file_paths([EditedFilePath(relative_path, relative_path)])
|
||||
|
||||
def delete_symbol(self, name_path: str, relative_file_path: str) -> None:
|
||||
"""
|
||||
Deletes the symbol with the given name in the given file.
|
||||
@@ -262,8 +236,6 @@ class CodeEditor(Generic[TSymbol], ABC):
|
||||
with self.edited_file_context(relative_file_path) as edited_file:
|
||||
edited_file.delete_text_between_positions(start_pos, end_pos)
|
||||
|
||||
self._set_last_edited_file_paths([EditedFilePath(relative_file_path, relative_file_path)])
|
||||
|
||||
@abstractmethod
|
||||
def rename_symbol(self, name_path: str, relative_path: str, new_name: str) -> str:
|
||||
pass
|
||||
@@ -320,10 +292,6 @@ class LanguageServerCodeEditor(CodeEditor[LanguageServerSymbol]):
|
||||
def apply(self) -> None:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_edited_file_paths(self) -> list[EditedFilePath]:
|
||||
pass
|
||||
|
||||
class EditOperationFileTextEdits(EditOperation):
|
||||
def __init__(self, code_editor: "LanguageServerCodeEditor", file_uri: str, text_edits: list[ls_types.TextEdit]):
|
||||
self._code_editor = code_editor
|
||||
@@ -335,9 +303,6 @@ class LanguageServerCodeEditor(CodeEditor[LanguageServerSymbol]):
|
||||
edited_file = cast(LanguageServerCodeEditor.EditedFile, edited_file)
|
||||
edited_file.apply_text_edits(self._text_edits)
|
||||
|
||||
def get_edited_file_paths(self) -> list[EditedFilePath]:
|
||||
return [EditedFilePath(self._relative_path, self._relative_path)]
|
||||
|
||||
class EditOperationRenameFile(EditOperation):
|
||||
def __init__(self, code_editor: "LanguageServerCodeEditor", old_uri: str, new_uri: str):
|
||||
self._code_editor = code_editor
|
||||
@@ -349,9 +314,6 @@ class LanguageServerCodeEditor(CodeEditor[LanguageServerSymbol]):
|
||||
new_abs_path = os.path.join(self._code_editor.project_root, self._new_relative_path)
|
||||
os.rename(old_abs_path, new_abs_path)
|
||||
|
||||
def get_edited_file_paths(self) -> list[EditedFilePath]:
|
||||
return [EditedFilePath(self._old_relative_path, self._new_relative_path)]
|
||||
|
||||
def _workspace_edit_to_edit_operations(self, workspace_edit: ls_types.WorkspaceEdit) -> list["LanguageServerCodeEditor.EditOperation"]:
|
||||
operations: list[LanguageServerCodeEditor.EditOperation] = []
|
||||
|
||||
@@ -381,15 +343,6 @@ class LanguageServerCodeEditor(CodeEditor[LanguageServerSymbol]):
|
||||
:return: number of edit operations applied
|
||||
"""
|
||||
operations = self._workspace_edit_to_edit_operations(workspace_edit)
|
||||
|
||||
# recording the affected files
|
||||
edited_file_paths: list[EditedFilePath] = []
|
||||
for operation in operations:
|
||||
edited_file_paths.extend(operation.get_edited_file_paths())
|
||||
|
||||
self._set_last_edited_file_paths(edited_file_paths)
|
||||
|
||||
# applying the edit operations
|
||||
for operation in operations:
|
||||
operation.apply()
|
||||
return len(operations)
|
||||
|
||||
@@ -427,8 +427,8 @@ class EditingToolWithDiagnostics(Tool, ToolMarkerCanEdit):
|
||||
self._before_edit_diagnostics_snapshot: PublishedDiagnosticsSnapshot | None = None
|
||||
self._symbol_retriever: Optional["LanguageServerSymbolRetriever"] | None = None
|
||||
if self._is_diagnostics_enabled:
|
||||
symbol_retriever = tool.create_language_server_symbol_retriever()
|
||||
self._before_edit_diagnostics_snapshot = PublishedDiagnosticsSnapshot(self._edited_files, symbol_retriever)
|
||||
self._symbol_retriever = tool.create_language_server_symbol_retriever()
|
||||
self._before_edit_diagnostics_snapshot = PublishedDiagnosticsSnapshot(self._edited_files, self._symbol_retriever)
|
||||
|
||||
def __enter__(self) -> Self:
|
||||
return self
|
||||
|
||||
Reference in new issue
Block a user