Commit Graph

33 Commits

Author SHA1 Message Date
0aa44bedc4 fix(watcher): coalesce edge cases, drain on unregister, expose ready()
Addresses review feedback on 7787626:

1. Deleted->Created at the same path is a file replacement, not a no-op.
   Previous coalescing dropped both Created->Deleted and Deleted->Created;
   the latter left the server with no signal to re-read replaced content.
   Now: Deleted->Created collapses to Changed, Created->Changed keeps
   Created (server didn't know the file at all). Extracted coalesce() so
   the matrix is reviewable in one place.

2. setPatterns([]) (server unregistered all watchers) stopped chokidar
   but left pending events + timers intact, so a queued batch could
   still fire after the server stopped caring. Now drains via
   cancelPending() before stopping chokidar.

3. Added ready() returning a promise resolved by chokidar's initial-scan
   'ready' event. Production daemon doesn't need to await it (LSP
   handshake gives chokidar ample wall-time), but tests now use it
   instead of fixed 200ms sleeps - deflakes the suite on slower
   filesystems and addresses the (narrow) startup race where a file
   created during chokidar's initial crawl could be missed.

4. Unit tests replace 11 hardcoded sleeps with watcher.ready(), and add
   coverage for the two coalesce fixes plus the unregister-drains case.
2026-05-19 23:51:32 -04:00
77876264ee feat(watcher): forward FS events as workspace/didChangeWatchedFiles
LSP servers maintain their own workspace index built at initialize time
and rely on the client to push file-system events. Previously the daemon
only synced the single file being queried, so externally created/changed
files (codegen, build scripts, git checkout, the agent's own writes from
the perspective of other open files) left the server's index stale until
manual /lsp-destroy.

Each ClientEntry now lazily owns a WorkspaceWatcher (chokidar + picomatch)
that translates FS events into workspace/didChangeWatchedFiles batches.
Patterns come from the server via client/registerCapability (no
speculative watching). Ignores layer a tiny baseline (.git, .DS_Store)
over the repo's root .gitignore, with a fallback list for non-git
workspaces. Events debounce 50ms quiet / 500ms max wait.

Notable: gopls registers absolute-path globs (/abs/root/**/*.go) rather
than relative ones, so compileWatchers() matches each event against both
relative and absolute path forms. Caught by the integration test; unit
regression test added.

Rollback: PI_LSP_DISABLE_WATCHERS=1 disables all watcher creation.

- src/client.ts: honor register/unregisterCapability for
  workspace/didChangeWatchedFiles; advertise dynamicRegistration;
  expose getFileWatchers/onWatchersChanged/sendNotification
- src/watcher.ts: new WorkspaceWatcher with layered ignores,
  debounce+batch, Created+Deleted coalescing, dual-form glob matching
- src/daemon.ts: per-entry watcher lifecycle, PI_LSP_DISABLE_WATCHERS,
  LSP_DEBUG-gated pattern/event logging
- test/unit/watcher.test.ts: 11 tests against real chokidar + temp dir
- test/integration/watcher-gopls.test.ts: end-to-end against gopls
- AGENTS.md: new "Workspace File Watching" section
- flake.nix: add go (required by gopls integration test)
2026-05-19 23:43:32 -04:00
e143e05758 feat(servers): split vscode-html-language-server and add css, json, bash, sql servers
- Split vscode-html-language-server into separate servers for HTML, CSS,
  and JSON with proper language IDs and file extensions
- Added bash-language-server for shell scripts (.sh, .bash)
- Added sqls for SQL files
- Added timeout wrapper to auto-check diagnostics to prevent blocking pi
2026-05-08 18:51:12 -04:00
46e3cc4ccd feat(config): add per-repo .pi-lsp.json server overrides
Users can now drop a .pi-lsp.json at any ancestor of their working
files to add new LSP servers, override built-in ones, or disable
servers entirely. The nearest config (walking upward) wins.

