Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
55 changes: 55 additions & 0 deletions generated/lsp_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
"""
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
16 changes: 16 additions & 0 deletions utils/generate_enumerations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down