Start pyright
(self)
| 372 | """Python LSP server (pyright)""" |
| 373 | |
| 374 | async def start(self) -> bool: |
| 375 | """Start pyright""" |
| 376 | try: |
| 377 | # Check if pyright is installed |
| 378 | check_process = await asyncio.create_subprocess_exec( |
| 379 | 'pyright', |
| 380 | '--version', |
| 381 | stdout=asyncio.subprocess.PIPE, |
| 382 | stderr=asyncio.subprocess.PIPE) |
| 383 | await check_process.communicate() |
| 384 | |
| 385 | if check_process.returncode != 0: |
| 386 | logger.warning( |
| 387 | 'Pyright not found. Install with: pip install pyright') |
| 388 | return False |
| 389 | |
| 390 | # Start pyright langserver |
| 391 | self.process = await asyncio.create_subprocess_exec( |
| 392 | 'pyright-langserver', |
| 393 | '--stdio', |
| 394 | stdin=asyncio.subprocess.PIPE, |
| 395 | stdout=asyncio.subprocess.PIPE, |
| 396 | stderr=asyncio.subprocess.PIPE, |
| 397 | cwd=str(self.workspace_dir)) |
| 398 | |
| 399 | self.stdin = self.process.stdin |
| 400 | self.stdout = self.process.stdout |
| 401 | |
| 402 | async def _read_server_stderr(process): |
| 403 | while True: |
| 404 | line = await process.stderr.readline() |
| 405 | if not line: |
| 406 | break |
| 407 | logger.error( |
| 408 | f"LSP: {line.decode(errors='ignore').rstrip()}") |
| 409 | |
| 410 | asyncio.create_task(_read_server_stderr(self.process)) |
| 411 | |
| 412 | # Initialize the server |
| 413 | return await self.initialize() |
| 414 | |
| 415 | except FileNotFoundError: |
| 416 | logger.error( |
| 417 | 'pyright-langserver not found. Install with: pip install pyright' |
| 418 | ) |
| 419 | return False |
| 420 | except Exception as e: |
| 421 | logger.error(f'Failed to start Python LSP server: {e}') |
| 422 | return False |
| 423 | |
| 424 | |
| 425 | class JavaLSPServer(LSPServer): |
nothing calls this directly
no test coverage detected