Skip to content

Commit 06c2d14

Browse files
committed
formatting
1 parent 39c6332 commit 06c2d14

File tree

7 files changed

+72
-76
lines changed

7 files changed

+72
-76
lines changed

lsp_types/process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import json
55
import logging
66
import os
7-
from pathlib import Path
87
import typing as t
8+
from pathlib import Path
99

1010
from . import requests, types
1111

lsp_types/pyrefly/backend.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def write_config(self, base_path: Path, options: PyreflyConfig) -> None:
3131

3232
config_path.write_text(toml_content)
3333

34-
def create_process_launch_info(self, base_path: Path, options: PyreflyConfig) -> ProcessLaunchInfo:
34+
def create_process_launch_info(
35+
self, base_path: Path, options: PyreflyConfig
36+
) -> ProcessLaunchInfo:
3537
"""Create process launch info for Pyrefly LSP server"""
3638
# Build command args for Pyrefly LSP server
3739
cmd_args = ["pyrefly", "lsp"]

lsp_types/pyrefly/config_schema.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
class Model(TypedDict):
1414
"""
1515
Pyrefly Configuration Schema
16-
16+
1717
Based on available CLI options and environment variables.
1818
Note: Pyrefly's configuration format is still evolving.
1919
"""
20-
20+
2121
# Core options
2222
verbose: NotRequired[bool]
2323
threads: NotRequired[int] # 0 = auto, 1 = sequential, higher = parallel
2424
color: NotRequired[Literal["auto", "always", "never"]]
25-
25+
2626
# LSP server options
2727
indexing_mode: NotRequired[IndexingMode] # Indexing strategy for LSP server
28-
28+
2929
# File inclusion/exclusion (basic patterns)
3030
include: NotRequired[list[str]]
3131
exclude: NotRequired[list[str]]
32-
32+
3333
# Environment variables that can be configured
3434
pyrefly_threads: NotRequired[int]
35-
pyrefly_color: NotRequired[str]
36-
pyrefly_verbose: NotRequired[bool]
35+
pyrefly_color: NotRequired[str]
36+
pyrefly_verbose: NotRequired[bool]

lsp_types/pyright/backend.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def write_config(self, base_path: Path, options: PyrightConfig) -> None:
1919
config_path = base_path / "pyrightconfig.json"
2020
config_path.write_text(json.dumps(options, indent=2))
2121

22-
def create_process_launch_info(self, base_path: Path, options: PyrightConfig) -> ProcessLaunchInfo:
22+
def create_process_launch_info(
23+
self, base_path: Path, options: PyrightConfig
24+
) -> ProcessLaunchInfo:
2325
"""Create process launch info for Pyright LSP server"""
2426
# NOTE: requires node and basedpyright to be installed and accessible
2527
return ProcessLaunchInfo(cmd=["pyright-langserver", "--stdio"], cwd=base_path)

lsp_types/session.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@ def write_config(self, base_path: Path, options: t.Mapping) -> None:
1616
"""Write backend-specific configuration file"""
1717
...
1818

19-
def create_process_launch_info(self, base_path: Path, options: t.Mapping) -> ProcessLaunchInfo:
19+
def create_process_launch_info(
20+
self, base_path: Path, options: t.Mapping
21+
) -> ProcessLaunchInfo:
2022
"""Create process launch info for the LSP server"""
2123
...
2224

2325
def get_lsp_capabilities(self) -> types.ClientCapabilities:
2426
"""Get LSP client capabilities"""
2527
...
2628

27-
def get_workspace_settings(self, options: t.Mapping) -> types.DidChangeConfigurationParams:
29+
def get_workspace_settings(
30+
self, options: t.Mapping
31+
) -> types.DidChangeConfigurationParams:
2832
"""Get workspace settings for didChangeConfiguration"""
2933
...
3034

@@ -162,9 +166,7 @@ async def get_diagnostics(self) -> list[types.Diagnostic]:
162166
# For 'unchanged' nothing is appended ⇒ return cached view if desired
163167
return diagnostics
164168

