コンテンツにスキップ

LSPサーバー

LSP Servers

OpenCode は Language Server Protocol (LSP) サーバーと統合して、診断をエージェントへのフィードバックとして使用できます。


Built-in

OpenCode は一般的な言語用にいくつかの組み込み LSP サーバーを備えています:

LSP ServerExtensionsRequirements
astro.astroAuto-installs for Astro projects
bash.sh, .bash, .zsh, .kshAuto-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, .ednclojure-lsp command available
dart.dartdart command available
deno.ts, .tsx, .js, .jsx, .mjsdeno command available (auto-detects deno.json/deno.jsonc)
elixir-ls.ex, .exselixir command available
eslint.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vueeslint dependency in project
fsharp.fs, .fsi, .fsx, .fsscript.NET SDK installed
gleam.gleamgleam command available
gopls.gogo command available
hls.hs, .lhshaskell-language-server-wrapper command available
jdtls.javaJava SDK (version 21+) installed
julials.jljulia and LanguageServer.jl installed
kotlin-ls.kt, .ktsAuto-installs for Kotlin projects
lua-ls.luaAuto-installs for Lua projects
nixd.nixnixd command available
ocaml-lsp.ml, .mliocamllsp command available
oxlint.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelteoxlint dependency in project
php intelephense.phpAuto-installs for PHP projects
prisma.prismaprisma command available
pyright.py, .pyipyright dependency installed
razor.razor, .cshtml.NET SDK and VS Code C# extension installed
ruby-lsp (rubocop).rb, .rake, .gemspec, .ruruby and gem commands available
rust.rsrust-analyzer command available
sourcekit-lsp.swift, .objc, .objcppswift installed (xcode on macOS)
svelte.svelteAuto-installs for Svelte projects
terraform.tf, .tfvarsAuto-installs from GitHub releases
tinymist.typ, .typcAuto-installs from GitHub releases
typescript.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .ctstypescript dependency in project
vue.vueAuto-installs for Vue projects
yaml-ls.yaml, .ymlAuto-installs Red Hat yaml-language-server
zls.zig, .zonzig command available

LSP はデフォルトで無効です。有効にすると、上記のファイル拡張子のいずれかが検出され、要件が満たされたときにサーバーが起動します。


How It Works

LSP が有効で opencode がファイルを開くと:

  1. 有効なすべての LSP サーバーに対してファイル拡張子を確認します。
  2. まだ実行中でなければ、適切な LSP サーバーを起動します。

Best Practices

LSP は言語サーバーからの診断を提供することで、エージェントが問題を見つけて修正するのを助けます。これは一部のプロジェクトでは便利ですが、必ずしもネット.Positiveではありません。

言語サーバーは同期を失うことができ значительный メモリを使用し、バージョンまたプロジェクトによって異なり、エージェントのワークフローを遅くする可能性があります。多くのプロジェクトでは、エージェントが直接 lint、typecheck、または他の診断 CLI ツールを実行し、エラーがそのトレードオフなしエージェントループにフィードバックされる方が良いでしょう。これらのコマンドを AGENTS.md や skills などの指示ファイルにドキュメント化して、エージェントが何を実行するかを知るようにします。プロジェクトが追加の言語サーバーフィードバックの恩恵を受けるときに LSP を有効にします。


Configure

OpenCode Configlsp セクションを通じて LSP サーバーを有効化し、カスタマイズできます。

すべての組み込み LSP サーバーを有効にするには、lsptrue に設定します。

{
  "$schema": "https://opencode.ai/config.json",
  "lsp": true
}

オブジェクトを使用して、組み込みを有効に保ちながら、上書きまたはカスタムサーバーの設定を行います。

{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {}
}

設定された各 LSP サーバーエントリは以下のをサポートします:

サーバーエントリには、サーバーを無効にする場合のみ command が必要です。

PropertyTypeDescription
disabledbooleanSet this to true to disable the LSP server
commandstring[]The command to start the LSP server
extensionsstring[]File extensions this LSP server should handle
envobjectEnvironment variables to set when starting server
initializationobjectInitialization 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 サーバーを無効にするには、lspfalse に設定します:

{
  "$schema": "https://opencode.ai/config.json",
  "lsp": false
}

特定の LSP サーバーを無効にするには、disabledtrue に設定します:

{
  "$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

ファイルには追加コンテンツなしでライセンスキーのみを含める必要があります。