Repository navigation
Description
Description
Feature hasn't been suggested before.
- I have verified this feature I'm about to request hasn't been suggested before.
Describe the enhancement you want to request
Feature Request: Expose LSP Diagnostics in the Tool Surface
Summary
Please add first-class LSP diagnostics support to the chat tool surface and auto-surface current-file diagnostics from read when an LSP client exists for that file type.
Problem
OpenCode already receives and stores diagnostics internally via textDocument/publishDiagnostics, but the chat-facing lsp tool does not expose them. As a result, when users ask simple questions like:
what warnings are in this file?does this file have diagnostics?read path/to/file
…the agent often falls back to running compiler commands, shell commands, or full build steps instead of using the language server directly.
The Problem: diagnostics are available internally, but not available as a first-class tool capability in the agent surface.
Impact: Without direct LSP diagnostics support, the agent cannot reliably:
- answer file-warning questions cheaply
- prefer language-server diagnostics over heavyweight compiler or build invocations
- surface current file errors/warnings during normal file reads
- avoid noisy project-wide output for simple file-level questions
This is especially noticeable in projects where users often just want the warnings for one file.
Example
Without LSP diagnostics surfaced (what the agent does today)
User: does this file have any warnings?
Agent: runs a compiler or build command
Agent: scans project-wide output for mentions of the file
With LSP diagnostics surfaced (what should happen)
User: does path/to/file have any warnings?
Agent: uses LSP diagnostics for path/to/file
Agent: returns:
- no-unused-vars: "x" is declared but its value is never read
- missing-return-type: Function is missing an explicit return type
Read flow example
User: read path/to/file
Tool output:
<path>/repo/path/to/file</path>
<type>file</type>
<content>
1: const x = 1
(End of file - total 1 lines)
</content>
<diagnostics file="/repo/path/to/file">
WARN [1:7] "x" is declared but its value is never read
WARN [1:1] Function is missing an explicit return type
</diagnostics>
Use Cases
-
File-Level Warning Checks: Users ask if a specific file has warnings/errors and expect a quick answer without running a project-wide build.
-
Better Tool Selection: The agent should prefer LSP diagnostics when available instead of reaching for compiler commands, shell commands, or full build steps just to get file errors.
-
Diagnostics While Reading Code:
read path/to/fileshould optionally surface current warnings/errors if an LSP server exists for that file type. -
Lower Noise, Faster Feedback: File-level diagnostics are more targeted than whole-project build output and are usually the right default for conversational queries.
Proposed Implementation
Files likely touched
packages/opencode/src/tool/lsp.tspackages/opencode/src/tool/lsp.txtpackages/opencode/src/tool/read.tspackages/opencode/src/tool/read.txt
1. Add a diagnostics LSP tool operation
Expose a first-class file-based diagnostics operation from the existing LSP tool.
Expected behavior:
operation: "diagnostics"- requires
filePath - does not require
lineorcharacter - touches the file / waits for diagnostics
- returns diagnostics only for that file
Example request:
{
"operation": "diagnostics",
"filePath": "path/to/file"
}Example implementation sketch in packages/opencode/src/tool/lsp.ts:
const operations = [
"goToDefinition",
"findReferences",
"diagnostics",
"hover",
"documentSymbol",
"workspaceSymbol",
"goToImplementation",
"prepareCallHierarchy",
"incomingCalls",
"outgoingCalls",
] as const
const positionOperations = [
"goToDefinition",
"findReferences",
"hover",
"goToImplementation",
"prepareCallHierarchy",
"incomingCalls",
"outgoingCalls",
] as const
parameters: z.object({
operation: z.enum(operations),
filePath: z.string(),
line: z.number().int().min(1).optional(),
character: z.number().int().min(1).optional(),
}).superRefine((args, ctx) => {
if (positionOperations.includes(args.operation)) {
if (args.line === undefined) ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["line"], message: "line is required" })
if (args.character === undefined) ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["character"], message: "character is required" })
}
})
case "diagnostics": {
await LSP.touchFile(file, true)
const diagnostics = await LSP.diagnostics()
return diagnostics[Filesystem.normalizePath(file)] ?? []
}Example result:
[
{
"code": "no-unused-vars",
"message": "\"x\" is declared but its value is never read.",
"severity": 2,
"source": "language-server"
},
{
"code": "missing-return-type",
"message": "Function is missing an explicit return type.",
"severity": 2,
"source": "language-server"
}
]2. Auto-surface diagnostics from read
When read is called on a file and LSP.hasClients(file) is true:
- touch the file
- wait for diagnostics
- attach warning/error diagnostics for that file to the tool output and metadata
Example implementation sketch in packages/opencode/src/tool/read.ts:
async function getFileDiagnostics(filepath: string) {
const hasClients = await LSP.hasClients(filepath).catch(() => false)
if (!hasClients) return []
await LSP.touchFile(filepath, true).catch(() => {})
const diagnostics = await LSP.diagnostics().catch(() => ({}))
const issues = diagnostics[Filesystem.normalizePath(filepath)] ?? []
return issues.filter((item) => item.severity === 1 || item.severity === 2)
}Then append to read output:
if (diagnostics.length > 0) {
output += `\n\n<diagnostics file="${filepath}">\n${diagnostics.map(LSP.Diagnostic.pretty).join("\n")}\n</diagnostics>`
}Related issues
I checked current open issues and did not find another open feature request for exposing diagnostics as a first-class chat/tool capability plus auto-surfacing them from read.
Related but distinct issues:
- LSP diagnostics are skipped or delayed under multiple conditions #12288
LSP diagnostics are skipped or delayed under multiple conditions - gopls LSP tools broken —
symbolsnever spawns server,document-symbols/diagnosticshave path handling bugs #15314gopls LSP tools broken — symbols never spawns server, document-symbols/diagnostics have path handling bugs - LSP diagnostics from external projects leak into tool results and context window #16353
LSP diagnostics from external projects leak into tool results and context window - disable diagnostics on the fly #12702
disable diagnostics on the fly - [FEATURE]: Force LSP usage #8712
[FEATURE]: Force LSP usage - [FEATURE]: Export LSP functionality through @opencode-ai/plugin for custom tools #4410
[FEATURE]: Export LSP functionality through @opencode-ai/plugin for custom tools
Those appear to focus on reliability, bugs, configuration, or other LSP feature exposure rather than this specific request to expose file diagnostics in the built-in chat tool surface and auto-surface them during reads.
Notes
OpenCode already has most of the plumbing:
- diagnostics are collected internally from
textDocument/publishDiagnostics LSP.diagnostics()already aggregates themopencode debug lsp diagnostics <file>can already print them
So the missing piece is mainly exposing diagnostics through the actual tool schema/API used by the chat agent and surfacing them automatically during normal file reads.
Example user flows
read path/to/file-> file contents plus current diagnosticsuse lsp diagnostics on path/to/file-> explicit file diagnostics without fake positional argumentsdoes this file have any warnings?-> agent uses LSP diagnostics instead of compiler/build output
Priority
Medium-High
This would reduce unnecessary compiler invocations and make OpenCode's LSP support much more useful for normal coding conversations.
Additional Context
This feature is useful across languages and ecosystems because users often ask for warnings in one file, while compiler or build output is broader, noisier, and slower than the language server path.
Tags: lsp, diagnostics, enhancement, tooling
Activity
[-]Expose LSP diagnostics as a tool and auto-surface them on read[/-][+][FEATURE]: Expose LSP diagnostics as a tool and auto-surface them on read[/+]github-actions commentedon Mar 8, 2026
Thanks for updating the issue! It now meets our contributing guidelines — the title has been corrected to start with
[FEATURE]:and the verification checkbox is present. The issue looks good to go.github-actions commentedon Jul 3, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.