Skip to content

Commit 2d96611

Browse files
authored
refactor: align formatting with LSP (#32)
1 parent 652036a commit 2d96611

11 files changed

Lines changed: 111 additions & 49 deletions

download_schemas.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env python3
22

3+
from __future__ import annotations
4+
35
from pathlib import Path
46
from urllib.request import urlopen
57

generate.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#!/usr/bin/env python3
22

33
from __future__ import annotations
4+
45
from pathlib import Path
5-
from typing import Literal, cast, TYPE_CHECKING
6+
from typing import cast
7+
from typing import Literal
8+
from typing import TYPE_CHECKING
69
from utils.generate_enumerations import generate_enumerations
710
from utils.generate_notifications import generate_notifications
811
from utils.generate_requests_and_responses import generate_requests_and_responses
912
from utils.generate_structures import generate_structures
1013
from utils.generate_type_aliases import generate_type_aliases
11-
from utils.helpers import get_new_literal_structures, reset_new_literal_structures
14+
from utils.helpers import get_new_literal_structures
15+
from utils.helpers import reset_new_literal_structures
1216
import json
1317

1418
if TYPE_CHECKING:
@@ -35,10 +39,7 @@
3539
'ApplyKind': 'IntFlag',
3640
}
3741

38-
ALIAS_OVERRIDES: dict[str, str] = {
39-
'LSPArray': "Sequence['LSPAny']",
40-
'LSPObject': 'Mapping[str, Any]'
41-
}
42+
ALIAS_OVERRIDES: dict[str, str] = {'LSPArray': "Sequence['LSPAny']", 'LSPObject': 'Mapping[str, Any]'}
4243

4344

4445
def generate(output: str) -> None:

generated/lsp_types.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33
# LSP v3.17.0
44

55
from __future__ import annotations
6-
from enum import IntEnum, IntFlag, StrEnum
7-
from typing import Any, Dict, List, Literal, Mapping, Sequence, TypedDict, Union
8-
from typing_extensions import NotRequired, TypeAlias
96

7+
from enum import IntEnum
8+
from enum import IntFlag
9+
from enum import StrEnum
10+
from typing import Any
11+
from typing import Dict
12+
from typing import List
13+
from typing import Literal
14+
from typing import Mapping
15+
from typing import Sequence
16+
from typing import TypedDict
17+
from typing import Union
18+
from typing_extensions import NotRequired
19+
from typing_extensions import TypeAlias
1020

1121
URI = str
1222
DocumentUri = str

lsp_schema.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
2-
from typing import Literal, TypedDict
3-
from typing_extensions import NotRequired
2+
3+
from typing import Literal
4+
from typing import NotRequired
5+
from typing import TypedDict
46

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

@@ -221,4 +223,16 @@ class MetaModel(TypedDict):
221223
typeAliases: list[TypeAlias]
222224

223225

224-
EveryType = BaseType | ReferenceType | ArrayType | MapType | AndType | OrType | TupleType | StructureLiteralType | StringLiteralType | IntegerLiteralType | BooleanLiteralType # noqa: E501
226+
EveryType = (
227+
BaseType
228+
| ReferenceType
229+
| ArrayType
230+
| MapType
231+
| AndType
232+
| OrType
233+
| TupleType
234+
| StructureLiteralType
235+
| StringLiteralType
236+
| IntegerLiteralType
237+
| BooleanLiteralType
238+
)

