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
2 changes: 2 additions & 0 deletions download_schemas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

from __future__ import annotations

from pathlib import Path
from urllib.request import urlopen

Expand Down
13 changes: 7 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env python3

from __future__ import annotations

from pathlib import Path
from typing import Literal, cast, TYPE_CHECKING
from typing import cast
from typing import Literal
from typing import TYPE_CHECKING
from utils.generate_enumerations import generate_enumerations
from utils.generate_notifications import generate_notifications
from utils.generate_requests_and_responses import generate_requests_and_responses
from utils.generate_structures import generate_structures
from utils.generate_type_aliases import generate_type_aliases
from utils.helpers import get_new_literal_structures, reset_new_literal_structures
from utils.helpers import get_new_literal_structures
from utils.helpers import reset_new_literal_structures
import json

if TYPE_CHECKING:
Expand All @@ -35,10 +39,7 @@
'ApplyKind': 'IntFlag',
}

ALIAS_OVERRIDES: dict[str, str] = {
'LSPArray': "Sequence['LSPAny']",
'LSPObject': 'Mapping[str, Any]'
}
ALIAS_OVERRIDES: dict[str, str] = {'LSPArray': "Sequence['LSPAny']", 'LSPObject': 'Mapping[str, Any]'}


def generate(output: str) -> None:
Expand Down
16 changes: 13 additions & 3 deletions generated/lsp_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
# LSP v3.17.0

from __future__ import annotations
from enum import IntEnum, IntFlag, StrEnum
from typing import Any, Dict, List, Literal, Mapping, Sequence, TypedDict, Union
from typing_extensions import NotRequired, TypeAlias

from enum import IntEnum
from enum import IntFlag
from enum import StrEnum
from typing import Any
from typing import Dict
from typing import List
from typing import Literal
from typing import Mapping
from typing import Sequence
from typing import TypedDict
from typing import Union
from typing_extensions import NotRequired
from typing_extensions import TypeAlias

URI = str
DocumentUri = str
Expand Down
20 changes: 17 additions & 3 deletions lsp_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations
from typing import Literal, TypedDict
from typing_extensions import NotRequired

from typing import Literal
from typing import NotRequired
from typing import TypedDict

_BaseTypes = Literal['URI', 'DocumentUri', 'integer', 'uinteger', 'decimal', 'RegExp', 'string', 'boolean', 'null']

Expand Down Expand Up @@ -221,4 +223,16 @@ class MetaModel(TypedDict):
typeAliases: list[TypeAlias]


EveryType = BaseType | ReferenceType | ArrayType | MapType | AndType | OrType | TupleType | StructureLiteralType | StringLiteralType | IntegerLiteralType | BooleanLiteralType # noqa: E501
EveryType = (
BaseType
| ReferenceType
| ArrayType
| MapType
| AndType
| OrType
| TupleType
| StructureLiteralType
| StringLiteralType
| IntegerLiteralType
| BooleanLiteralType
)
51 changes: 33 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "lsp-types"
version = "1.0.0"
license = "MIT"
requires-python = ">=3.8"
requires-python = ">=3.13"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
Expand All @@ -12,7 +12,7 @@ dependencies = [
]

[tool.pyright]
pythonVersion = "3.11"
pythonVersion = "3.13"
reportUnusedCallResult = "none"

[[tool.pyright.executionEnvironments]]
Expand All @@ -21,12 +21,32 @@ pythonVersion = "3.8"

[tool.ruff]
line-length = 120
target-version = "py313"

[tool.ruff.per-file-target-version]
"generated/*.py" = "py38"

[tool.ruff.format]
quote-style = "single"
exclude = [
"generated/*.py"
]

