mirror of
https://github.com/tiennm99/serena.git
synced 2026-10-13 06:15:43 +00:00
Fix: Enhance SymbolKind handling for non-standard values
This commit is contained in:
1 parent
0c915bd18d
commit
c51887dc2f
3 files changed
+18
-1
No files matched your search
@@ -222,7 +222,7 @@ class LanguageServerSymbol(Symbol, ToStringMixin):
|
||||
"""
|
||||
:return: string representation of the symbol kind (name attribute of the `SymbolKind` enum item)
|
||||
"""
|
||||
return SymbolKind(self.symbol_kind).name
|
||||
return SymbolKind.from_int(self.symbol_kind).name
|
||||
|
||||
@property
|
||||
def symbol_kind(self) -> SymbolKind:
|
||||
|
||||
@@ -1276,6 +1276,10 @@ class SolidLanguageServer(ABC):
|
||||
item = cast(ls_types.UnifiedSymbolInformation, dict(original_symbol_dict))
|
||||
absolute_path = os.path.join(self.repository_root_path, relative_file_path)
|
||||
|
||||
# handle non-standard symbol kind values (e.g., 255)
|
||||
if "kind" in item and isinstance(item["kind"], int):
|
||||
item["kind"] = ls_types.SymbolKind.from_int(item["kind"])
|
||||
|
||||
# handle missing location and path entries
|
||||
if "location" not in item:
|
||||
uri = pathlib.Path(absolute_path).as_uri()
|
||||
|
||||
@@ -152,6 +152,7 @@ class SymbolKind(IntEnum):
|
||||
|
||||
# TODO: This is a duplicate of SymbolKind in lsp_types.
|
||||
|
||||
Unknown = 0
|
||||
File = 1
|
||||
Module = 2
|
||||
Namespace = 3
|
||||
@@ -179,6 +180,18 @@ class SymbolKind(IntEnum):
|
||||
Operator = 25
|
||||
TypeParameter = 26
|
||||
|
||||
@classmethod
|
||||
def from_int(cls, value: int) -> "SymbolKind":
|
||||
"""Convert an integer to a SymbolKind.
|
||||
|
||||
Returns Unknown (0) for non-standard values instead of raising ValueError.
|
||||
This handles language servers that may use custom/extended symbol kinds.
|
||||
"""
|
||||
try:
|
||||
return cls(value)
|
||||
except ValueError:
|
||||
return cls.Unknown
|
||||
|
||||
|
||||
class SymbolTag(IntEnum):
|
||||
"""Symbol tags are extra annotations that tweak the rendering of a symbol.
|
||||
|
||||
Reference in new issue
Block a user