Start jdtls (Eclipse JDT Language Server)
(self)
| 426 | """Java LSP server (Eclipse JDT Language Server)""" |
| 427 | |
| 428 | async def start(self) -> bool: |
| 429 | """Start jdtls (Eclipse JDT Language Server)""" |
| 430 | try: |
| 431 | # Check if jdtls is available |
| 432 | # Try common installation locations |
| 433 | jdtls_paths = [ |
| 434 | '/usr/local/bin/jdtls', |
| 435 | '/opt/homebrew/bin/jdtls', |
| 436 | os.path.expanduser('~/.local/bin/jdtls'), |
| 437 | ] |
| 438 | |
| 439 | jdtls_cmd = None |
| 440 | for path in jdtls_paths: |
| 441 | if os.path.exists(path): |
| 442 | jdtls_cmd = path |
| 443 | break |
| 444 | |
| 445 | if not jdtls_cmd: |
| 446 | # Try to find in PATH |
| 447 | check_process = await asyncio.create_subprocess_exec( |
| 448 | 'which', |
| 449 | 'jdtls', |
| 450 | stdout=asyncio.subprocess.PIPE, |
| 451 | stderr=asyncio.subprocess.PIPE) |
| 452 | stdout, _ = await check_process.communicate() |
| 453 | if check_process.returncode == 0: |
| 454 | jdtls_cmd = stdout.decode('utf-8').strip() |
| 455 | |
| 456 | if not jdtls_cmd: |
| 457 | logger.warning( |
| 458 | 'jdtls not found. Install Eclipse JDT Language Server.\n' |
| 459 | 'macOS: brew install jdtls\n' |
| 460 | 'Or download from: https://download.eclipse.org/jdtls/snapshots/' |
| 461 | ) |
| 462 | return False |
| 463 | |
| 464 | # Create workspace data directory for jdtls |
| 465 | workspace_data_dir = Path(self.workspace_dir) / '.jdtls_workspace' |
| 466 | workspace_data_dir.mkdir(exist_ok=True) |
| 467 | |
| 468 | # Start jdtls |
| 469 | self.process = await asyncio.create_subprocess_exec( |
| 470 | jdtls_cmd, |
| 471 | '-data', |
| 472 | str(workspace_data_dir), |
| 473 | stdin=asyncio.subprocess.PIPE, |
| 474 | stdout=asyncio.subprocess.PIPE, |
| 475 | stderr=asyncio.subprocess.PIPE, |
| 476 | cwd=str(self.workspace_dir)) |
| 477 | |
| 478 | self.stdin = self.process.stdin |
| 479 | self.stdout = self.process.stdout |
| 480 | |
| 481 | # Initialize the server |
| 482 | return await self.initialize() |
| 483 | |
| 484 | except FileNotFoundError: |
| 485 | logger.error( |
no test coverage detected