diff --git a/src/serena/cli.py b/src/serena/cli.py index 73aeb6c9..3cc66d14 100644 --- a/src/serena/cli.py +++ b/src/serena/cli.py @@ -39,6 +39,7 @@ from serena.tools import FindReferencingSymbolsTool, FindSymbolTool, GetSymbolsO from serena.util.dataclass import get_dataclass_default from serena.util.logging import MemoryLogHandler from solidlsp.ls_config import Language +from solidlsp.ls_types import SymbolKind from solidlsp.util.subprocess_util import subprocess_kwargs log = logging.getLogger(__name__) @@ -808,9 +809,7 @@ class ProjectCommands(AutoRegisteringGroup): return # Extract suitable symbol (prefer class or function over variables) - # LSP symbol kinds: 5=class, 12=function, 6=method, 9=constructor - preferred_kinds = [5, 12, 6, 9] # class, function, method, constructor - + preferred_kinds = {SymbolKind.Class.name, SymbolKind.Function.name, SymbolKind.Method.name, SymbolKind.Constructor.name} selected_symbol = None for symbol in overview_data: if symbol.get("kind") in preferred_kinds: diff --git a/src/serena/symbol.py b/src/serena/symbol.py index a5f395fb..dc02f58c 100644 --- a/src/serena/symbol.py +++ b/src/serena/symbol.py @@ -212,14 +212,17 @@ class LanguageServerSymbol(Symbol, ToStringMixin): return [] def _tostring_additional_entries(self) -> dict[str, Any]: - return dict(name=self.name, kind=self.kind, num_children=len(self.symbol_root["children"])) + return dict(name=self.name, kind=self.symbol_kind_name, num_children=len(self.symbol_root["children"])) @property def name(self) -> str: return self.symbol_root["name"] @property - def kind(self) -> str: + def symbol_kind_name(self) -> str: + """ + :return: string representation of the symbol kind (name attribute of the `SymbolKind` enum item) + """ return SymbolKind(self.symbol_kind).name @property @@ -403,6 +406,9 @@ class LanguageServerSymbol(Symbol, ToStringMixin): body_location: NotRequired[dict[str, Any]] body: NotRequired[str | None] kind: NotRequired[str] + """ + string representation of the symbol kind (name attribute of the `SymbolKind` enum item) + """ children: NotRequired[list["LanguageServerSymbol.OutputDict"]] OutputDictKey = Literal["name", "name_path", "relative_path", "location", "body_location", "body", "kind", "children"] @@ -450,7 +456,7 @@ class LanguageServerSymbol(Symbol, ToStringMixin): result["name"] = self.name if kind: - result["kind"] = self.kind + result["kind"] = self.symbol_kind_name if location: result["location"] = self.location.to_dict(include_relative_path=relative_path)