LSPサーバー
LSP Servers
OpenCode は Language Server Protocol (LSP) サーバーと統合して、診断をエージェントへのフィードバックとして使用できます。
Built-in
OpenCode は一般的な言語用にいくつかの組み込み LSP サーバーを備えています:
| LSP Server | Extensions | Requirements |
|---|---|---|
| astro | .astro | Auto-installs for Astro projects |
| bash | .sh, .bash, .zsh, .ksh | Auto-installs bash-language-server |
| clangd | .c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++ | Auto-installs for C/C++ projects |
| csharp | .cs, .csx | .NET SDK installed |
| clojure-lsp | .clj, .cljs, .cljc, .edn | clojure-lsp command available |
| dart | .dart | dart command available |
| deno | .ts, .tsx, .js, .jsx, .mjs | deno command available (auto-detects deno.json/deno.jsonc) |
| elixir-ls | .ex, .exs | elixir command available |
| eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | eslint dependency in project |
| fsharp | .fs, .fsi, .fsx, .fsscript | .NET SDK installed |
| gleam | .gleam | gleam command available |
| gopls | .go | go command available |
| hls | .hs, .lhs | haskell-language-server-wrapper command available |
| jdtls | .java | Java SDK (version 21+) installed |
| julials | .jl | julia and LanguageServer.jl installed |
| kotlin-ls | .kt, .kts | Auto-installs for Kotlin projects |
| lua-ls | .lua | Auto-installs for Lua projects |
| nixd | .nix | nixd command available |
| ocaml-lsp | .ml, .mli | ocamllsp command available |
| oxlint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelte | oxlint dependency in project |
| php intelephense | .php | Auto-installs for PHP projects |
| prisma | .prisma | prisma command available |
| pyright | .py, .pyi | pyright dependency installed |
| razor | .razor, .cshtml | .NET SDK and VS Code C# extension installed |
| ruby-lsp (rubocop) | .rb, .rake, .gemspec, .ru | ruby and gem commands available |
| rust | .rs | rust-analyzer command available |
| sourcekit-lsp | .swift, .objc, .objcpp | swift installed (xcode on macOS) |
| svelte | .svelte | Auto-installs for Svelte projects |
| terraform | .tf, .tfvars | Auto-installs from GitHub releases |
| tinymist | .typ, .typc | Auto-installs from GitHub releases |
| typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | typescript dependency in project |
| vue | .vue | Auto-installs for Vue projects |
| yaml-ls | .yaml, .yml | Auto-installs Red Hat yaml-language-server |
| zls | .zig, .zon | zig command available |
LSP はデフォルトで無効です。有効にすると、上記のファイル拡張子のいずれかが検出され、要件が満たされたときにサーバーが起動します。
How It Works
LSP が有効で opencode がファイルを開くと:
- 有効なすべての LSP サーバーに対してファイル拡張子を確認します。
- まだ実行中でなければ、適切な LSP サーバーを起動します。
Best Practices
LSP は言語サーバーからの診断を提供することで、エージェントが問題を見つけて修正するのを助けます。これは一部のプロジェクトでは便利ですが、必ずしもネット.Positiveではありません。
言語サーバーは同期を失うことができ значительный メモリを使用し、バージョンまたプロジェクトによって異なり、エージェントのワークフローを遅くする可能性があります。多くのプロジェクトでは、エージェントが直接 lint、typecheck、または他の診断 CLI ツールを実行し、エラーがそのトレードオフなしエージェントループにフィードバックされる方が良いでしょう。これらのコマンドを AGENTS.md や skills などの指示ファイルにドキュメント化して、エージェントが何を実行するかを知るようにします。プロジェクトが追加の言語サーバーフィードバックの恩恵を受けるときに LSP を有効にします。
Configure
OpenCode Config の lsp セクションを通じて LSP サーバーを有効化し、カスタマイズできます。
すべての組み込み LSP サーバーを有効にするには、lsp を true に設定します。
{
"$schema": "https://opencode.ai/config.json",
"lsp": true
} オブジェクトを使用して、組み込みを有効に保ちながら、上書きまたはカスタムサーバーの設定を行います。
{
"$schema": "https://opencode.ai/config.json",
"lsp": {}
} 設定された各 LSP サーバーエントリは以下のをサポートします:
サーバーエントリには、サーバーを無効にする場合のみ command が必要です。
| Property | Type | Description |
|---|---|---|
disabled | boolean | Set this to true to disable the LSP server |
command | string[] | The command to start the LSP server |
extensions | string[] | File extensions this LSP server should handle |
env | object | Environment variables to set when starting server |
initialization | object | Initialization options to send to the LSP server |
いくつかの例を見てみましょう。
Environment variables
LSP サーバーを起動するときの環境変数を設定するには env プロパティを使用します:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"rust": {
"command": ["rust-analyzer"],
"env": {
"RUST_LOG": "debug"
}
}
}
} Initialization options
initialization プロパティを使用して LSP サーバーに初期化オプションを渡します。これらは LSP initialize リクエスト中に送信されるサーバー固有の設定です:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"custom-lsp": {
"command": ["custom-lsp-server", "--stdio"],
"extensions": [".custom"],
"initialization": {
"preferences": {
"importModuleSpecifierPreference": "relative"
}
}
}
}
} Disabling LSP servers
lsp が省略された場合、すべての LSP サーバーは無効です。他の構成後にすべての LSP サーバーを無効にするには、lsp を false に設定します:
{
"$schema": "https://opencode.ai/config.json",
"lsp": false
} 特定の LSP サーバーを無効にするには、disabled を true に設定します:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"typescript": {
"disabled": true
}
}
} Custom LSP servers
コマンドとファイル拡張子を指定してカスタム LSP サーバーを追加できます:
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"custom-lsp": {
"command": ["custom-lsp-server", "--stdio"],
"extensions": [".custom"]
}
}
} Additional Information
PHP Intelephense
PHP Intelephense はライセンスキーを通じてプレミアム機能を提供します。ライセンスキーを配置して提供できます(キーのみを):
- macOS/Linux:
$HOME/intelephense/license.txt - Windows:
%USERPROFILE%/intelephense/license.txt
ファイルには追加コンテンツなしでライセンスキーのみを含める必要があります。