[tool.ruff.lint.isort]
case-sensitive = false
force-single-line = true
from-first = true
no-sections = true
order-by-type = false
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.ruff.lint]
extend-select = ["ALL"]
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
ignore = [
"COM812", # https://docs.astral.sh/ruff/rules/missing-trailing-comma/
"C901", # https://docs.astral.sh/ruff/rules/complex-structure/
Expand All @@ -41,7 +61,6 @@ ignore = [
"D213", # https://docs.astral.sh/ruff/rules/multi-line-summary-second-line/
"D400", # https://docs.astral.sh/ruff/rules/missing-trailing-period/
"D415", # https://docs.astral.sh/ruff/rules/missing-terminal-punctuation/
"I001", # https://docs.astral.sh/ruff/rules/unsorted-imports/
"N801", # https://docs.astral.sh/ruff/rules/invalid-class-name/
"PLR0911", # https://docs.astral.sh/ruff/rules/too-many-return-statements/
"PLR0912", # https://docs.astral.sh/ruff/rules/too-many-branches/
Expand All @@ -51,20 +70,16 @@ ignore = [
"UP037" # https://docs.astral.sh/ruff/rules/quoted-annotation/
]

[tool.ruff.lint.flake8-quotes]
inline-quotes = "single"

[tool.tox]
legacy_tox_ini = """
[tox]
envlist = py3
skipsdist = True
env_list = ["py3"]
skipsdist = true

[testenv]
deps =
pyright==1.1.407
ruff==0.14.14
commands =
pyright .
ruff check .
"""
[tool.tox.env_run_base]
deps = [
"pyright==1.1.408",
"ruff==0.15.0",
]
commands = [
["pyright"],
["ruff", "check"],
]
11 changes: 8 additions & 3 deletions utils/generate_enumerations.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import annotations

from enum import Enum
from typing import Literal, TYPE_CHECKING
from utils.helpers import capitalize, format_comment, indentation
from typing import Literal
from typing import TYPE_CHECKING
from utils.helpers import capitalize
from utils.helpers import format_comment
from utils.helpers import indentation
import keyword

if TYPE_CHECKING:
from lsp_schema import Enumeration, EnumerationEntry
from lsp_schema import Enumeration
from lsp_schema import EnumerationEntry


class EnumKind(Enum):
Expand Down
5 changes: 4 additions & 1 deletion utils/generate_notifications.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from utils.helpers import StructureKind, format_type, indentation
from utils.helpers import format_type
from utils.helpers import indentation
from utils.helpers import StructureKind

if TYPE_CHECKING:
from lsp_schema import Notification
Expand Down
5 changes: 4 additions & 1 deletion utils/generate_requests_and_responses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from utils.helpers import StructureKind, format_type, indentation
from utils.helpers import format_type
from utils.helpers import indentation
from utils.helpers import StructureKind

if TYPE_CHECKING:
from lsp_schema import Request
Expand Down
19 changes: 9 additions & 10 deletions utils/generate_structures.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from utils.helpers import (
FormattedProperty,
format_comment,
indentation,
format_class_properties,
format_dict_properties,
get_formatted_properties,
has_invalid_property_name,
StructureKind,
)
from utils.helpers import format_class_properties
from utils.helpers import format_comment
from utils.helpers import format_dict_properties
from utils.helpers import FormattedProperty
from utils.helpers import get_formatted_properties
from utils.helpers import has_invalid_property_name
from utils.helpers import indentation
from utils.helpers import StructureKind

if TYPE_CHECKING:
from lsp_schema import Structure
Expand Down
5 changes: 4 additions & 1 deletion utils/generate_type_aliases.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations
from utils.helpers import format_comment, format_type, StructureKind

from typing import TYPE_CHECKING
from utils.helpers import format_comment
from utils.helpers import format_type
from utils.helpers import StructureKind

if TYPE_CHECKING:
from lsp_schema import TypeAlias
Expand Down
13 changes: 10 additions & 3 deletions utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from __future__ import annotations

from enum import Enum
from typing import Any, ClassVar, TypedDict, TYPE_CHECKING
from typing import Any
from typing import ClassVar
from typing import TYPE_CHECKING
from typing import TypedDict
import keyword

if TYPE_CHECKING:
from lsp_schema import EveryType, BaseType, MapKeyType, Property
from lsp_schema import BaseType
from lsp_schema import EveryType
from lsp_schema import MapKeyType
from lsp_schema import Property


indentation = ' '
Expand Down Expand Up @@ -127,7 +134,7 @@ def format_base_types(base_type: BaseType | MapKeyType) -> str:
'decimal': 'float',
'string': 'str',
'boolean': 'bool',
'null': 'None'
'null': 'None',
}
name = base_type['name']

Expand Down