Language Server Protocol (LSP) Support

Full LSP support with refactoring tools and code analysis

What is LSP?

The Language Server Protocol (LSP) is a protocol that provides language-specific features like autocomplete, go to definition, find all references, and more. LSP allows editors and IDEs to communicate with language servers to provide rich language features.

Oh My OpenCode provides full LSP support, including:

  • All standard OpenCode LSP configurations
  • Custom settings from opencode.json
  • Additional Oh My OpenCode-specific settings
  • Refactoring tools (rename, code actions)

LSP Features

Code Analysis

Full LSP analysis capabilities including type checking, error detection, and code quality analysis.

Refactoring Tools

Rename symbols, extract functions, and perform code actions with full LSP support.

Custom LSP Servers

Add your own LSP servers for any language or tool that supports LSP.

Priority Management

Configure server priorities when multiple servers handle the same file type.

Extension Mapping

Map LSP servers to specific file extensions for precise control.

Environment Configuration

Customize environment variables for each LSP server.

LSP Configuration

Add and configure LSP servers in your oh-my-opencode.json file:

Basic Configuration

{
  "lsp": {
    "typescript-language-server": {
      "command": ["typescript-language-server", "--stdio"],
      "extensions": [".ts", ".tsx"],
      "priority": 10
    }
  }
}

Configuration Options

Option Type Description
command Array<string> Array of command and arguments to start the LSP server. Required.
extensions Array<string> Array of file extensions this server should handle (e.g., [".ts", ".tsx"]).
priority number Priority number (higher = more priority) when multiple servers handle the same file. Default: 0.
env object Environment variables to pass to the server (e.g., {"NODE_ENV": "development"}).
initialization object Custom initialization options for the server (LSP initialization parameters).
disabled boolean Set to true to disable a server. Useful for disabling default servers.

Disabling Servers

{
  "lsp": {
    "pylsp": {
      "disabled": true
    }
  }
}

Configuration Examples

TypeScript/JavaScript

{
  "lsp": {
    "typescript-language-server": {
      "command": ["typescript-language-server", "--stdio"],
      "extensions": [".ts", ".tsx", ".js", ".jsx"],
      "priority": 10
    }
  }
}

Python

{
  "lsp": {
    "pylsp": {
      "command": ["pylsp"],
      "extensions": [".py"],
      "priority": 10,
      "env": {
        "PYTHONPATH": "${workspaceFolder}"
      }
    }
  }
}

Rust

{
  "lsp": {
    "rust-analyzer": {
      "command": ["rust-analyzer"],
      "extensions": [".rs"],
      "priority": 10
    }
  }
}

Multiple Servers

{
  "lsp": {
    "typescript-language-server": {
      "command": ["typescript-language-server", "--stdio"],
      "extensions": [".ts", ".tsx"],
      "priority": 10
    },
    "eslint": {
      "command": ["vscode-eslint-language-server", "--stdio"],
      "extensions": [".ts", ".tsx", ".js", ".jsx"],
      "priority": 5
    },
    "prettier": {
      "command": ["prettier", "--lsp"],
      "extensions": [".ts", ".tsx", ".js", ".jsx", ".json", ".md"],
      "priority": 1
    }
  }
}

With Custom Initialization

{
  "lsp": {
    "typescript-language-server": {
      "command": ["typescript-language-server", "--stdio"],
      "extensions": [".ts", ".tsx"],
      "priority": 10,
      "initialization": {
        "preferences": {
          "includePackageJsonAutoImports": "on"
        }
      }
    }
  }
}

OpenCode Integration

Oh My OpenCode supports all OpenCode LSP configurations and custom settings from opencode.json. This means:

  • All existing OpenCode LSP configurations work with Oh My OpenCode
  • Custom settings from opencode.json are respected
  • Oh My OpenCode-specific settings extend OpenCode functionality
  • Refactoring tools are available in addition to standard LSP features

Best Practices

  • Use appropriate priorities - Set higher priorities for primary language servers, lower for linters and formatters.
  • Configure extensions carefully - Only include extensions that the server actually handles.
  • Set environment variables - Configure environment variables for servers that need them (e.g., Python path).
  • Disable unused servers - Disable servers you don't use to improve performance.
  • Test server commands - Make sure server commands work in your environment before configuring.
  • Use project-specific config - Configure LSP servers per-project when needed.

Troubleshooting

Server Not Starting

  • Verify the command is correct and available in your PATH
  • Check that the server supports stdio mode
  • Review server logs for error messages

Server Not Responding

  • Check that file extensions are correctly configured
  • Verify server priority settings
  • Ensure server is not disabled

Performance Issues

  • Disable unused servers
  • Adjust server priorities
  • Check server resource usage

External Resources

Learn more about LSP and language servers: