From c51887dc2f33c7d4f8048052a409d049ec02358b Mon Sep 17 00:00:00 2001 From: habaneraa Date: Thu, 19 Mar 2026 18:19:49 +0800 Subject: [PATCH 1/5] Fix: Enhance SymbolKind handling for non-standard values --- src/serena/symbol.py | 2 +- src/solidlsp/ls.py | 4 ++++ src/solidlsp/ls_types.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/serena/symbol.py b/src/serena/symbol.py index f8ba9dd2..5e80e93d 100644 --- a/src/serena/symbol.py +++ b/src/serena/symbol.py @@ -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: diff --git a/src/solidlsp/ls.py b/src/solidlsp/ls.py index 881f070d..432f11eb 100644 --- a/src/solidlsp/ls.py +++ b/src/solidlsp/ls.py @@ -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() diff --git a/src/solidlsp/ls_types.py b/src/solidlsp/ls_types.py index 0eafcfea..7be552ff 100644 --- a/src/solidlsp/ls_types.py +++ b/src/solidlsp/ls_types.py @@ -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. From 4f0863dec5da612ea7f277f7cf94f674a4cdefa9 Mon Sep 17 00:00:00 2001 From: habaneraa Date: Thu, 19 Mar 2026 19:02:52 +0800 Subject: [PATCH 2/5] fix: Update SymbolKind handling to use Enum _missing_ method --- src/serena/symbol.py | 2 +- src/solidlsp/ls.py | 4 ---- src/solidlsp/ls_types.py | 12 ++---------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/serena/symbol.py b/src/serena/symbol.py index 5e80e93d..f8ba9dd2 100644 --- a/src/serena/symbol.py +++ b/src/serena/symbol.py @@ -222,7 +222,7 @@ class LanguageServerSymbol(Symbol, ToStringMixin): """ :return: string representation of the symbol kind (name attribute of the `SymbolKind` enum item) """ - return SymbolKind.from_int(self.symbol_kind).name + return SymbolKind(self.symbol_kind).name @property def symbol_kind(self) -> SymbolKind: diff --git a/src/solidlsp/ls.py b/src/solidlsp/ls.py index 432f11eb..881f070d 100644 --- a/src/solidlsp/ls.py +++ b/src/solidlsp/ls.py @@ -1276,10 +1276,6 @@ 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() diff --git a/src/solidlsp/ls_types.py b/src/solidlsp/ls_types.py index 7be552ff..18aaf25d 100644 --- a/src/solidlsp/ls_types.py +++ b/src/solidlsp/ls_types.py @@ -181,16 +181,8 @@ class SymbolKind(IntEnum): 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 + def _missing_(cls, value: int) -> "SymbolKind": + return cls.Unknown class SymbolTag(IntEnum): From 01bbf7254e4bf6adbedcdff9ce8c720f27f9d819 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Mon, 23 Mar 2026 11:07:53 +0100 Subject: [PATCH 3/5] Removed duplicated SymbolKind definition Adjusted comment in autogenerated code, which from now on will be maintained manually --- src/solidlsp/ls_types.py | 45 +++---------------- .../lsp_protocol_handler/lsp_types.py | 39 ++++------------ 2 files changed, 15 insertions(+), 69 deletions(-) diff --git a/src/solidlsp/ls_types.py b/src/solidlsp/ls_types.py index 18aaf25d..78446bc5 100644 --- a/src/solidlsp/ls_types.py +++ b/src/solidlsp/ls_types.py @@ -7,13 +7,18 @@ from __future__ import annotations from enum import Enum, IntEnum from typing import TYPE_CHECKING, NotRequired, Union +from sensai.util.helper import mark_used from typing_extensions import TypedDict -from solidlsp.lsp_protocol_handler.lsp_types import DiagnosticSeverity +from solidlsp.lsp_protocol_handler.lsp_types import DiagnosticSeverity, SymbolKind if TYPE_CHECKING: from .ls import SymbolBody +# a lot of code relied on a previously duplicated SymbolKind definition here. +# This line is kept to avoid breaking downstream imports +mark_used(SymbolKind) + URI = str DocumentUri = str @@ -147,44 +152,6 @@ class CompletionItem(TypedDict): about this item, like type or symbol information. """ -class SymbolKind(IntEnum): - """A symbol kind.""" - - # TODO: This is a duplicate of SymbolKind in lsp_types. - - Unknown = 0 - File = 1 - Module = 2 - Namespace = 3 - Package = 4 - Class = 5 - Method = 6 - Property = 7 - Field = 8 - Constructor = 9 - Enum = 10 - Interface = 11 - Function = 12 - Variable = 13 - Constant = 14 - String = 15 - Number = 16 - Boolean = 17 - Array = 18 - Object = 19 - Key = 20 - Null = 21 - EnumMember = 22 - Struct = 23 - Event = 24 - Operator = 25 - TypeParameter = 26 - - @classmethod - def _missing_(cls, value: int) -> "SymbolKind": - return cls.Unknown - - class SymbolTag(IntEnum): """Symbol tags are extra annotations that tweak the rendering of a symbol. diff --git a/src/solidlsp/lsp_protocol_handler/lsp_types.py b/src/solidlsp/lsp_protocol_handler/lsp_types.py index 4c1753b5..e6d6b87f 100644 --- a/src/solidlsp/lsp_protocol_handler/lsp_types.py +++ b/src/solidlsp/lsp_protocol_handler/lsp_types.py @@ -1,32 +1,12 @@ -# Code generated. DO NOT EDIT. +# The code in this module is mostly autogenerated using https://github.com/predragnikolic/OLSP +# To update it for higher LSP versions, autogenerate a new version in a different file and merge manually. + # LSP v3.17.0 -# TODO: Look into use of https://pypi.org/project/ts2python/ to generate the types for https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/ +# Note by author of the autogenerator: Look into use of https://pypi.org/project/ts2python/ to generate the types f +# or https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/ """ This file provides the Python types corresponding to the Typescript types defined in the language server protocol. -This file is obtained from https://github.com/predragnikolic/OLSP under the MIT License with the following terms: - -MIT License - -Copyright (c) 2023 Предраг Николић - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. """ from enum import Enum, IntEnum, IntFlag @@ -166,6 +146,8 @@ class FoldingRangeKind(Enum): class SymbolKind(IntEnum): """A symbol kind.""" + Unknown = 0 + """Not an LSP type, we use it to represent symbols that don't have a known kind.""" File = 1 Module = 2 Namespace = 3 @@ -197,11 +179,8 @@ class SymbolKind(IntEnum): TypeParameter = 26 @classmethod - def from_int(cls, value: int) -> "SymbolKind": - for symbol_kind in cls: - if symbol_kind.value == value: - return symbol_kind - raise ValueError(f"Invalid symbol kind: {value}") + def _missing_(cls, value: int) -> "SymbolKind": + return cls.Unknown class SymbolTag(IntEnum): From efb895e2b3e1218cffdabab8ae764ab043d67ed2 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Mon, 23 Mar 2026 11:09:16 +0100 Subject: [PATCH 4/5] Minor typing issue --- src/solidlsp/lsp_protocol_handler/lsp_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/solidlsp/lsp_protocol_handler/lsp_types.py b/src/solidlsp/lsp_protocol_handler/lsp_types.py index e6d6b87f..89434f1e 100644 --- a/src/solidlsp/lsp_protocol_handler/lsp_types.py +++ b/src/solidlsp/lsp_protocol_handler/lsp_types.py @@ -10,7 +10,7 @@ This file provides the Python types corresponding to the Typescript types define """ from enum import Enum, IntEnum, IntFlag -from typing import Literal, NotRequired, Union +from typing import Literal, NotRequired, Union, Any from typing_extensions import TypedDict @@ -179,7 +179,7 @@ class SymbolKind(IntEnum): TypeParameter = 26 @classmethod - def _missing_(cls, value: int) -> "SymbolKind": + def _missing_(cls, value: Any) -> "SymbolKind": return cls.Unknown From 9509320083223a5550d9922b3c1dd98135531a97 Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Mon, 23 Mar 2026 14:36:34 +0100 Subject: [PATCH 5/5] Format --- src/solidlsp/lsp_protocol_handler/lsp_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/solidlsp/lsp_protocol_handler/lsp_types.py b/src/solidlsp/lsp_protocol_handler/lsp_types.py index 89434f1e..ffb6135e 100644 --- a/src/solidlsp/lsp_protocol_handler/lsp_types.py +++ b/src/solidlsp/lsp_protocol_handler/lsp_types.py @@ -10,7 +10,7 @@ This file provides the Python types corresponding to the Typescript types define """ from enum import Enum, IntEnum, IntFlag -from typing import Literal, NotRequired, Union, Any +from typing import Any, Literal, NotRequired, Union from typing_extensions import TypedDict