From d497a07779e8edf0dbe7ebc708dc59471ac5264a Mon Sep 17 00:00:00 2001 From: Dominik Jain Date: Wed, 9 Jul 2025 22:59:41 +0200 Subject: [PATCH] Move 'symbol overview' function to SymbolManager to avoid using the LS directly in GetSymbolsOverviewTool --- src/serena/symbol.py | 14 ++++++++++++++ src/serena/tools/symbol_tools.py | 11 +++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/serena/symbol.py b/src/serena/symbol.py index 8161e94..5a85bb5 100644 --- a/src/serena/symbol.py +++ b/src/serena/symbol.py @@ -700,6 +700,20 @@ class SymbolManager: """Get the content of a file using the language server.""" return self._lang_server.language_server.retrieve_full_file_content(relative_path) + @dataclass + class SymbolOverviewElement: + name_path: str + kind: int + + def get_symbol_overview(self, relative_path: str) -> dict[str, list[SymbolOverviewElement]]: + path_to_symbol_infos = self._lang_server.request_overview(relative_path) + result = {} + for file_path, symbols in path_to_symbol_infos.items(): + # TODO: maybe include not just top-level symbols? We could filter by kind to exclude variables + # The language server methods would need to be adjusted for this. + result[file_path] = [self.SymbolOverviewElement(name_path=symbol[0], kind=int(symbol[1])) for symbol in symbols] + return result + class JetBrainsSymbol(AbstractSymbol): def __init__(self, symbol_dict: dict, project: Project) -> None: diff --git a/src/serena/tools/symbol_tools.py b/src/serena/tools/symbol_tools.py index 1910928..e513832 100644 --- a/src/serena/tools/symbol_tools.py +++ b/src/serena/tools/symbol_tools.py @@ -2,6 +2,7 @@ Language server-related tools """ +import dataclasses import json from collections.abc import Sequence from copy import copy @@ -60,14 +61,8 @@ class GetSymbolsOverviewTool(Tool): (e.g. a subdirectory). :return: a JSON object mapping relative paths of all contained files to info about top-level symbols in the file (name_path, kind). """ - path_to_symbol_infos = self.language_server.request_overview(relative_path) - result = {} - for file_path, symbols in path_to_symbol_infos.items(): - # TODO: maybe include not just top-level symbols? We could filter by kind to exclude variables - # The language server methods would need to be adjusted for this. - result[file_path] = [{"name_path": symbol[0], "kind": int(symbol[1])} for symbol in symbols] - - result_json_str = json.dumps(result) + result = self.symbol_manager.get_symbol_overview(relative_path) + result_json_str = json.dumps({k: [dataclasses.asdict(i) for i in l] for k, l in result.items()}) return self._limit_length(result_json_str, max_answer_chars)