Skip to content

Commit f898cfa

Browse files
Mazyodclaude
andcommitted
style: apply ruff formatting and add post-generation formatting
- Run ruff format on all files to ensure consistent code style - Run ruff check --fix to remove unused imports - Sort imports with ruff check --select I --fix - Update Makefile to run ruff format after code generation - This ensures generated files are always properly formatted Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 70bd902 commit f898cfa

13 files changed

Lines changed: 1704 additions & 1016 deletions

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ generate-pyright-schema:
5050
generate-types: ## Generate LSP type definitions
5151
echo "Generating LSP type definitions..."
5252
uv run python -m assets.scripts.generate
53+
echo "Formatting generated files..."
54+
uvx ruff format lsp_types/types.py lsp_types/requests.py lsp_types/methods.py
55+
uvx ruff check lsp_types/types.py lsp_types/requests.py lsp_types/methods.py --fix --silent || true
5356
echo "Done."
5457

5558
generate-latest-types: download-schemas generate-lsp-schema generate-pyright-schema generate-types ## Download latest LSP schemas and generate type definitions

assets/scripts/generate.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
from .utils.generate_requests import generate_requests
1010
from .utils.generate_structures import generate_structures
1111
from .utils.generate_type_aliases import generate_type_aliases
12-
from .utils.helpers import (get_new_literal_structures, indentation,
13-
reset_new_literal_structures)
12+
from .utils.helpers import (
13+
get_new_literal_structures,
14+
indentation,
15+
reset_new_literal_structures,
16+
)
1417

1518

1619
def generate_python_types(lsp_json: MetaModel, output: Path):

assets/scripts/utils/generate_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
from pathlib import Path
33

4-
from ..lsp_schema import MetaModel, Notification, Request
4+
from ..lsp_schema import MetaModel
55

66

77
def method_to_enum_name(method: str) -> str:

assets/scripts/utils/generate_structures.py

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,84 @@
11
from ..lsp_schema import Structure
2-
from .helpers import (FormattedProperty, StructureKind,
3-
format_class_properties, format_comment,
4-
format_dict_properties, get_formatted_properties,
5-
has_invalid_property_name, indentation)
2+
from .helpers import (
3+
FormattedProperty,
4+
StructureKind,
5+
format_class_properties,
6+
format_comment,
7+
format_dict_properties,
8+
get_formatted_properties,
9+
has_invalid_property_name,
10+
indentation,
11+
)
612

713

814
def generate_structures(structures: list[Structure]) -> list[str]:
9-
1015
def toString(structure: Structure) -> str:
1116
kind = StructureKind.Class
12-
if has_invalid_property_name(structure['properties']):
17+
if has_invalid_property_name(structure["properties"]):
1318
kind = StructureKind.Function
1419
return generate_structure(structure, structures, kind)
1520

16-
return [toString(structure) for structure in structures if not structure['name'].startswith('_')]
21+
return [
22+
toString(structure)
23+
for structure in structures
24+
if not structure["name"].startswith("_")
25+
]
1726

1827

19-
def get_additional_properties(for_structure: Structure, structures: list[Structure], structure_kind: StructureKind) -> list[FormattedProperty]:
20-
"""Returns properties from extended and mixin types. """
28+
def get_additional_properties(
29+
for_structure: Structure, structures: list[Structure], structure_kind: StructureKind
30+
) -> list[FormattedProperty]:
31+
"""Returns properties from extended and mixin types."""
2132
result: list[FormattedProperty] = []
22-
additional_structures = for_structure.get('extends') or []
23-
additional_structures.extend(for_structure.get('mixins') or [])
33+
additional_structures = for_structure.get("extends") or []
34+
additional_structures.extend(for_structure.get("mixins") or [])
2435
for additional_structure in additional_structures:
25-
if additional_structure['kind'] != 'reference':
26-
raise Exception("Cannot generate extends. Currently only supports kind: 'reference', but received:", additional_structure['kind'])
27-
structure = next(structure for structure in structures if structure["name"] == additional_structure['name'])
36+
if additional_structure["kind"] != "reference":
37+
raise Exception(
38+
"Cannot generate extends. Currently only supports kind: 'reference', but received:",
39+
additional_structure["kind"],
40+
)
41+
structure = next(
42+
structure
43+
for structure in structures
44+
if structure["name"] == additional_structure["name"]
45+
)
2846
if structure:
29-
properties = get_formatted_properties(structure['properties'], structure['name'], structure_kind)
47+
properties = get_formatted_properties(
48+
structure["properties"], structure["name"], structure_kind
49+
)
3050
result.extend(properties)
3151
return result
3252

