OpenCode: OpenCode LSP Integration
Last updated: 2026-08-31
--- title: OpenCode LSP Server Configuration description: Configure LSP servers for IDE-level code analysis capabilities order: 16 lang: en
LSP (Language Server Protocol) gives OpenCode IDE-level code analysis capabilities.
1. What You Will Learn
- LSP purpose and principles
- LSP configuration in OpenCode
- Supported language servers
- Enabling experimental features
2. What is LSP
LSP provides: code completion, go-to-definition, find references, rename symbol, diagnostics, hover info.
3. Enabling LSP in OpenCode
BASH
export OPENCODE_EXPERIMENTAL_LSP_TOOL=true
Configure in opencode.json:
JSON
{
"lsp": {
"typescript": {
"command": "typescript-language-server",
"args": ["--stdio"]
},
"python": {
"command": "pylsp",
"args": []
}
}
}
4. Common Language Servers
| Language | Server | Install |
|---|---|---|
| TypeScript/JS | typescript-language-server | npm i -g typescript-language-server typescript |
| Python | pylsp / pyright | pip install python-lsp-server / npm i -g pyright |
| Go | gopls | go install golang.org/x/tools/gopls@latest |
| Rust | rust-analyzer | rustup component add rust-analyzer |
| C/C++ | clangd | System package manager |
5. Usage
After enabling, AI uses LSP for precise analysis:
TEXT
📖 Display only
Find all references to the auth function
❓ FAQ
Q Is LSP required?
A No. Without LSP, OpenCode still analyzes code via file reading and search. LSP adds more precise analysis (go-to-definition, find references).
Q LSP server slow to start?
A Large projects need indexing on first start. Pre-start the LSP server—OpenCode reuses existing instances.
📖 Summary
- LSP provides IDE-level code analysis
- Enable via
OPENCODE_EXPERIMENTAL_LSP_TOOL - Configure servers in opencode.json lsp field
- Common languages: TS, Python, Go, Rust all supported
- Enhancement feature—works without it
📝 Exercises
-
Basic: Install an LSP server for your primary language.
-
Intermediate: Configure LSP in opencode.json for go-to-definition and find references.
-
Advanced: Compare code analysis accuracy with and without LSP.