Skip to content

Commit 2139552

Browse files
committed
Fix health check incorrectly checking symbol kind against int instead of SymbolKind.name
1 parent 6337765 commit 2139552

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/serena/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from serena.util.dataclass import get_dataclass_default
4040
from serena.util.logging import MemoryLogHandler
4141
from solidlsp.ls_config import Language
42+
from solidlsp.ls_types import SymbolKind
4243
from solidlsp.util.subprocess_util import subprocess_kwargs
4344

4445
log = logging.getLogger(__name__)
@@ -808,9 +809,7 @@ def health_check(project: str) -> None:
808809
return
809810

810811
# Extract suitable symbol (prefer class or function over variables)
811-
# LSP symbol kinds: 5=class, 12=function, 6=method, 9=constructor
812-
preferred_kinds = [5, 12, 6, 9] # class, function, method, constructor
813-
812+
preferred_kinds = {SymbolKind.Class.name, SymbolKind.Function.name, SymbolKind.Method.name, SymbolKind.Constructor.name}
814813
selected_symbol = None
815814
for symbol in overview_data:
816815
if symbol.get("kind") in preferred_kinds:

src/serena/symbol.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,17 @@ def _tostring_includes(self) -> list[str]:
212212
return []
213213

214214
def _tostring_additional_entries(self) -> dict[str, Any]:
215-
return dict(name=self.name, kind=self.kind, num_children=len(self.symbol_root["children"]))
215+
return dict(name=self.name, kind=self.symbol_kind_name, num_children=len(self.symbol_root["children"]))
216216

217217
@property
218218
def name(self) -> str:
219219
return self.symbol_root["name"]
220220

221221
@property
222-
def kind(self) -> str:
222+
def symbol_kind_name(self) -> str:
223+
"""
224+
:return: string representation of the symbol kind (name attribute of the `SymbolKind` enum item)
225+
"""
223226
return SymbolKind(self.symbol_kind).name
224227

225228
@property
@@ -403,6 +406,9 @@ class OutputDict(TypedDict):
403406
body_location: NotRequired[dict[str, Any]]
404407
body: NotRequired[str | None]
405408
kind: NotRequired[str]
409+
"""
410+
string representation of the symbol kind (name attribute of the `SymbolKind` enum item)
411+
"""
406412
children: NotRequired[list["LanguageServerSymbol.OutputDict"]]
407413

408414
OutputDictKey = Literal["name", "name_path", "relative_path", "location", "body_location", "body", "kind", "children"]
@@ -450,7 +456,7 @@ def to_dict(
450456
result["name"] = self.name
451457

452458
if kind:
453-
result["kind"] = self.kind
459+
result["kind"] = self.symbol_kind_name
454460

455461
if location:
456462
result["location"] = self.location.to_dict(include_relative_path=relative_path)

0 commit comments

Comments
 (0)