165-
async def get_hover_info(
166-
self, position: types.Position
167-
) -> types.Hover | None:
169+
async def get_hover_info(self, position: types.Position) -> types.Hover | None:
168170
"""Get hover information at the given position"""
169171
return await self._process.send.hover(
170172
{"textDocument": {"uri": self._document_uri}, "position": position}

tests/test_pool.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
import lsp_types
1313
from lsp_types.pool import LSPProcessPool
14-
from lsp_types.pyright.backend import PyrightBackend
1514
from lsp_types.pyrefly.backend import PyreflyBackend
15+
from lsp_types.pyright.backend import PyrightBackend
1616

1717

1818
@pytest.fixture(params=[PyrightBackend, PyreflyBackend])
@@ -63,7 +63,9 @@ async def test_session_pool_acquire_and_recycle(self, session_pool, lsp_backend)
6363
assert session_pool.available_count == 1
6464
assert session_pool.current_size == 1
6565

66-
async def test_session_recycling_with_different_code(self, session_pool, lsp_backend):
66+
async def test_session_recycling_with_different_code(
67+
self, session_pool, lsp_backend
68+
):
6769
"""Test that recycled sessions work correctly with different code"""
6870
# First session with initial code
6971
session1 = await lsp_types.Session.create(
@@ -96,17 +98,21 @@ async def test_session_recycling_with_different_code(self, session_pool, lsp_bac
9698

9799
await session2.shutdown()
98100

99-
async def test_session_recycling_with_different_options(self, session_pool, lsp_backend, backend_name):
101+
async def test_session_recycling_with_different_options(
102+
self, session_pool, lsp_backend, backend_name
103+
):
100104
"""Test recycling sessions with different options"""
101105

102106
if backend_name == "pyright":
103107
from lsp_types.pyright.config_schema import Model as ConfigType
108+
104109
options1: ConfigType = {"strict": ["reportUndefinedVariable"]}
105110
options2: ConfigType = {"strict": ["reportGeneralTypeIssues"]}
106111
code1 = "undefined_var = 1"
107112
code2 = "x: int = 'string'" # Type error
108113
else: # pyrefly
109114
from lsp_types.pyrefly.config_schema import Model as ConfigType
115+
110116
options1: ConfigType = {"verbose": True, "threads": 1}
111117
options2: ConfigType = {"verbose": False, "threads": 2}
112118
code1 = "test_var = 1"
@@ -447,7 +453,9 @@ async def test_idle_cleanup_timing_precision(self, lsp_backend):
447453
class TestLSPProcessPoolBenchmarks:
448454
"""Benchmark tests comparing pooled vs non-pooled session performance"""
449455

450-
async def test_benchmark_session_creation_comparison(self, lsp_backend, backend_name):
456+
async def test_benchmark_session_creation_comparison(
457+
self, lsp_backend, backend_name
458+
):
451459
"""Compare session creation times with and without pooling"""
452460
pool = LSPProcessPool(max_size=3)
453461

@@ -551,7 +559,9 @@ async def test_benchmark_session_reuse_performance(self, lsp_backend, backend_na
551559
finally:
552560
await pool.cleanup()
553561

554-
async def test_benchmark_concurrent_session_creation(self, lsp_backend, backend_name):
562+
async def test_benchmark_concurrent_session_creation(
563+
self, lsp_backend, backend_name
564+
):
555565
"""Compare concurrent session creation with and without pooling"""
556566
pool = LSPProcessPool(max_size=5)
557567

@@ -580,7 +590,8 @@ async def create_pooled_session(session_id: int):
580590

581591
async def create_fresh_session(session_id: int):
582592
session = await lsp_types.Session.create(
583-
lsp_backend, initial_code=f"fresh_concurrent_{session_id} = {session_id}"
593+
lsp_backend,
594+
initial_code=f"fresh_concurrent_{session_id} = {session_id}",
584595
)
585596
hover_info = await session.get_hover_info(
586597
lsp_types.Position(line=0, character=0)
@@ -616,7 +627,7 @@ async def test_pyrefly_config_options_benchmark():
616627
# Test different threading configurations
617628
configs: list[PyreflyConfig] = [
618629
{"threads": 0, "verbose": False}, # Auto
619-
{"threads": 1, "verbose": False}, # Sequential
630+
{"threads": 1, "verbose": False}, # Sequential
620631
{"threads": 2, "verbose": False}, # Parallel
621632
{"threads": 4, "verbose": False}, # More parallel
622633
]
@@ -626,31 +637,31 @@ async def test_pyrefly_config_options_benchmark():
626637
try:
627638
for config in configs:
628639
config_times = []
629-
640+
630641
for i in range(3):
631642
start_time = time.perf_counter()
632-
643+
633644
session = await lsp_types.Session.create(
634645
backend,
635646
initial_code=f"def test_{i}(x: int) -> int: return x * 2\nresult = test_{i}(5)",
636647
options=config, # type: ignore
637-
pool=pool
648+
pool=pool,
638649
)
639-
650+
640651
# Do some work to test performance
641652
hover_info = await session.get_hover_info(
642653
lsp_types.Position(line=0, character=4)
643654
)
644655
assert hover_info is not None
645-
656+
646657
diagnostics = await session.get_diagnostics()
647658
await session.shutdown()
648-
659+
649660
end_time = time.perf_counter()
650661
config_times.append(end_time - start_time)
651-
662+
652663
avg_time = sum(config_times) / len(config_times)
653664
print(f"\nPyrefly Config {config}: Average time {avg_time:.3f}s")
654665

655666
finally:
656-
await pool.cleanup()
667+
await pool.cleanup()

0 commit comments

Comments
 (0)