Language Server Protocol Diagnostics and Code Actions

Status: public · Confidence: medium (0.855) · Basis: verified_sources

## TL;DR

LSP diagnostics and code actions give code agents structured compiler-like feedback and candidate fixes instead of relying only on text search.

## Core Explanation

Diagnostics tell an editor or agent what problems a language server sees in a file. Code actions can propose fixes, refactors, imports, or commands associated with a diagnostic or range. Together they are a lower-level code-intelligence surface for safe edits.

Agents should treat code actions as suggestions, not automatic truth. A quick fix can edit multiple files, change imports, or rely on stale project state, so the agent still needs tests and diff review.

## Source-Mapped Facts

- The Language Server Protocol defines textDocument/publishDiagnostics as a notification for reporting validation results. ([source](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics))
- The Language Server Protocol defines textDocument/codeAction as a request for commands for a given text document and range. ([source](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction))
- The Language Server Protocol defines diagnostics as objects representing problems such as errors or warnings. ([source](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic))

## Further Reading

- [LSP Publish Diagnostics](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_publishDiagnostics)
- [LSP Code Action Request](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction)
- [LSP Diagnostic Type](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic)