Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing hook for Semantic Token capabilities. #98

Merged
merged 3 commits into from
Oct 18, 2022
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
18 changes: 9 additions & 9 deletions generator/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ importlib-metadata==5.0.0 \
--hash=sha256:da31db32b304314d044d3c12c79bd59e307889b287ad12ff387b3500835fc2ab \
--hash=sha256:ddb0e35065e8938f867ed4928d0ae5bf2a53b7773871bfe6bcc7e4fcdc7dea43
# via jsonschema
importlib-resources==5.9.0 \
--hash=sha256:5481e97fb45af8dcf2f798952625591c58fe599d0735d86b10f54de086a61681 \
--hash=sha256:f78a8df21a79bcc30cfd400bdc38f314333de7c0fb619763f6b9dabab8268bb7
importlib-resources==5.10.0 \
--hash=sha256:c01b1b94210d9849f286b86bb51bcea7cd56dde0600d8db721d7b81330711668 \
--hash=sha256:ee17ec648f85480d523596ce49eae8ead87d5631ae1551f913c0100b5edd3437
# via
# -r ./generator/requirements.in
# jsonschema
Expand Down Expand Up @@ -49,15 +49,15 @@ pyrsistent==0.18.1 \
--hash=sha256:f87cc2863ef33c709e237d4b5f4502a62a00fab450c9e020892e8e2ede5847f5 \
--hash=sha256:fd8da6d0124efa2f67d86fa70c851022f87c98e205f0594e1fae044e7119a5a6
# via jsonschema
typing-extensions==4.3.0 \
--hash=sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02 \
--hash=sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6
typing-extensions==4.4.0 \
--hash=sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa \
--hash=sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e
# via
# importlib-metadata
# jsonschema
zipp==3.8.1 \
--hash=sha256:05b45f1ee8f807d0cc928485ca40a07cb491cf092ff587c0df9cb1fd154848d2 \
--hash=sha256:47c40d7fe183a6f21403a199b3e4192cca5774656965b0a4988ad2f8feb5f009
zipp==3.9.0 \
--hash=sha256:3a7af91c3db40ec72dd9d154ae18e008c69efe8ca88dde4f9a731bb82fe2f9eb \
--hash=sha256:972cfa31bc2fedd3fa838a51e9bc7e64b7fb725a8c00e7431554311f180e9980
# via
# importlib-metadata
# importlib-resources
18 changes: 18 additions & 0 deletions lsprotocol/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@ def _semantic_tokens_hook(object_: Any, _: type):
return object_
return converter.structure(object_, lsp_types.SemanticTokensOptionsFullType1)

def _semantic_tokens_capabilities_hook(object_: Any, _: type):
if object_ is None:
return None
if isinstance(object_, (bool, int, str, float)):
return object_
return converter.structure(
object_, lsp_types.SemanticTokensClientCapabilitiesRequestsTypeFullType1
)

structure_hooks = [
(
Optional[
Expand Down Expand Up @@ -587,6 +596,15 @@ def _semantic_tokens_hook(object_: Any, _: type):
Optional[Union[bool, lsp_types.SemanticTokensOptionsFullType1]],
_semantic_tokens_hook,
),
(
Optional[
Union[
bool,
lsp_types.SemanticTokensClientCapabilitiesRequestsTypeFullType1,
]
],
_semantic_tokens_capabilities_hook,
),
]
for type_, hook in structure_hooks:
converter.register_structure_hook(type_, hook)
Expand Down
12 changes: 6 additions & 6 deletions lsprotocol/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

from typing import Any

import attrs

INTEGER_MIN_VALUE = -(2**31)
INTEGER_MAX_VALUE = 2**31 - 1


def integer_validator(instance: Any, attribute: attrs.Attribute, value: Any) -> bool:
def integer_validator(instance: Any, attribute: Any, value: Any) -> bool:
"""Validates that integer value belongs in the range expected by LSP."""
if not isinstance(value, int) or not (
INTEGER_MIN_VALUE <= value <= INTEGER_MAX_VALUE
):
name = attribute.name if hasattr(attribute, "name") else str(attribute)
raise ValueError(
f"{instance.__class__.__qualname__}.{attribute.name} should be in range [{INTEGER_MIN_VALUE}:{INTEGER_MAX_VALUE}], but was {value}."
f"{instance.__class__.__qualname__}.{name} should be in range [{INTEGER_MIN_VALUE}:{INTEGER_MAX_VALUE}], but was {value}."
)
return True

Expand All @@ -25,13 +24,14 @@ def integer_validator(instance: Any, attribute: attrs.Attribute, value: Any) ->
UINTEGER_MAX_VALUE = 2**31 - 1


def uinteger_validator(instance: Any, attribute: attrs.Attribute, value: Any) -> bool:
def uinteger_validator(instance: Any, attribute: Any, value: Any) -> bool:
"""Validates that unsigned integer value belongs in the range expected by
LSP."""
if not isinstance(value, int) or not (
UINTEGER_MIN_VALUE <= value <= UINTEGER_MAX_VALUE
):
name = attribute.name if hasattr(attribute, "name") else str(attribute)
raise ValueError(
f"{instance.__class__.__qualname__}.{attribute.name} should be in range [{UINTEGER_MIN_VALUE}:{UINTEGER_MAX_VALUE}], but was {value}."
f"{instance.__class__.__qualname__}.{name} should be in range [{UINTEGER_MIN_VALUE}:{UINTEGER_MAX_VALUE}], but was {value}."
)
return True
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exceptiongroup==1.0.0rc9 \
--hash=sha256:2e3c3fc1538a094aab74fad52d6c33fc94de3dfee3ee01f187c0e0c72aec5337 \
--hash=sha256:9086a4a21ef9b31c72181c77c040a074ba0889ee56a7b289ff0afb0d97655f96
# via cattrs
typing-extensions==4.3.0 \
--hash=sha256:25642c956049920a5aa49edcdd6ab1e06d7e5d467fc00e0506c44ac86fbfca02 \
--hash=sha256:e6d2677a32f47fc7eb2795db1dd15c1f34eff616bcaf2cfb5e997f854fa1c4a6
typing-extensions==4.4.0 \
--hash=sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa \
--hash=sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e
# via cattrs
Loading