fix(lsp): surface gopls spawn failure reasons to LLM via tool output#26864
fix(lsp): surface gopls spawn failure reasons to LLM via tool output#26864LinuxForYQH wants to merge 2 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
2a629f8 to
a599728
Compare
When gopls fails to start (e.g. Go runtime not installed), the error was silently swallowed, causing the LLM to only see a generic 'No LSP server available' message with no actionable guidance. Changes: - server.ts: Gopls.spawn() now throws descriptive errors instead of silently returning undefined when Go is missing or installation fails - lsp.ts: broken set -> map to store failure reasons; add failureReason() method to query stored reasons by file - tool/lsp.ts: query failureReason() when LSP unavailable, pass specific error message to LLM (e.g. 'Go runtime not found. Please install Go first')
a599728 to
437bf66
Compare
|
Rebased this PR onto the latest dev and cleaned it up to a single commit.\n\nLocal verification:\n- bun --cwd packages/opencode test --timeout 30000 test/tool/lsp.test.ts\n- bun run --cwd packages/opencode typecheck\n\nI also tried the broader related session tests, but they currently fail locally while starting the test server with |
…ureReason API and error messages)
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #26865
Type of change
What does this PR do?
When gopls fails to start (e.g. Go not installed),
Gopls.spawn()silently returnsundefined. The.catch()inlsp.tsswallows it, so the LLM only sees"No LSP server available for this file type."— no clue what's actually wrong.This PR:
Gopls.spawn()throw descriptive errors instead of silentreturn(2 cases: missing Go runtime, failedgo install)brokenfromSet<string>toMap<string, string>so failure reasons are stored alongside broken keysfailureReason(file)to the LSP servicetool/lsp.tsqueriesfailureReason()when LSP is unavailable and passes the actual error to the LLMNow the LLM gets
"Go runtime not found. Please install Go first — gopls will then be installed automatically."and can guide the user accordingly.How did you verify your code works?
npx tsc --noEmit --project packages/opencode/tsconfig.json— zero new compilation errorsserver.tsthrow →lsp.ts.catch()storeserr.messageinbrokenMap →tool/lsp.tsqueriesfailureReason()→ error surfaces to LLMScreenshots / recordings
N/A — no UI changes.
Checklist