한국어
문서
LSP 서버

LSP 서버

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

OpenCode는 Language Server Protocol (LSP)과 통합하여 LLM이 코드베이스와 상호작용하도록 돕습니다. 진단 정보를 사용하여 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.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 (버전 21+) 설치됨
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 의존성 설치됨
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 의존성
vue.vueVue 프로젝트에 자동 설치
yaml-ls.yaml, .ymlRed Hat yaml-language-server 자동 설치
zls.zig, .zonzig 명령어 사용 가능

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

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

작동 방식

opencode가 파일을 열면:

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

설정

opencode 설정의 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 서버 문서를 확인하세요.

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/licence.txt
  • Windows: %USERPROFILE%/intelephense/licence.txt

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