한국어
문서
LSP 서버

LSP 서버

OpenCode는 LSP 서버와 통합됩니다.

OpenCode는 Language Server Protocol(LSP)과 통합하여 LLM이 코드베이스와 상호작용하도록 도울 수 있습니다. 진단(diagnostics)을 사용하여 LLM에 피드백을 제공합니다.


내장

OpenCode에는 인기 언어를 위한 여러 내장 LSP 서버가 함께 제공됩니다:

LSP 서버확장자요구사항
astro.astroAstro 프로젝트에 자동 설치
bash.sh, .bash, .zsh, .kshbash-language-server 자동 설치
clangd.c, .cpp, .cc, .cxx, .c++, .h, .hpp, .hh, .hxx, .h++C/C++ 프로젝트에 자동 설치
csharp.cs, .csx.NET SDK 설치됨
clojure-lsp.clj, .cljs, .cljc, .ednclojure-lsp 명령 사용 가능
dart.dartdart 명령 사용 가능
deno.ts, .tsx, .js, .jsx, .mjsdeno 명령 사용 가능(deno.json/deno.jsonc 자동 감지)
elixir-ls.ex, .exselixir 명령 사용 가능
eslint.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue프로젝트에 eslint 의존성
fsharp.fs, .fsi, .fsx, .fsscript.NET SDK 설치됨
gleam.gleamgleam 명령 사용 가능
gopls.gogo 명령 사용 가능
hls.hs, .lhshaskell-language-server-wrapper 명령 사용 가능
jdtls.javaJava SDK (version 21+) 설치됨
julials.jljuliaLanguageServer.jl 설치됨
kotlin-ls.kt, .ktsKotlin 프로젝트에 자동 설치
lua-ls.luaLua 프로젝트에 자동 설치
nixd.nixnixd 명령 사용 가능
ocaml-lsp.ml, .mliocamllsp 명령 사용 가능
oxlint.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelte프로젝트에 oxlint 의존성
php intelephense.phpPHP 프로젝트에 자동 설치
prisma.prismaprisma 명령 사용 가능
pyright.py, .pyipyright 의존성 설치됨
razor.razor, .cshtml.NET SDK 및 VS Code C# 확장 설치됨
ruby-lsp (rubocop).rb, .rake, .gemspec, .rurubygem 명령 사용 가능
rust.rsrust-analyzer 명령 사용 가능
sourcekit-lsp.swift, .objc, .objcppswift 설치됨(macOS에서는 xcode)
svelte.svelteSvelte 프로젝트에 자동 설치
terraform.tf, .tfvarsGitHub 릴리스에서 자동 설치
tinymist.typ, .typcGitHub 릴리스에서 자동 설치
typescript.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts프로젝트에 typescript 의존성
vue.vueVue 프로젝트에 자동 설치
yaml-ls.yaml, .ymlRed Hat yaml-language-server 자동 설치
zls.zig, .zonzig 명령 사용 가능

LSP가 활성화되면, 위 파일 확장자 중 하나가 감지되고 요구사항이 충족될 때 서버가 시작됩니다.

Note: OPENCODE_DISABLE_LSP_DOWNLOAD 환경 변수를 true로 설정하여 자동 LSP 서버 다운로드를 비활성화할 수 있습니다.


작동 방식

LSP가 활성화되고 opencode가 파일을 열면, 다음을 수행합니다:

  1. 모든 활성화된 LSP 서버에 대해 파일 확장자를 확인합니다.
  2. 아직 실행 중이 아니면 적절한 LSP 서버를 시작합니다.

설정

opencode 설정의 lsp 섹션을 통해 LSP 서버를 활성화하고 커스터마이즈할 수 있습니다.

모든 내장 LSP 서버를 활성화하려면, lsptrue로 설정하세요.

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

내장 서버를 활성화 상태로 유지하면서 재정의나 커스텀 서버를 설정하려면 객체를 사용하세요.

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

설정된 각 LSP 서버 항목은 다음을 지원합니다:

서버 항목은 서버를 비활성화하기만 하는 경우가 아니라면 command가 필요합니다.

속성타입설명
disabledbooleanLSP 서버를 비활성화하려면 true로 설정
commandstring[]LSP 서버를 시작하는 명령
extensionsstring[]이 LSP 서버가 처리해야 할 파일 확장자
envobject서버 시작 시 설정할 환경 변수
initializationobjectLSP 서버에 보낼 초기화 옵션

몇 가지 예시를 살펴보겠습니다.


환경 변수

env 속성을 사용하여 LSP 서버 시작 시 환경 변수를 설정합니다:

opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {
    "rust": {
      "command": ["rust-analyzer"],
      "env": {
        "RUST_LOG": "debug"
      }
    }
  }
}

초기화 옵션

initialization 속성을 사용하여 LSP 서버에 초기화 옵션을 전달합니다. 이들은 LSP initialize 요청 중에 보내지는 서버별 설정입니다:

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

Note: 초기화 옵션은 LSP 서버에 따라 다릅니다. 사용 가능한 옵션은 LSP 서버의 문서를 확인하세요.


LSP 서버 비활성화

lsp를 생략하면 모든 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

이 파일에는 추가 내용 없이 라이선스 키만 포함되어야 합니다.