mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-12 20:15:56 +00:00
Feature: move symbol WIP
This commit is contained in:
1 parent
3912a07fcb
commit
20e14fa158
2 files changed
+46
-1
No files matched your search
@@ -425,6 +425,21 @@ class JetBrainsPluginClient(ToStringMixin):
|
||||
self._postprocess_symbol_collection_response(symbol_collection)
|
||||
return symbol_collection
|
||||
|
||||
def move_symbol(
|
||||
self,
|
||||
name_path: str | None,
|
||||
relative_path: str | None,
|
||||
target_parent_name_path: str | None,
|
||||
target_relative_path: str | None,
|
||||
) -> dict[str, Any]:
|
||||
request_data = {
|
||||
"namePath": name_path,
|
||||
"relativePath": relative_path,
|
||||
"targetParentNamePath": target_parent_name_path,
|
||||
"targetRelativePath": target_relative_path,
|
||||
}
|
||||
return self._make_request("POST", "/moveSymbol", request_data)
|
||||
|
||||
def find_references(self, name_path: str, relative_path: str, include_quick_info: bool) -> jb.SymbolCollectionResponse:
|
||||
"""
|
||||
Finds references to a symbol.
|
||||
|
||||
@@ -6,7 +6,7 @@ import serena.jetbrains.jetbrains_types as jb
|
||||
from serena.jetbrains.jetbrains_plugin_client import JetBrainsPluginClient
|
||||
from serena.jetbrains.jetbrains_types import SymbolDTO
|
||||
from serena.symbol import JetBrainsSymbolDictGrouper
|
||||
from serena.tools import Tool, ToolMarkerOptional, ToolMarkerSymbolicRead
|
||||
from serena.tools import Tool, ToolMarkerOptional, ToolMarkerSymbolicEdit, ToolMarkerSymbolicRead
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -111,6 +111,36 @@ class JetBrainsFindSymbolTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional):
|
||||
return self._limit_length(result, max_answer_chars, shortened_result_factories=[create_shortened_result])
|
||||
|
||||
|
||||
class JetBrainsMoveSymbolTool(Tool, ToolMarkerSymbolicEdit, ToolMarkerOptional):
|
||||
def apply(
|
||||
self,
|
||||
name_path: str | None = None,
|
||||
relative_path: str | None = None,
|
||||
target_parent_name_path: str | None = None,
|
||||
target_relative_path: str | None = None,
|
||||
) -> str:
|
||||
"""
|
||||
Moves a symbol to a different location (file or parent symbol) using the JetBrains refactoring engine.
|
||||
References to the symbol are automatically updated.
|
||||
|
||||
:param name_path: the name path of the symbol to move (e.g. "MyClass/my_method").
|
||||
:param relative_path: the relative path to the file containing the symbol to move.
|
||||
:param target_parent_name_path: the name path of the target parent symbol (e.g. "TargetClass").
|
||||
If None, the symbol is moved to the top level of the target file.
|
||||
:param target_relative_path: the relative path to the target file. If None, the symbol
|
||||
is moved within the same file.
|
||||
:return: JSON string with the result of the operation.
|
||||
"""
|
||||
with JetBrainsPluginClient.from_project(self.project) as client:
|
||||
response_dict = client.move_symbol(
|
||||
name_path=name_path,
|
||||
relative_path=relative_path,
|
||||
target_parent_name_path=target_parent_name_path,
|
||||
target_relative_path=target_relative_path,
|
||||
)
|
||||
return self._to_json(response_dict)
|
||||
|
||||
|
||||
class JetBrainsFindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional):
|
||||
"""
|
||||
Finds symbols that reference the given symbol using the JetBrains backend
|
||||
|
||||
Reference in new issue
Block a user