Skip to main content

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

tip

Running many LSP servers can increase memory usage — disable languages you do not use.

opencode includes built-in support for the following language servers:

LanguageServerNotes
TypeScript / JavaScripttypescript-language-serverFull TS/JS support
Pythonpyright or pylspConfigurable via settings
Rustrust-analyzerRequires Rust toolchain
GogoplsStandard Go LSP
Javaeclipse-jdtlsRequires JDK
C / C++clangdRequires clang tools
RubysolargraphRequires gem installation
PHPintelephensePHP language server
HTML / CSS / JSONvscode-langservers-extractedBuilt-in web support
YAMLyaml-language-serverYAML validation
MarkdownmarksmanMarkdown intelligence
Lualua-language-serverLua development
Shellbash-language-serverShell 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

note

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:

OperationDescription
goToDefinitionNavigate to the definition of a symbol
findReferencesFind all references to a symbol
hoverShow hover information for a symbol
documentSymbolList all symbols in the current document
workspaceSymbolSearch for symbols across the workspace
goToImplementationNavigate to implementations of an interface or type
prepareCallHierarchyPrepare call hierarchy data for a symbol
incomingCallsShow calls that invoke the given symbol
outgoingCallsShow 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=true environment 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
}