Skip to content

fix(diagnostics): wait for publishDiagnostics instead of sleeping 3s#131

Open
STRd6 wants to merge 1 commit into
isaacphi:mainfrom
STRd6:civet-fixes
Open

fix(diagnostics): wait for publishDiagnostics instead of sleeping 3s#131
STRd6 wants to merge 1 commit into
isaacphi:mainfrom
STRd6:civet-fixes

Conversation

@STRd6
Copy link
Copy Markdown

@STRd6 STRd6 commented May 13, 2026

Summary

The diagnostics tool currently sleeps a hardcoded time.Sleep(time.Second * 3) after OpenFile then calls textDocument/diagnostic (pull-mode). Two problems:

  • 3s minimum latency per call, even when the LSP has already published diagnostics within milliseconds. The original comment was // TODO: wait for notification.
  • Push-only LSPs (TypeScript-server, Civet, others) reject the pull request with -32601, which surfaces as a top-level [ERROR][tools] Failed to get diagnostics: ... Unhandled method textDocument/diagnostic even though the publishDiagnostics cache was populated correctly. This is the exact symptom reported in Unreliable diagnostics for typescript-server #60.

Fix

  • Adds Client.WaitForDiagnostics(uri, timeout, settle) which blocks until textDocument/publishDiagnostics arrives for the URI (signaled from the existing handler), with a settle window for follow-up republishes that some servers send after a project-wide rescan.
  • GetDiagnosticsForFile calls WaitForDiagnostics(ctx, uri, 3*time.Second, 150*time.Millisecond) instead of the unconditional sleep. The 3s upper bound preserves the previous worst case.
  • The textDocument/diagnostic pull call is kept (still useful for true pull-mode servers like gopls) but the unavailable-method log goes from Error to Debug — push-only servers are common and the cache is already fresh.

No changes to public tool surface or arguments. Pull-mode LSPs see no behavioral change beyond faster return after publish.

Impact

Measured against a push-only LSP (Civet language server) with a file containing two TS type errors:

call before after
diagnostics cold 3008 ms 414 ms
diagnostics warm 3002 ms 0 ms

Closes #60.

Test plan

  • Build with Go 1.24
  • Smoke test against push-only LSP (civet-lsp): both diagnostics returned at correct source positions with severity/code/snippet, no -32601 error noise
  • Warm path returns from cache instantly
  • Verify pull-mode LSP (gopls) still works — would appreciate confirmation from a Go-project user; the pull call is unchanged, only its failure-log level moved

🤖 Generated with Claude Code

…ping 3s

The diagnostics tool slept a hardcoded 3s after open_document then fell
back to a textDocument/diagnostic pull request. Servers that only
support push-mode diagnostics (e.g. Civet's LSP) returned -32601, which
was logged as an error even though the publishDiagnostics cache was
already populated correctly.

This change:
- Adds Client.WaitForDiagnostics(uri, timeout, settle) which blocks
  until the LSP publishes diagnostics for the URI (signaled by the
  publishDiagnostics handler), with a settle window for follow-up
  republishes.
- Replaces the 3s sleep in GetDiagnosticsForFile with that wait.
- Demotes the pull-mode failure from Error to Debug — push-only servers
  are common (Civet, several others) and the pull is an optional
  optimization, not a requirement.

Measured against civet-lsp: cold call 3008ms -> 414ms, warm 3002ms -> 0ms.
STRd6 pushed a commit to STRd6/mcp-language-server that referenced this pull request May 14, 2026
Upstream's last commit on isaacphi/main is 2025-06-03 — ~11 months
of inactivity. PR isaacphi#131 has sat in their review queue unmerged since
the start of this session. The expected-upstream-merge path that
justified keeping the original module path no longer applies in
practice.

Renames the module to github.com/STRd6/mcp-language-server across:
- go.mod
- every internal import (~80 .go files)
- the integration-test template workspaces' go.mod
- the snapshots that capture gopls hover/definition output (which
  embeds package paths)
- README install instructions

go install github.com/STRd6/mcp-language-server@latest now works.
Anyone using the previous install path (go install github.com/isaacphi/...)
keeps getting upstream's 2025-06-03 cut; they will need to switch
binaries to pick up this fork's changes.

The import-path inside go.mod is the only signal a Go compiler uses
to identify a module, so the GoDoc badge in the README is dropped
since pkg.go.dev/STRd6/... isn't indexed by GoDoc the same way.
The other three badges (CI, Go report card, go-version) already
pointed at STRd6 in the previous README refresh.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unreliable diagnostics for typescript-server

1 participant