LSP Servers
Language Server Protocol (LSP) support gives opencode deep code intelligence capabilities. When enabled, opencode can query language servers for definitions, references, hover information, symbols, call hierarchies, and more.
Enabling LSP
Enable LSP globally by setting the lsp key to true in opencode.json:
{
"lsp": true
}
When enabled, opencode automatically starts the appropriate LSP server for each detected language in your workspace.
Supported Languages and Servers
Running many LSP servers can increase memory usage — disable languages you do not use.
opencode includes built-in support for the following language servers:
| Language | Server | Notes |
|---|---|---|
| TypeScript / JavaScript | typescript-language-server | Full TS/JS support |
| Python | pyright or pylsp | Configurable via settings |
| Rust | rust-analyzer | Requires Rust toolchain |
| Go | gopls | Standard Go LSP |
| Java | eclipse-jdtls | Requires JDK |
| C / C++ | clangd | Requires clang tools |
| Ruby | solargraph | Requires gem installation |
| PHP | intelephense | PHP language server |
| HTML / CSS / JSON | vscode-langservers-extracted | Built-in web support |
| YAML | yaml-language-server | YAML validation |
| Markdown | marksman | Markdown intelligence |
| Lua | lua-language-server | Lua development |
| Shell | bash-language-server | Shell scripting |
Configuring Individual Servers
You can disable specific language servers while keeping LSP enabled for others:
{
"lsp": {
"typescript": { "disabled": true },
"python": { "disabled": true }
}
}
You can also pass configuration options to individual servers:
{
"lsp": {
"python": {
"settings": {
"python": {
"analysis": {
"typeCheckingMode": "strict",
"autoImportCompletions": true
}
}
}
},
"rust-analyzer": {
"settings": {
"rust-analyzer": {
"checkOnSave": true,
"inlayHints": { "typeHints": true }
}
}
}
}
}
Experimental LSP Tool
The LSP tool is experimental and must be explicitly enabled — it is off by default.
Enabling
Set the environment variable:
export OPENCODE_EXPERIMENTAL_LSP_TOOL=true
Supported Operations
When the experimental LSP tool is active, the model can invoke these operations:
| Operation | Description |
|---|---|
goToDefinition | Navigate to the definition of a symbol |
findReferences | Find all references to a symbol |
hover | Show hover information for a symbol |
documentSymbol | List all symbols in the current document |
workspaceSymbol | Search for symbols across the workspace |
goToImplementation | Navigate to implementations of an interface or type |
prepareCallHierarchy | Prepare call hierarchy data for a symbol |
incomingCalls | Show calls that invoke the given symbol |
outgoingCalls | Show calls the given symbol makes |
Usage Example
Once enabled, the model can request LSP information during a conversation. For example, when you ask "What does this function do?", the model may invoke the hover operation against the symbol at the cursor position.
How LSP Works in opencode
{
"lsp": {
"typescript": {
"settings": {
"typescript": {
"exclude": ["node_modules", "dist", "build"]
}
}
}
}
}
Troubleshooting
Server Fails to Start
If a language server does not start:
- Verify the required runtime is installed (e.g., Node.js for TypeScript, JDK for Java).
- Check the server logs:
opencode debug lsp
- Try starting the server manually to verify it works:
typescript-language-server --stdio
LSP Tool Returns No Results
If the experimental LSP tool returns empty results:
- Confirm the document is saved and the language server has finished indexing.
- Check that the symbol exists in the current workspace.
- Verify the
OPENCODE_EXPERIMENTAL_LSP_TOOL=trueenvironment variable is set.
Slow Performance
If LSP operations are slow:
- Disable servers for languages you do not use.
- Reduce the workspace scope by opening only relevant directories.
- Increase server initialization timeout if needed:
{
"lsp": {
"initializeTimeoutMs": 30000
}
}
{
"lsp": false
}