1111
1212import lsp_types
1313from lsp_types .pool import LSPProcessPool
14- from lsp_types .pyright .backend import PyrightBackend
1514from 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):
447453class 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\n result = 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"\n Pyrefly Config { config } : Average time { avg_time :.3f} s" )
654665
655666 finally :
656- await pool .cleanup ()
667+ await pool .cleanup ()
0 commit comments