feat(lsp): add background daemon for language servers

This commit is contained in:
2026-04-29 00:04:06 -04:00
parent 60b8900a09
commit 076eee4e96
12 changed files with 707 additions and 76 deletions

View File

@@ -40,9 +40,16 @@ npm install
## CLI Usage (for development/testing)
```
tsx ./cli.ts <file> <lsp_command> <req_data_json>
tsx ./cli.ts <file> <lsp_command> <req_data_json> [--no-daemon]
tsx ./cli.ts daemon <status|stop>
```
Requests use a long-lived background daemon by default. The daemon is
autospawned on first use, keeps one language server alive per
`(server.id, project root)`, and evicts idle servers after
`ServerConfig.idleTtlMs` (default: 5 minutes). Pass `--no-daemon` to use the
legacy one-shot path for debugging.
`req_data_json` is the raw LSP params for the command, minus
`textDocument.uri` (we inject that from `<file>`).
@@ -71,9 +78,15 @@ npm run lsp -- backend/api/server.go documentSymbol '{}'
# Diagnostics
npm run lsp -- backend/api/server.go diagnostics '{}'
# Inspect/stop the background daemon
npm run lsp -- daemon status
npm run lsp -- daemon stop
```
Set `LSP_DEBUG=1` to forward server stderr.
Set `LSP_DEBUG=1` to forward server stderr to the daemon log. The daemon
socket is `$XDG_RUNTIME_DIR/pi-lsp-$UID.sock` (tmpdir fallback); logs are in
`/tmp/pi-lsp-daemon.log`.
## Adding A Server
@@ -97,7 +110,5 @@ Edit `server.ts`:
## Future
- **Daemon with TTL** - `ServerConfig.idleTtlMs` is reserved for a future
daemon that keeps language servers alive per `(server.id, rootUri)` to
avoid cold-start latency. Not implemented; the CLI is short-lived and
spawns fresh each invocation.
- **Daemon hardening** - persistent metrics, health checks, and richer status output.
- **Build output** - ship compiled JS entrypoints instead of relying on tsx for development.