11from __future__ import annotations
22
33import json
4+ import shutil
45from pathlib import Path
56
67import lsp_types
1415class PyrightBackend (LSPBackend ):
1516 """Pyright-specific LSP backend implementation"""
1617
18+ def __init__ (self , * , node_flags : list [str ] | None = None ):
19+ """
20+ Initialize PyrightBackend.
21+
22+ Args:
23+ node_flags: Optional list of node flags to pass when launching the server.
24+ If provided, pyright-langserver will be launched via node with these flags.
25+ Example: ['--prof'] for profiling, ['--cpu-prof'] for CPU profiling.
26+ """
27+ self ._node_flags = node_flags or []
28+
1729 def write_config (self , base_path : Path , options : PyrightConfig ) -> None :
1830 """Write pyrightconfig.json configuration file"""
1931 config_path = base_path / "pyrightconfig.json"
@@ -24,7 +36,20 @@ def create_process_launch_info(
2436 ) -> ProcessLaunchInfo :
2537 """Create process launch info for Pyright LSP server"""
2638 # NOTE: requires node and basedpyright to be installed and accessible
27- return ProcessLaunchInfo (cmd = ["pyright-langserver" , "--stdio" ], cwd = base_path )
39+ if self ._node_flags :
40+ # Launch via node with specified flags
41+ langserver_path = shutil .which ("pyright-langserver" )
42+ if not langserver_path :
43+ raise RuntimeError (
44+ "pyright-langserver not found in PATH. "
45+ "Please ensure it is installed and accessible."
46+ )
47+ cmd = ["node" , * self ._node_flags , langserver_path , "--stdio" ]
48+ else :
49+ # Direct invocation (default behavior)
50+ cmd = ["pyright-langserver" , "--stdio" ]
51+
52+ return ProcessLaunchInfo (cmd = cmd , cwd = base_path )
2853
2954 def get_lsp_capabilities (self ) -> types .ClientCapabilities :
3055 """Get LSP client capabilities for Pyright"""
0 commit comments