コンテンツにスキップ

LSPサーバー

OpenCode は LSP サーバーと統合します。

OpenCode は言語サーバー プロトコル (LSP) と統合して、LLM がコードベースと対話できるようにします。診断を使用して LLM にフィードバックを提供します。


内蔵

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.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
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
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 サーバーは自動的に有効になります。


仕組み

opencode がファイルを開くと、次のようになります。

  1. 有効なすべての LSP サーバーに対してファイル拡張子をチェックします。
  2. 適切な LSP サーバーがまだ実行されていない場合は開始します。

設定する

Opencode 構成の lsp セクションを通じて LSP サーバーをカスタマイズできます。

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

各 LSP サーバーは以下をサポートします。

プロパティタイプ説明
disabledブール値LSP サーバーを無効にするには、これを true に設定します。
command文字列[]LSP サーバーを起動するコマンド
extensions文字列[]この LSP サーバーが処理するファイル拡張子
envオブジェクトサーバーの起動時に設定する環境変数
initializationオブジェクトLSP サーバーに送信する初期化オプション

いくつかの例を見てみましょう。


環境変数

LSP サーバーの起動時に env プロパティを使用して環境変数を設定します。

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"rust": {
"env": {
"RUST_LOG": "debug"
}
}
}
}

初期化オプション

initialization プロパティを使用して、初期化オプションを LSP サーバーに渡します。これらは、LSP initialize リクエスト中に送信されるサーバー固有の設定です。

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"typescript": {
"initialization": {
"preferences": {
"importModuleSpecifierPreference": "relative"
}
}
}
}
}

LSPサーバーの無効化

すべて LSP サーバーをグローバルに無効にするには、lspfalse に設定します。

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

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

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

カスタムLSPサーバー

コマンドとファイル拡張子を指定して、カスタム LSP サーバーを追加できます。

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"lsp": {
"custom-lsp": {
"command": ["custom-lsp-server", "--stdio"],
"extensions": [".custom"]
}
}
}

追加情報

PHP Intelephense

PHP Intelephense は、ライセンス キーを通じてプレミアム機能を提供します。ライセンス キーを指定するには、次の場所にあるテキスト ファイルにキー (のみ) を配置します。

  • macOS/Linux の場合: $HOME/intelephense/license.txt
  • Windows の場合: %USERPROFILE%/intelephense/license.txt

ファイルにはライセンス キーのみが含まれており、追加のコンテンツは含まれていません。