- New src/config.ts: walks upward for .pi-lsp.json, parses, and
  merges with the built-in registry. Cached per config-file path
  with mtime invalidation. Falls back to built-ins on parse error.
- Merge rules: matching id shallow-merges (user wins); new id
  appends (must include match/command/args/rootMarkers); `disable`
  filters at the end.
- src/root.ts: pickServer() now resolves servers via the per-repo
  registry. Adds findServerById(filePath, id) and re-exports
  getServersForPath() for callers.
- src/daemon.ts: getOrCreateEntry() resolves serverId against the
  filePath's config so spawned servers reflect repo overrides.
- index.ts and cli.ts: replace direct `servers` imports with
  path-aware getServersForPath() lookups.
- Tests: 9 new unit tests covering merge semantics, walk-up
  discovery, mtime invalidation, and graceful fallback.
- Docs: README "Per-Repo Config" section + AGENTS.md updates.
2026-05-07 22:43:41 -04:00
0b23e203f4 build(flake): add gopls and pyright for tests 2026-05-07 22:43:28 -04:00
9e5a0677c8 feat: add svelteserver to LSP server registry 2026-05-07 21:19:46 -04:00
99ce79ac88 fix(lsp): support server workspace configuration 2026-05-05 23:44:21 -04:00
81ab984a86 chore: add oxlint 2026-05-04 07:45:50 -04:00
e40c93fc80 feat(server): add diagnosticsOnly flag for lint-only servers
Add diagnosticsOnly?: boolean to ServerConfig. When set, the server is
excluded from pickServer() (hover/definition/references/completion/
documentSymbol) but still included in pickDiagnosticServers() for
lsp_diagnostics and auto-check.

Mark oxlint as diagnosticsOnly: true — it now contributes diagnostics
alongside typescript-language-server without interfering with navigation
or completion tools.
2026-05-04 07:41:39 -04:00
b9808a8b1f refactor(daemon): require explicit serverId on all daemon ops
Move all server matching logic to the extension/CLI side. The daemon no
longer calls pickServer() — it receives an explicit serverId (or
serverIds[] for diagnostics) and uses it directly for cache lookup and
server spawning.

Key changes:
- request op requires serverId: string
- diagnostics op requires serverIds: string[] — daemon fans out in
  parallel via Promise.allSettled and returns grouped map
- formatDiagnostics() handles grouped results with per-server headers
  when multiple servers contribute (single-server omits header)
- CLI picks servers locally before calling daemon helpers
- New pickDiagnosticServers() in extension returns all available,
  non-disabled servers matching the file extension

This makes multi-server diagnostics (e.g., typescript-language-server +
oxlint) work naturally — the extension decides which servers to query,
the daemon just executes.
2026-05-04 07:39:03 -04:00
d24e2e94f4 refactor(root): extract isOnPath and add extension-side server qualification
Extract isOnPath() to shared src/util.ts so both the daemon (client.ts)
and extension (root.ts) can use it. Add isServerAvailable() with a
per-process cache to pickServer(), skipping servers whose binary isn't
on PATH before sending requests to the daemon.

