Skip to content
Merged
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
12 changes: 12 additions & 0 deletions generator/plugins/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@
SPECIAL_ENUMS = ["LanguageKind", "ErrorCodes", "LSPErrorCodes"]


def customizations(spec: model.LSPModel) -> model.LSPModel:
# https://github.com/microsoft/lsprotocol/issues/344
# Allow CompletionItemKind to support custom values
for enum in spec.enumerations:
if enum.name == "CompletionItemKind":
enum.supportsCustomValues = True
break

return spec


def generate_from_spec(spec: model.LSPModel, output_dir: str, test_dir: str) -> None:
spec = customizations(spec)
code = TypesCodeGenerator(spec).get_code()

output_path = pathlib.Path(output_dir, PACKAGE_NAME)
Expand Down
17 changes: 17 additions & 0 deletions packages/python/lsprotocol/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,15 @@ def _text_edit_hook(
return converter.structure(object_, lsp_types.AnnotatedTextEdit)
return converter.structure(object_, lsp_types.TextEdit)

def _completion_item_kind_hook(
object_: Any, _: type
) -> Union[lsp_types.CompletionItemKind, OptionalPrimitive]:
if object_ is None:
return None
if isinstance(object_, (bool, int, str, float)):
return object_
return converter.structure(object_, lsp_types.CompletionItemKind)

structure_hooks = [
(
Optional[
Expand Down Expand Up @@ -1098,6 +1107,14 @@ def _text_edit_hook(
],
_text_edit_hook,
),
(
Optional[Union[lsp_types.CompletionItemKind, int]],
_completion_item_kind_hook,
),
(
Union[lsp_types.CompletionItemKind, int],
_completion_item_kind_hook,
),
]
for type_, hook in structure_hooks:
converter.register_structure_hook(type_, hook)
Expand Down
6 changes: 4 additions & 2 deletions packages/python/lsprotocol/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3239,7 +3239,7 @@ class CompletionItem:
@since 3.17.0"""
# Since: 3.17.0

kind: Optional[CompletionItemKind] = attrs.field(default=None)
kind: Optional[Union[CompletionItemKind, int]] = attrs.field(default=None)
"""The kind of this completion item. Based of the kind
an icon is chosen by the editor."""

Expand Down Expand Up @@ -9125,7 +9125,9 @@ class ClientCompletionItemOptionsKind:

# Since: 3.18.0

value_set: Optional[Sequence[CompletionItemKind]] = attrs.field(default=None)
value_set: Optional[Sequence[Union[CompletionItemKind, int]]] = attrs.field(
default=None
)
"""The completion item kind values the client supports. When this
property exists the client also guarantees that it will
handle values outside its set gracefully and falls back
Expand Down