3353

34-
def generate_structure(structure: Structure, structures: list[Structure], structure_kind: StructureKind) -> str:
54+
def generate_structure(
55+
structure: Structure, structures: list[Structure], structure_kind: StructureKind
56+
) -> str:
3557
result = ""
36-
symbol_name = structure['name']
37-
properties = get_formatted_properties(structure['properties'], structure['name'], structure_kind)
38-
additional_properties = get_additional_properties(structure, structures, structure_kind)
58+
symbol_name = structure["name"]
59+
properties = get_formatted_properties(
60+
structure["properties"], structure["name"], structure_kind
61+
)
62+
additional_properties = get_additional_properties(
63+
structure, structures, structure_kind
64+
)
3965

4066
# add extended properties
41-
taken_property_names = [property['name'] for property in properties]
67+
taken_property_names = [property["name"] for property in properties]
4268
for additional_property in additional_properties:
43-
if additional_property['name'] not in taken_property_names:
69+
if additional_property["name"] not in taken_property_names:
4470
properties.append(additional_property)
4571

4672
if structure_kind == StructureKind.Function:
47-
documentation = format_comment(structure.get('documentation'), '')
73+
documentation = format_comment(structure.get("documentation"), "")
4874
result += f"{symbol_name} = TypedDict('{symbol_name}', "
4975
result += "{\n"
5076
result += f"{indentation}{format_dict_properties(properties)}\n"
5177
result += "})"
5278
if documentation:
53-
result += f'\n{documentation}'
79+
result += f"\n{documentation}"
5480
else:
55-
documentation = format_comment(structure.get('documentation'), indentation)
81+
documentation = format_comment(structure.get("documentation"), indentation)
5682
result += f"class {symbol_name}(TypedDict):\n"
5783
if documentation:
5884
result += f"{documentation}\n"

examples/pyrefly_circular_imports.py

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
from tempfile import TemporaryDirectory
3131
from textwrap import dedent
3232

33-
import lsp_types
3433
from rich.console import Console
3534
from rich.markdown import Markdown
35+
36+
import lsp_types
3637
from lsp_types.pyrefly.backend import PyreflyBackend
3738
from lsp_types.pyright.backend import PyrightBackend
3839

3940
console = Console()
4041

42+
4143
# Simple structured logging helpers
4244
def log_step(title: str) -> None:
4345
console.print(f"\n=== {title} ===")
@@ -50,6 +52,7 @@ def log_result(label: str, value) -> None:
5052
else:
5153
console.print(f"{label}: {value}")
5254