This avoids wasted daemon round-trips for missing binaries and sets up
for upcoming multi-server diagnostics fan-out.
2026-05-04 07:24:59 -04:00
630226a00a feat: add lua, html/css/json, nix, and oxlint LSPs; add global .git root marker 2026-05-04 06:59:08 -04:00
f811efef68 fix(diagnostics): sort by severity before truncating
Errors appear first, then warnings, info, hints. Ensures the most
actionable issues survive the cap instead of being pushed out by
low-priority hints.
2026-05-02 20:24:35 -04:00
01ab10a7d9 feat(references): cap formatted references at 30 with truncation notice
Prevents flooding the context window when a common symbol has hundreds
of references. Shows the first 30 and appends a count of the remainder.
2026-05-02 20:24:27 -04:00
99525ad0ee feat(diagnostics): cap diagnostic output with truncation notice
Add a limit parameter to formatDiagnostics (default 20 for explicit
lsp_diagnostics calls, 10 for auto-check after edit/write). When
truncated, a summary line indicates how many more diagnostics exist.
2026-05-02 20:13:05 -04:00
04fd520438 fix(daemon): launch LSP servers with caller env 2026-05-02 15:28:25 -04:00
306771f92a refactor(extension): resolve remaining type narrowing diagnostics
Narrow `unknown` types with explicit casts before `in` operator checks
to avoid "Type '{}' may represent a primitive value" errors. Also fix
getActiveTools() which returns string[] (not object[]), removing the
unnecessary .map((t) => t.name). Brings index.ts to zero diagnostics.
2026-05-02 00:50:16 -04:00
4b486b2464 build: add pi-coding-agent and typebox dev dependencies
Resolve 47 of 52 LSP diagnostics: module-not-found errors for
@mariozechner/pi-coding-agent and typebox, plus cascading implicit-any
errors on callback parameters. Both packages are available on npm and
provided at runtime by pi.
2026-05-02 00:46:46 -04:00
6111321fda fix(extension): suppress warnings for unsupported file types and missing binaries
Move pickServer() into the try-catch in runLsp() so UnsupportedExtensionError
is caught directly. Add message-based fallback in both runLsp() and
runDiagnostics() to handle daemon-wrapped errors that come through as plain
Error instances rather than the original typed exception.

This eliminates spurious 'No LSP server registered' warnings during auto-check
after edit/write on files without LSP support (e.g. .md, .txt, .sh).
2026-05-02 00:42:44 -04:00
9b863168ff fix: handle unhandled promise rejection in background read init 2026-04-30 11:53:43 -04:00
b614e700fd fix(daemon): tear down daemon when destroying all servers with no entries 2026-04-30 11:41:37 -04:00
620d9cc70f feat: warm-start LSP server on file read 2026-04-30 11:10:36 -04:00
aa7309b363 test: add unit and integration test suite
Add 34 tests (27 unit, 7 integration) using node:test runner:

Unit tests:
- pickServer(), findRoot(), pathToUri(), uriToPath()
- isLspCommand(), listCommands()
- formatHover(), formatDefinition(), formatReferences(), formatDiagnostics()

Integration tests:
- daemon lifecycle (status/stop) on isolated socket
- CLI --no-daemon queries (hover, documentSymbol, diagnostics)

Supporting changes:
- socketPath() honors PI_LSP_SOCKET_PATH env var for test isolation
- test fixtures for valid and broken TypeScript files
- npm test / test:unit / test:integration scripts
2026-04-30 10:36:54 -04:00
e131e0e8cd feat: add server control commands (disable, enable, destroy)
Add /lsp-servers, /lsp-disable, /lsp-enable, and /lsp-destroy TUI commands.
Disabled servers are tracked in-memory per-extension-instance; the shared
daemon is never mutated by disable/enable. When all servers are disabled,
LSP tools are removed from the active tool set so the LLM won't attempt them.

Also adds a destroy_server daemon operation that kills running LspClient
entries by server ID or all entries.
2026-04-30 09:48:01 -04:00
7abe4efa02 refactor: replace string-matching error checks with custom error classes 2026-04-30 08:27:13 -04:00
81ed5c88b8 fix(daemon): auto-shutdown when last LSP server entry is evicted 2026-04-30 08:21:16 -04:00
36b9b0cde4 docs: add AGENTS.md with project context and conventions 2026-04-30 08:21:09 -04:00
a516d80c71 fix(cli): harden no-daemon teardown 2026-04-29 16:18:27 -04:00
d073f2272f chore: rename project to evan/pi-lsp 2026-04-29 00:16:51 -04:00
46aac3ef39 build: add oxlint 2026-04-29 00:08:34 -04:00
076eee4e96 feat(lsp): add background daemon for language servers 2026-04-29 00:04:06 -04:00
60b8900a09 chore: add nix flake for dev environment 2026-04-26 09:45:41 -04:00
61bca87bba initial commit 2026-04-25 21:06:15 -04:00