diff --git a/generate.py b/generate.py index f22d125..6c1a296 100755 --- a/generate.py +++ b/generate.py @@ -68,6 +68,7 @@ def generate_protocol(output: str) -> None: 'from typing import TypedDict', 'from typing import Union', 'from typing_extensions import NotRequired', + 'from typing_extensions import override', 'from typing_extensions import TypeAlias\n', 'URI = str', 'DocumentUri = str', diff --git a/generated/lsp_types.py b/generated/lsp_types.py index e5d46c2..01e42e3 100644 --- a/generated/lsp_types.py +++ b/generated/lsp_types.py @@ -16,6 +16,7 @@ from typing import TypedDict from typing import Union from typing_extensions import NotRequired +from typing_extensions import override from typing_extensions import TypeAlias URI = str @@ -33,6 +34,15 @@ class SemanticTokenTypes(StrEnum): @since 3.16.0 """ + @classmethod + @override + def _missing_(cls, value: object) -> str: + str_value = str(value) + obj = str.__new__(cls, str_value) + obj._value_ = str_value + obj._name_ = str_value + return obj + Namespace = 'namespace' Type = 'type' """ @@ -74,6 +84,15 @@ class SemanticTokenModifiers(StrEnum): @since 3.16.0 """ + @classmethod + @override + def _missing_(cls, value: object) -> str: + str_value = str(value) + obj = str.__new__(cls, str_value) + obj._value_ = str_value + obj._name_ = str_value + return obj + Declaration = 'declaration' Definition = 'definition' Readonly = 'readonly' @@ -160,6 +179,15 @@ class LSPErrorCodes(IntEnum): class FoldingRangeKind(StrEnum): """A set of predefined range kinds.""" + @classmethod + @override + def _missing_(cls, value: object) -> str: + str_value = str(value) + obj = str.__new__(cls, str_value) + obj._value_ = str_value + obj._name_ = str_value + return obj + Comment = 'comment' """Folding range for a comment""" Imports = 'imports' @@ -420,6 +448,15 @@ class DocumentHighlightKind(IntEnum): class CodeActionKind(StrEnum): """A set of predefined code action kinds""" + @classmethod + @override + def _missing_(cls, value: object) -> str: + str_value = str(value) + obj = str.__new__(cls, str_value) + obj._value_ = str_value + obj._name_ = str_value + return obj + Empty = '' """Empty kind.""" QuickFix = 'quickfix' @@ -543,6 +580,15 @@ class LanguageKind(StrEnum): @since 3.18.0 """ + @classmethod + @override + def _missing_(cls, value: object) -> str: + str_value = str(value) + obj = str.__new__(cls, str_value) + obj._value_ = str_value + obj._name_ = str_value + return obj + ABAP = 'abap' WindowsBat = 'bat' BibTeX = 'bibtex' @@ -639,6 +685,15 @@ class PositionEncodingKind(StrEnum): @since 3.17.0 """ + @classmethod + @override + def _missing_(cls, value: object) -> str: + str_value = str(value) + obj = str.__new__(cls, str_value) + obj._value_ = str_value + obj._name_ = str_value + return obj + UTF8 = 'utf-8' """Character offsets count UTF-8 code units (e.g. bytes).""" UTF16 = 'utf-16' diff --git a/utils/generate_enumerations.py b/utils/generate_enumerations.py index 64a2fe6..24b47dd 100644 --- a/utils/generate_enumerations.py +++ b/utils/generate_enumerations.py @@ -13,6 +13,18 @@ from lsp_schema import EnumerationEntry +STR_ENUM_MISSING_IMPL = f""" +@classmethod +@override +def _missing_(cls, value: object) -> str: +{indentation}str_value = str(value) +{indentation}obj = str.__new__(cls, str_value) +{indentation}obj._value_ = str_value +{indentation}obj._name_ = str_value +{indentation}return obj +""".strip() + + class EnumKind(Enum): Number = 1 String = 2 @@ -49,6 +61,10 @@ def to_string(enumeration: Enumeration) -> str: result += f'class {symbol_name}({enum_class}):\n' if documentation: result += f'{documentation}\n\n' + if enum_class == 'StrEnum' and enumeration.get('supportsCustomValues'): + lines = STR_ENUM_MISSING_IMPL.splitlines() + formatted = '\n'.join([f'{indentation}{line}' for line in lines]) + result += f'{formatted}\n\n' result += f'{indentation}' + values return result