콘텐츠로 이동

LSP 서버

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

OpenCode는 Language Server Protocol(LSP)과 통합되어 LLM이 코드베이스와 상호작용하도록 돕습니다. 진단 정보를 활용해 LLM에 피드백을 제공합니다.


기본 제공 (Built-in)

OpenCode는 널리 사용되는 언어를 위해 여러 built-in 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.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 dependency 존재
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 dependency 존재
php intelephense.phpPHP 프로젝트에서 자동 설치
prisma.prismaprisma 명령 사용 가능
pyright.py, .pyipyright dependency 설치됨
ruby-lsp (rubocop).rb, .rake, .gemspec, .rurubygem 명령 사용 가능
rust.rsrust-analyzer 명령 사용 가능
sourcekit-lsp.swift, .objc, .objcppswift 설치됨 (macOS에서는 xcode)
svelte.svelteSvelte 프로젝트에서 자동 설치
terraform.tf, .tfvarsGitHub releases에서 자동 설치
tinymist.typ, .typcGitHub releases에서 자동 설치
typescript.ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts프로젝트에 typescript dependency 존재
vue.vueVue 프로젝트에서 자동 설치
yaml-ls.yaml, .ymlRed Hat yaml-language-server 자동 설치
zls.zig, .zonzig 명령 사용 가능

위 확장자 중 하나가 감지되고 요구 사항이 충족되면 LSP 서버가 자동으로 활성화됩니다.


작동 방식

OpenCode가 파일을 열면 다음과 같이 동작합니다.

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

구성

OpenCode config의 lsp 섹션에서 LSP 서버를 사용자 정의할 수 있습니다.

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

각 LSP 서버는 다음 속성을 지원합니다.

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

예시를 살펴보겠습니다.


환경 변수

env 속성을 사용하면 LSP 서버 시작 시 환경 변수를 설정할 수 있습니다.

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

파일에는 추가 내용 없이 라이선스 키만 포함하는 것이 좋습니다.