OpenCode integrates with Language Server Protocol (LSP) to provide code intelligence features across multiple programming languages. The AI assistant can access diagnostics, errors, and warnings to help you write better code.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/opencode-ai/opencode/llms.txt
Use this file to discover all available pages before exploring further.
What is LSP?
The Language Server Protocol (LSP) is a standardized protocol that provides language-specific intelligence features:- Diagnostics: Real-time error and warning detection
- Type checking: Static analysis and type errors
- Linting: Code style and quality issues
- Semantic analysis: Language-specific code understanding
OpenCode’s LSP client implementation is based on the mcp-language-server project.
Supported features
OpenCode’s LSP integration currently exposes diagnostics to the AI assistant:Error detection
- Syntax errors
- Type errors
- Compilation errors
- Import/reference errors
Warnings
- Unused variables
- Deprecated APIs
- Potential bugs
- Code smells
Hints
- Optimization suggestions
- Style improvements
- Best practices
- Refactoring opportunities
Real-time feedback
- Instant analysis on file open
- Updates on file changes
- Persistent across session
- Multi-file awareness
While the LSP client supports the full protocol (completions, hover, go-to-definition, etc.), only diagnostics are currently exposed to the AI assistant.
Configuration
LSP servers are configured in.opencode.json under the lsp key:
Configuration fields
Whether this language server is disabled
Path to the language server executable
Command-line arguments to pass to the server (e.g.,
["--stdio"])Enable debug logging for LSP operations (top-level config)
Language-specific configuration
Go (gopls)
- Type checking
- Import errors
- Unused variables
- Build errors
- Module issues
TypeScript (typescript-language-server)
- Type errors
- Missing imports
- Unused code
- Strict mode violations
- TSConfig issues
OpenCode automatically opens
tsconfig.json and package.json to help TypeScript servers initialize properly.JavaScript (typescript-language-server)
jsconfig.json.
Python (pyright)
- Type checking (with type hints)
- Import resolution
- Undefined variables
- Syntax errors
Rust (rust-analyzer)
- Borrow checker errors
- Type mismatches
- Lifetime errors
- Cargo build issues
- Macro expansion
Java (jdtls)
C/C++ (clangd)
How LSP integration works
Server initialization
When OpenCode starts:
- Reads LSP configuration from
.opencode.json - Launches configured language servers
- Sends
initializerequest with workspace info - Waits for server to be ready
File operations
When AI tools interact with files:
textDocument/didOpensent when file is first accessedtextDocument/didChangesent when file is modifiedtextDocument/didClosesent when no longer needed
Diagnostic collection
Language servers send diagnostics:
textDocument/publishDiagnosticsreceived asynchronously- Diagnostics cached per file URI
- Available to AI via
diagnosticstool - Automatically included after file modifications
File lifecycle management
Automatic file opening
OpenCode intelligently manages file state:Persistent sessions
Files remain open across multiple operations:Smart initialization
For TypeScript/JavaScript projects, OpenCode:-
Opens configuration files first:
tsconfig.jsonpackage.jsonjsconfig.json
-
Opens sample source files to help server index:
- Finds up to 5
.ts/.tsx/.js/.jsxfiles - Skips
node_modulesand build directories - Accelerates initial diagnostics
- Finds up to 5
Server detection and optimization
OpenCode detects server types and optimizes accordingly:- TypeScript
- Go
- Rust
- Generic
Detected by: Command contains
typescript, vtsls, or tsserverOptimizations:- Opens key config files (tsconfig.json, package.json)
- Opens sample source files to help with indexing
- Uses document symbol requests for readiness checks
- Waits longer for initial diagnostics
Diagnostic format
Diagnostics are displayed in a structured format:Severity levels
Error
Error
Code will not compile or has serious issuesExamples:
- Syntax errors
- Type mismatches
- Undefined references
- Import failures
Warning
Warning
Potential issues or questionable codeExamples:
- Unused variables
- Deprecated APIs
- Type assertions
- Missing error handling
Info
Info
Informational messagesExamples:
- Documentation
- Suggestions
- Code metrics
Hint
Hint
Improvement suggestionsExamples:
- Simplifications
- Performance tips
- Style consistency
Diagnostic tags
Additional metadata:- Unnecessary: Code that can be removed (e.g., unused imports)
- Deprecated: Using deprecated APIs or features
AI tool integration
The AI assistant accesses diagnostics through thediagnostics tool:
Get file diagnostics
Get project diagnostics
Automatic inclusion
Diagnostics are automatically shown:- After view: If file has errors/warnings
- After write: Shows new diagnostics
- After edit: Validates changes
- After patch: Shows diagnostics for all modified files
Common workflows
Debugging errors
Type error resolution
Pre-commit validation
Troubleshooting
Server not starting
Server not starting
Check:
- Command path is correct:
which gopls - Server is installed and in PATH
- No conflicting servers running
- Enable debug logging:
"debugLSP": true - Check logs:
opencode -d
No diagnostics appearing
No diagnostics appearing
Verify:
- Server initialized successfully (check logs)
- File is in workspace directory
- File type matches language ID
- Server has finished indexing (may take time for large projects)
- Try closing and reopening file
Stale diagnostics
Stale diagnostics
Possible causes:
- File modified outside OpenCode
- Server hasn’t processed changes yet
- Cache not updated
- Wait for server to process (5-10 seconds)
- Use
diagnosticstool to refresh - Restart OpenCode if persistent
TypeScript server slow
TypeScript server slow
TypeScript can be slow on large projects:
- Initial indexing takes time
- Configure smaller
includein tsconfig.json - Exclude
node_modulesexplicitly - Use project references for monorepos
- Consider increasing system resources
Multiple servers for same language
Multiple servers for same language
If you have multiple configs for same language:
- Last configured server wins
- Disable unused servers:
"disabled": true - Use different language IDs if needed
Performance considerations
Lazy file opening
OpenCode opens files on-demand:
- Only when AI tools access them
- Reduces memory usage
- Faster startup
- Less server load
File closing
Files remain open until:
- Session ends
- Explicit close
- OpenCode shutdown
Diagnostic caching
Diagnostics are cached:
- Per-file URI
- Updated on publishDiagnostics
- Shared across tools
- Memory-efficient
Async updates
Diagnostics arrive asynchronously:
- Non-blocking operations
- Background processing
- Timeout after 5 seconds
- Graceful degradation
Limitations
- Diagnostics only: Other LSP features (completions, hover, etc.) not exposed to AI
- Single workspace: One workspace root per session
- File-based: Works with file:// URIs only
- No refactoring: Code actions not yet available
- Limited customization: Server-specific options not configurable
Future enhancements
Planned improvements:- Code actions: Enable AI to apply quick fixes
- Completions: Suggest completions to AI
- Hover information: Provide type info and docs
- Go to definition: Navigate code references
- Workspace symbols: Better code navigation
- Semantic tokens: Enhanced code understanding
- Server-specific configs: Per-server initialization options
Best practices
Install recommended servers
Use official language servers:
- They’re well-maintained
- Best diagnostic quality
- Regular updates
- Good documentation
Configure project properly
Ensure project config files exist:
- tsconfig.json for TypeScript
- go.mod for Go
- Cargo.toml for Rust
- Helps servers understand project
Monitor performance
Watch for slow servers:
- Enable debug logging temporarily
- Check initialization time
- Monitor memory usage
- Tune server settings
Use diagnostics proactively
Check regularly during development:
- Before commits
- After major changes
- When debugging
- During code review
Keep servers updated
Update regularly:
Debug systematically
When issues arise:
- Enable
debugLSP: true - Run
opencode -d - Check server logs
- Test server independently
- Review configuration
Debug mode
Enable detailed LSP logging:- Server initialization
- File open/close events
- Diagnostic publications
- Server responses
- Error messages
Debug logs are written to
~/.opencode/logs/ and shown in the logs page (Ctrl+L)Next steps
Diagnostics tool
Learn how to use the diagnostics tool
Configuration
Complete configuration reference
AI tools
Explore all available AI tools
LSP Specification
Official LSP documentation