55+
5356
PKGB_B = dedent(
5457
"""\
5558
from __future__ import annotations
@@ -108,10 +111,19 @@ def prepare_workspace(pkgb_dir: Path, pkgc_dir: Path) -> None:
108111
pkgc.joinpath("c.py").write_text(PKGC_C)
109112

110113

111-
async def run_backend(backend_name: str, backend, options_key: str, root: Path, external_pkgb: Path, external_pkgc: Path) -> None:
114+
async def run_backend(
115+
backend_name: str,
116+
backend,
117+
options_key: str,
118+
root: Path,
119+
external_pkgb: Path,
120+
external_pkgc: Path,
121+
) -> None:
112122
"""Run the circular imports test for a specific backend."""
113-
console.rule(f"[bold cyan]{backend_name.upper()} Backend[/bold cyan]", characters="=")
114-
123+
console.rule(
124+
f"[bold cyan]{backend_name.upper()} Backend[/bold cyan]", characters="="
125+
)
126+
115127
session = await lsp_types.Session.create(
116128
backend,
117129
base_path=root,
@@ -147,9 +159,11 @@ async def run_backend(backend_name: str, backend, options_key: str, root: Path,
147159

148160

149161
async def main() -> None:
150-
with TemporaryDirectory(prefix="circular-root-") as tmp_root, TemporaryDirectory(
151-
prefix="circular-pkgb-"
152-
) as tmp_pkgb, TemporaryDirectory(prefix="circular-pkgc-") as tmp_pkgc:
162+
with (
163+
TemporaryDirectory(prefix="circular-root-") as tmp_root,
164+
TemporaryDirectory(prefix="circular-pkgb-") as tmp_pkgb,
165+
TemporaryDirectory(prefix="circular-pkgc-") as tmp_pkgc,
166+
):
153167
root = Path(tmp_root)
154168
external_pkgb = Path(tmp_pkgb)
155169
external_pkgc = Path(tmp_pkgc)
@@ -160,12 +174,26 @@ async def main() -> None:
160174
console.print()
161175

162176
# Run Pyrefly backend
163-
await run_backend("pyrefly", PyreflyBackend(), "search_path", root, external_pkgb, external_pkgc)
164-
177+
await run_backend(
178+
"pyrefly",
179+
PyreflyBackend(),
180+
"search_path",
181+
root,
182+
external_pkgb,
183+
external_pkgc,
184+
)
185+
165186
console.print("\n")
166-
187+
167188
# Run Pyright backend
168-
await run_backend("pyright", PyrightBackend(), "extraPaths", root, external_pkgb, external_pkgc)
189+
await run_backend(
190+
"pyright",
191+
PyrightBackend(),
192+
"extraPaths",
193+
root,
194+
external_pkgb,
195+
external_pkgc,
196+
)
169197

170198

171199
if __name__ == "__main__":

examples/pyrefly_diagnostics_completion.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ def rich_format(widget):
236236
render_diagnostics(diagnostics)
237237

238238
user_print("[bold]Step 1.1:[/] Hover on compile_report in initial code")
239-
hover_initial = await controller.hover(
240-
"compile_report", label="Initial hover"
241-
)
239+
hover_initial = await controller.hover("compile_report", label="Initial hover")
242240
user_print(f"Hover (initial) received: {hover_initial is not None}")
243241

244242
user_print("[bold]Step 1.2:[/] Semantic tokens snapshot (initial code)")
@@ -300,9 +298,7 @@ def rich_format(widget):
300298
)
301299

302300
user_print("[bold]Step 5:[/] Second completion request (same cursor)")
303-
completions_second = await controller.completion(
304-
label="Completion request 2"
305-
)
301+
completions_second = await controller.completion(label="Completion request 2")
306302
if completions_second is None:
307303
user_print("[yellow]No completion items returned[/]")
308304
else:
@@ -312,9 +308,7 @@ def rich_format(widget):
312308
else completions_second
313309
)
314310
top_labels = [item.get("label") for item in items[:3]]
315-
user_print(
316-
f"Completion count: {len(items)}; sample labels: {top_labels}"
317-
)
311+
user_print(f"Completion count: {len(items)}; sample labels: {top_labels}")
318312

319313
user_print("[bold]Step 6:[/] Finish completion snippet and verify diagnostics")
320314
await controller.write_code(
@@ -355,19 +349,13 @@ def stress_helper_{idx}(seed: str) -> str:
355349
hover_loop = await controller.hover(
356350
f"stress_helper_{idx}", label=f"Stress hover {loop_id}"
357351
)
358-
user_print(
359-
f"Hover (stress {loop_id}) received: {hover_loop is not None}"
360-
)
352+
user_print(f"Hover (stress {loop_id}) received: {hover_loop is not None}")
361353

362354
tokens_loop = await controller.semantic_tokens(
363355
label=f"Stress semantic tokens {loop_id}"
364356
)
365-
token_count_loop = (
366-
len(tokens_loop.get("data", [])) if tokens_loop else 0
367-
)
368-
user_print(
369-
f"Semantic tokens (stress {loop_id}) count: {token_count_loop}"
370-
)
357+
token_count_loop = len(tokens_loop.get("data", [])) if tokens_loop else 0
358+
user_print(f"Semantic tokens (stress {loop_id}) count: {token_count_loop}")
371359

372360
await controller.write_code(
373361
f"\nstress_completion_{idx} = current.",
@@ -446,9 +434,9 @@ async def main() -> None:
446434

447435
# Run Pyrefly backend
448436
await run_backend("pyrefly", PyreflyBackend(), workspace)
449-
437+
450438
console.print("\n\n")
451-
439+
452440
# Run Pyright backend
453441
await run_backend("pyright", PyrightBackend(node_flags=["--prof"]), workspace)
454442

lsp_types/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import importlib.metadata
2+
13
from . import methods # noqa: F401
24
from .requests import * # noqa: F401, F403
35
from .session import * # noqa: F401, F403
46
from .types import * # noqa: F401, F403
57

6-
import importlib.metadata
7-
88
try:
99
__version__ = importlib.metadata.version("lsp-types")
1010
except Exception:

lsp_types/methods.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Generated code.
44
# DO NOT EDIT.
55
# LSP v3.17.0
6-
76
from enum import StrEnum
87

98

0 commit comments

Comments
 (0)