pyproject.toml

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "lsp-types"
33
version = "1.0.0"
44
license = "MIT"
5-
requires-python = ">=3.8"
5+
requires-python = ">=3.13"
66
classifiers = [
77
"Programming Language :: Python :: 3",
88
"Operating System :: OS Independent",
@@ -12,7 +12,7 @@ dependencies = [
1212
]
1313

1414
[tool.pyright]
15-
pythonVersion = "3.11"
15+
pythonVersion = "3.13"
1616
reportUnusedCallResult = "none"
1717

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

2222
[tool.ruff]
2323
line-length = 120
24+
target-version = "py313"
25+
26+
[tool.ruff.per-file-target-version]
27+
"generated/*.py" = "py38"
2428

2529
[tool.ruff.format]
2630
quote-style = "single"
31+
exclude = [
32+
"generated/*.py"
33+
]
34+
35+
[tool.ruff.lint.isort]
36+
case-sensitive = false
37+
force-single-line = true
38+
from-first = true
39+
no-sections = true
40+
order-by-type = false
41+
required-imports = ["from __future__ import annotations"]
42+
43+
[tool.ruff.lint.flake8-quotes]
44+
inline-quotes = "single"
2745

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

54-
[tool.ruff.lint.flake8-quotes]
55-
inline-quotes = "single"
56-
5773
[tool.tox]
58-
legacy_tox_ini = """
59-
[tox]
60-
envlist = py3
61-
skipsdist = True
74+
env_list = ["py3"]
75+
skipsdist = true
6276

63-
[testenv]
64-
deps =
65-
pyright==1.1.407
66-
ruff==0.14.14
67-
commands =
68-
pyright .
69-
ruff check .
70-
"""
77+
[tool.tox.env_run_base]
78+
deps = [
79+
"pyright==1.1.408",
80+
"ruff==0.15.0",
81+
]
82+
commands = [
83+
["pyright"],
84+
["ruff", "check"],
85+
]

utils/generate_enumerations.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
from __future__ import annotations
2+
23
from enum import Enum
3-
from typing import Literal, TYPE_CHECKING
4-
from utils.helpers import capitalize, format_comment, indentation
4+
from typing import Literal
5+
from typing import TYPE_CHECKING
6+
from utils.helpers import capitalize
7+
from utils.helpers import format_comment
8+
from utils.helpers import indentation
59
import keyword
610

711
if TYPE_CHECKING:
8-
from lsp_schema import Enumeration, EnumerationEntry
12+
from lsp_schema import Enumeration
13+
from lsp_schema import EnumerationEntry
914

1015

1116
class EnumKind(Enum):

utils/generate_notifications.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
2+
23
from typing import TYPE_CHECKING
3-
from utils.helpers import StructureKind, format_type, indentation
4+
from utils.helpers import format_type
5+
from utils.helpers import indentation
6+
from utils.helpers import StructureKind
47

58
if TYPE_CHECKING:
69
from lsp_schema import Notification

utils/generate_requests_and_responses.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
2+
23
from typing import TYPE_CHECKING
3-
from utils.helpers import StructureKind, format_type, indentation
4+
from utils.helpers import format_type
5+
from utils.helpers import indentation
6+
from utils.helpers import StructureKind
47

58
if TYPE_CHECKING:
69
from lsp_schema import Request

utils/generate_structures.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from __future__ import annotations
2+
23
from typing import TYPE_CHECKING
3-
from utils.helpers import (
4-
FormattedProperty,
5-
format_comment,
6-
indentation,
7-
format_class_properties,
8-
format_dict_properties,
9-
get_formatted_properties,
10-
has_invalid_property_name,
11-
StructureKind,
12-
)
4+
from utils.helpers import format_class_properties
5+
from utils.helpers import format_comment
6+
from utils.helpers import format_dict_properties
7+
from utils.helpers import FormattedProperty
8+
from utils.helpers import get_formatted_properties
9+
from utils.helpers import has_invalid_property_name
10+
from utils.helpers import indentation
11+
from utils.helpers import StructureKind
1312

1413
if TYPE_CHECKING:
1514
from lsp_schema import Structure

utils/generate_type_aliases.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
2-
from utils.helpers import format_comment, format_type, StructureKind
2+
33
from typing import TYPE_CHECKING
4+
from utils.helpers import format_comment
5+
from utils.helpers import format_type
6+
from utils.helpers import StructureKind
47

58
if TYPE_CHECKING:
69
from lsp_schema import TypeAlias

0 commit comments

Comments
 (0)