OpenCode
OpenCode is a terminal-based AI coding agent. It integrates with LSP servers to give the AI access to diagnostics, go-to-definition, references, hover, and more.
For the full settings schema, see Setup Overview.
LSP tool (experimental)
OpenCode has an experimental lsp tool that gives the AI direct access to LSP methods. Enable it with:
OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencodeOr set it in your environment permanently:
export OPENCODE_EXPERIMENTAL_LSP_TOOL=trueWith the LSP tool enabled, the AI agent can call:
| Operation | LSP Method | Description |
|---|---|---|
hover | textDocument/hover | Type info, NatSpec docs, selectors |
goToDefinition | textDocument/definition | Jump to symbol definition |
findReferences | textDocument/references | Find all references to a symbol |
goToImplementation | textDocument/implementation | Find implementations |
documentSymbol | textDocument/documentSymbol | Browse file structure |
workspaceSymbol | workspace/symbol | Search symbols across project |
prepareCallHierarchy | callHierarchy/prepare | Trace call graphs |
incomingCalls | callHierarchy/incomingCalls | Who calls this function |
outgoingCalls | callHierarchy/outgoingCalls | What this function calls |
Example: hover
OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencode run "use the lsp tool to hover on src/Pool.sol at line 102 col 15"The AI will invoke the LSP hover method and get back type signatures, NatSpec documentation, and function selectors from the Solidity language server.
Example: find references
OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencode run "use the lsp tool to find all references to the initialize function in src/PoolManager.sol"Configure
Add to your global config (~/.config/opencode/opencode.json) or project-level opencode.json. The solidity-language-server binary must be in your $PATH (installed via cargo install solidity-language-server).
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"solidity": {
"command": ["solidity-language-server", "--stdio"],
"extensions": [".sol"],
"initialization": {
"solidity-language-server": {
"inlayHints": {
"parameters": true
},
"lint": {
"enabled": true
},
"fileOperations": {
"templateOnCreate": true,
"updateImportsOnRename": true,
"updateImportsOnDelete": true
},
"projectIndex": {
"fullProjectScan": true
}
}
}
}
}
}How it works
When OpenCode encounters a .sol file, it automatically:
- Starts the Solidity language server
- Sends
textDocument/didOpento index the file - Collects diagnostics (errors, warnings, lint) and feeds them to the AI agent
- The AI uses diagnostics to detect and fix issues in code it writes
Lint options reference
Lint options (severity, rule IDs, only, exclude) are documented in Setup Overview - Lint values.