diff --git a/src/serena/code_editor.py b/src/serena/code_editor.py index ac3dca3a..eb60b2bb 100644 --- a/src/serena/code_editor.py +++ b/src/serena/code_editor.py @@ -422,7 +422,7 @@ class JetBrainsCodeEditor(CodeEditor[JetBrainsSymbol]): if len(symbols) > 1: raise ValueError( f"Found multiple {len(symbols)} symbols with name {name_path} in file {relative_file_path}. " - "Their locations are: \n " + json.dumps([s["text_range"] for s in symbols], indent=2) + "They are: \n " + json.dumps(symbols, indent=2) ) return JetBrainsSymbol(symbols[0], self._project) diff --git a/src/serena/tools/jetbrains_plugin_client.py b/src/serena/tools/jetbrains_plugin_client.py index 4d1fea89..19617eb2 100644 --- a/src/serena/tools/jetbrains_plugin_client.py +++ b/src/serena/tools/jetbrains_plugin_client.py @@ -142,7 +142,9 @@ class JetBrainsPluginClient(ToStringMixin): name_path: str, relative_path: str | None = None, include_body: bool = False, - include_info: bool = True, + include_quick_info: bool = True, + include_documentation: bool = False, + include_num_usages: bool = True, depth: int = 0, include_location: bool = False, search_deps: bool = False, @@ -153,7 +155,9 @@ class JetBrainsPluginClient(ToStringMixin): :param name_path: the name path to match :param relative_path: the relative path to which to restrict the search :param include_body: whether to include symbol body content - :param include_info: whether to include symbol info + :param include_quick_info: whether to include quick info + :param include_documentation: whether to include documentation + :param include_num_usages: whether to include number of usages :param depth: depth of children to include (0 = no children) :param include_location: whether to include symbol location information :param search_deps: whether to also search in dependencies @@ -165,19 +169,21 @@ class JetBrainsPluginClient(ToStringMixin): "depth": depth, "includeLocation": include_location, "searchDeps": search_deps, - "includeInfo": include_info, + "includeQuickInfo": include_quick_info, + "includeDocumentation": include_documentation, + "includeNumUsages": include_num_usages, } return cast(jb.SymbolCollectionResponse, self._make_request("POST", "/findSymbol", request_data)) - def find_references(self, name_path: str, relative_path: str, include_info: bool) -> jb.SymbolCollectionResponse: + def find_references(self, name_path: str, relative_path: str, include_quick_info: bool) -> jb.SymbolCollectionResponse: """ Finds references to a symbol. :param name_path: the name path of the symbol :param relative_path: the relative path - :param include_info: whether to include symbol info + :param include_quick_info: whether to include quick info about references """ - request_data = {"namePath": name_path, "relativePath": relative_path, "includeInfo": include_info} + request_data = {"namePath": name_path, "relativePath": relative_path, "includeQuickInfo": include_quick_info} return cast(jb.SymbolCollectionResponse, self._make_request("POST", "/findReferences", request_data)) def get_symbols_overview(self, relative_path: str, depth: int) -> jb.SymbolCollectionResponse: diff --git a/src/serena/tools/jetbrains_tools.py b/src/serena/tools/jetbrains_tools.py index 9ec7e456..ad65e365 100644 --- a/src/serena/tools/jetbrains_tools.py +++ b/src/serena/tools/jetbrains_tools.py @@ -1,6 +1,6 @@ import logging from collections import defaultdict -from typing import Any, Literal +from typing import Any, Literal, cast import serena.tools.jetbrains_types as jb from serena.text_utils import render_html @@ -21,7 +21,7 @@ class JetBrainsFindSymbolTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional): depth: int = 0, relative_path: str | None = None, include_body: bool = False, - include_info: bool = True, + include_info: bool = False, search_deps: bool = False, max_answer_chars: int = -1, ) -> str: @@ -62,27 +62,25 @@ class JetBrainsFindSymbolTool(Tool, ToolMarkerSymbolicRead, ToolMarkerOptional): """ if relative_path == ".": relative_path = None - if include_body: - include_info = False # we save tokens and don't include info if body is requested with JetBrainsPluginClient.from_project(self.project) as client: + include_documentation = include_info and not include_body + include_quick_info = not include_documentation and not include_info response_dict = client.find_symbol( name_path=name_path_pattern, relative_path=relative_path, depth=depth, include_body=include_body, - include_info=include_info, + include_documentation=include_documentation, + include_quick_info=include_quick_info, search_deps=search_deps, ) - # massage the response to include only 'info' field if requested (instead of both doc and quick info) - if not include_body and include_info: - symbols = response_dict["symbols"] - for symbol in symbols: - documentation = symbol.pop("documentation", None) - quick_info = symbol.pop("quick_info", None) - info = documentation if documentation else quick_info - if info: - symbol["info"] = render_html(info) # type: ignore + symbols = response_dict["symbols"] + for symbol in symbols: + for doc_field in ("documentation", "quick_info"): + if doc_html := symbol.get(doc_field): + doc_html = cast(str, doc_html) + symbol[doc_field] = render_html(doc_html) result = self._to_json(response_dict) return self._limit_length(result, max_answer_chars) @@ -97,7 +95,6 @@ class JetBrainsFindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead, ToolMark self, name_path: str, relative_path: str, - include_info: bool = True, max_answer_chars: int = -1, ) -> str: """ @@ -107,7 +104,6 @@ class JetBrainsFindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead, ToolMark :param name_path: name path of the symbol for which to find references; matching logic as described in find symbol tool. :param relative_path: the relative path to the file containing the symbol for which to find references. Note that here you can't pass a directory but must pass a file. - :param include_info: whether to include additional info (hover-like, typically including docstring and signature). :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: a list of JSON objects with the symbols referencing the requested symbol @@ -116,7 +112,7 @@ class JetBrainsFindReferencingSymbolsTool(Tool, ToolMarkerSymbolicRead, ToolMark response_dict = client.find_references( name_path=name_path, relative_path=relative_path, - include_info=include_info, + include_quick_info=True, ) result = self._to_json(response_dict) return self._limit_length(result, max_answer_chars) diff --git a/src/serena/tools/jetbrains_types.py b/src/serena/tools/jetbrains_types.py index 4398f468..fba344a9 100644 --- a/src/serena/tools/jetbrains_types.py +++ b/src/serena/tools/jetbrains_types.py @@ -40,7 +40,6 @@ class TypeHierarchyNodeDTO(TypedDict): class TypeHierarchyResponse(TypedDict): - symbol: NotRequired[SymbolDTO] hierarchy: NotRequired[list[TypeHierarchyNodeDTO]] error: NotRequired[str] num_levels_not_included: NotRequired[int]