mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 14:16:21 +00:00
Various minor improvements (review comments)
This commit is contained in:
1 parent
6c53fd130a
commit
dd5065f180
4 files changed
+25
-41
No files matched your search
@@ -1,2 +0,0 @@
|
||||
|
||||
us: UnifiedSymbolInformation (return format of many low-level language server symbol requests)
|
||||
+20
-35
@@ -188,9 +188,7 @@ class NamePathMatcher(ToStringMixin):
|
||||
|
||||
|
||||
class LanguageServerSymbol(Symbol, ToStringMixin):
|
||||
def __init__(
|
||||
self, symbol_root_from_ls: UnifiedSymbolInformation, docstring: str | None = None, signature_string: str | None = None
|
||||
) -> None:
|
||||
def __init__(self, symbol_root_from_ls: UnifiedSymbolInformation) -> None:
|
||||
self.symbol_root = symbol_root_from_ls
|
||||
|
||||
def _tostring_includes(self) -> list[str]:
|
||||
@@ -498,7 +496,7 @@ class LanguageServerSymbolRetriever:
|
||||
self._ls_manager: LanguageServerManager = ls_manager
|
||||
self.agent = agent
|
||||
|
||||
def request_info(self, relative_file_path: str, line: int, column: int) -> str | None:
|
||||
def _request_info(self, relative_file_path: str, line: int, column: int) -> str | None:
|
||||
"""Retrieves information (in a sanitized format) about the symbol at the desired location,
|
||||
typically containing the docstring and signature.
|
||||
|
||||
@@ -509,40 +507,27 @@ class LanguageServerSymbolRetriever:
|
||||
if hover_info is None:
|
||||
return None
|
||||
contents = hover_info["contents"]
|
||||
try:
|
||||
# Handle various response formats
|
||||
if isinstance(contents, list):
|
||||
# Array format: extract all parts and join them
|
||||
stripped_parts = []
|
||||
for part in contents:
|
||||
if isinstance(part, str) and (stripped_part := part.strip()):
|
||||
stripped_parts.append(stripped_part)
|
||||
else:
|
||||
# should be a dict with "value" key
|
||||
stripped_parts.append(part["value"].strip()) # type: ignore
|
||||
return "\n".join(stripped_parts) if stripped_parts else None
|
||||
if isinstance(contents, dict) and (stripped_contents := contents.get("value", "").strip()):
|
||||
return stripped_contents
|
||||
if isinstance(contents, str) and (stripped_contents := contents.strip()):
|
||||
return stripped_contents
|
||||
except (KeyError, IndexError, TypeError):
|
||||
pass
|
||||
# Handle various response formats
|
||||
if isinstance(contents, list):
|
||||
# Array format: extract all parts and join them
|
||||
stripped_parts = []
|
||||
for part in contents:
|
||||
if isinstance(part, str) and (stripped_part := part.strip()):
|
||||
stripped_parts.append(stripped_part)
|
||||
else:
|
||||
# should be a dict with "value" key
|
||||
stripped_parts.append(part["value"].strip()) # type: ignore
|
||||
return "\n".join(stripped_parts) if stripped_parts else None
|
||||
if isinstance(contents, dict) and (stripped_contents := contents.get("value", "").strip()):
|
||||
return stripped_contents
|
||||
if isinstance(contents, str) and (stripped_contents := contents.strip()):
|
||||
return stripped_contents
|
||||
return None
|
||||
|
||||
def request_info_for_us(self, us: UnifiedSymbolInformation) -> str | None:
|
||||
relative_path = us["location"]["relativePath"]
|
||||
if relative_path is None:
|
||||
return None
|
||||
return self.request_info(
|
||||
relative_file_path=relative_path,
|
||||
# we need to use selectionRange for hover,
|
||||
# as range typically starts at the symbol definition (at def, class, etc.) where no hover info is available
|
||||
line=us["selectionRange"]["start"]["line"],
|
||||
column=us["selectionRange"]["start"]["character"],
|
||||
)
|
||||
|
||||
def request_info_for_symbol(self, symbol: LanguageServerSymbol) -> str | None:
|
||||
return self.request_info_for_us(symbol.symbol_root)
|
||||
if None in [symbol.relative_path, symbol.line, symbol.column]:
|
||||
return None
|
||||
return self._request_info(relative_file_path=symbol.relative_path, line=symbol.line, column=symbol.column) # type: ignore[arg-type]
|
||||
|
||||
def get_root_path(self) -> str:
|
||||
return self._ls_manager.get_root_path()
|
||||
|
||||
@@ -177,8 +177,8 @@ class JetBrainsTypeHierarchyTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptiona
|
||||
:param name_path: name path of the symbol for which to get the type hierarchy.
|
||||
:param relative_path: the relative path to the file containing the symbol.
|
||||
:param hierarchy_type: which hierarchy to retrieve: "super" for parent classes/interfaces,
|
||||
"sub" for subclasses/implementations, or "both" for both directions.
|
||||
:param depth: depth limit for hierarchy traversal (None or 0 for unlimited).
|
||||
"sub" for subclasses/implementations, or "both" for both directions. Default is "sub".
|
||||
:param depth: depth limit for hierarchy traversal (None or 0 for unlimited). Default is 1.
|
||||
:param max_answer_chars: max characters for the JSON result. If exceeded, no content is returned.
|
||||
-1 means the default value from the config will be used.
|
||||
:return: Compact JSON with file-grouped hierarchy. Error string if not applicable.
|
||||
|
||||
@@ -114,14 +114,15 @@ class FindSymbolTool(Tool, ToolMarkerSymbolicRead):
|
||||
|
||||
:param name_path_pattern: the name path matching pattern (see above)
|
||||
:param depth: depth up to which descendants shall be retrieved (e.g. use 1 to also retrieve immediate children;
|
||||
for the case where the symbol is a class, this will return its methods).
|
||||
for the case where the symbol is a class, this will return its methods). Default 0.
|
||||
:param relative_path: Optional. Restrict search to this file or directory. If None, searches entire codebase.
|
||||
If a directory is passed, the search will be restricted to the files in that directory.
|
||||
If a file is passed, the search will be restricted to that file.
|
||||
If you have some knowledge about the codebase, you should use this parameter, as it will significantly
|
||||
speed up the search as well as reduce the number of results.
|
||||
:param include_body: whether to include the symbol's source code. Use judiciously.
|
||||
:param include_info: whether to include additional info about the symbol (ignored if include_body is True).
|
||||
:param include_info: whether to include additional info (hover-like, typically including docstring and signature),
|
||||
about the symbol (ignored if include_body is True). Default True, info is never included for child symbols.
|
||||
:param include_kinds: List of LSP symbol kind integers to include.
|
||||
If not provided, all kinds are included.
|
||||
:param exclude_kinds: Optional. List of LSP symbol kind integers to exclude. Takes precedence over `include_kinds`.
|
||||
|
||||
Reference in new issue
Block a user