LSP 伺服器
Dropstone 與您的 LSP 伺服器整合。
Dropstone 可以與您的語言伺服器協議 (LSP) 整合,幫助 LLM 與您的程式碼庫互動。它使用診斷來向 LLM 提供回饋。
內建
Dropstone 為熱門語言提供了多個內建 LSP 伺服器:
| LSP 伺服器 | 副檔名 | 需求 |
|---|---|---|
| astro | .astro | 為 Astro 專案自動安裝 |
| bash | .sh, .bash, .zsh, .ksh | 自動安裝 bash-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, .edn | clojure-lsp 命令可用 |
| dart | .dart | dart 命令可用 |
| deno | .ts, .tsx, .js, .jsx, .mjs | deno 命令可用(自動偵測 deno.json/deno.jsonc) |
| elixir-ls | .ex, .exs | elixir 命令可用 |
| eslint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue | 專案中有 eslint 依賴 |
| fsharp | .fs, .fsi, .fsx, .fsscript | 已安裝 .NET SDK |
| gleam | .gleam | gleam 命令可用 |
| gopls | .go | go 命令可用 |
| hls | .hs, .lhs | haskell-language-server-wrapper 命令可用 |
| jdtls | .java | 已安裝 Java SDK (版本 21+) |
| julials | .jl | 已安裝 julia 和 LanguageServer.jl |
| kotlin-ls | .kt, .kts | 為 Kotlin 專案自動安裝 |
| lua-ls | .lua | 為 Lua 專案自動安裝 |
| nixd | .nix | nixd 命令可用 |
| ocaml-lsp | .ml, .mli | ocamllsp 命令可用 |
| oxlint | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts, .vue, .astro, .svelte | 專案中有 oxlint 依賴 |
| php intelephense | .php | 為 PHP 專案自動安裝 |
| prisma | .prisma | prisma 命令可用 |
| pyright | .py, .pyi | 已安裝 pyright 依賴 |
| razor | .razor, .cshtml | 已安裝 .NET SDK 和 VS Code C# 擴充功能 |
| ruby-lsp (rubocop) | .rb, .rake, .gemspec, .ru | ruby 和 gem 命令可用 |
| rust | .rs | rust-analyzer 命令可用 |
| sourcekit-lsp | .swift, .objc, .objcpp | 已安裝 swift(macOS 上為 xcode) |
| svelte | .svelte | 為 Svelte 專案自動安裝 |
| terraform | .tf, .tfvars | 從 GitHub 版本自動安裝 |
| tinymist | .typ, .typc | 從 GitHub 版本自動安裝 |
| typescript | .ts, .tsx, .js, .jsx, .mjs, .cjs, .mts, .cts | 專案中有 typescript 依賴 |
| vue | .vue | 為 Vue 專案自動安裝 |
| yaml-ls | .yaml, .yml | 自動安裝 Red Hat yaml-language-server |
| zls | .zig, .zon | zig 命令可用 |
啟用 LSP 時,當偵測到上述副檔名之一且符合需求時,伺服器就會啟動。
運作方式
啟用 LSP 且 dropstone 開啟檔案時,它會:
- 根據所有已啟用的 LSP 伺服器檢查檔案副檔名。
- 如果尚未執行,啟動適當的 LSP 伺服器。
設定
您可以透過 dropstone 設定中的 lsp 部分來啟用和自訂 LSP 伺服器。
若要啟用所有內建 LSP 伺服器,請將 lsp 設定為 true。
{
"$schema": "https://dropstone.io/schema/config.json",
"lsp": true
}
使用物件來保持內建伺服器啟用,同時設定覆蓋或自訂伺服器。
{
"$schema": "https://dropstone.io/schema/config.json",
"lsp": {}
}
每個已設定的 LSP 伺服器項目支援以下內容:
伺服器項目需要 command,除非它們只是停用伺服器。
| 屬性 | 類型 | 說明 |
|---|---|---|
disabled | boolean | 設定為 true 以停用 LSP 伺服器 |
command | string[] | 啟動 LSP 伺服器的命令 |
extensions | string[] | 此 LSP 伺服器應處理的檔案副檔名 |
env | object | 啟動伺服器時要設定的環境變數 |
initialization | object | 要傳送至 LSP 伺服器的初始化選項 |
讓我們看一些範例。
環境變數
使用 env 屬性在啟動 LSP 伺服器時設定環境變數:
{
"$schema": "https://dropstone.io/schema/config.json",
"lsp": {
"rust": {
"command": ["rust-analyzer"],
"env": {
"RUST_LOG": "debug"
}
}
}
}
初始化選項
使用 initialization 屬性將初始化選項傳遞至 LSP 伺服器。這些是在 LSP initialize 請求期間傳送的伺服器特定設定:
{
"$schema": "https://dropstone.io/schema/config.json",
"lsp": {
"custom-lsp": {
"command": ["custom-lsp-server", "--stdio"],
"extensions": [".custom"],
"initialization": {
"preferences": {
"importModuleSpecifierPreference": "relative"
}
}
}
}
}
Note:
初始化選項因 LSP 伺服器而異。檢查您的 LSP 伺服器文件以了解可用的選項。
停用 LSP 伺服器
如果省略 lsp,所有 LSP 伺服器都會被停用。若要在另一個設定啟用它們後停用所有 LSP 伺服器,請將 lsp 設定為 false:
{
"$schema": "https://dropstone.io/schema/config.json",
"lsp": false
}
若要停用特定的 LSP 伺服器,請將 disabled 設定為 true:
{
"$schema": "https://dropstone.io/schema/config.json",
"lsp": {
"typescript": {
"disabled": true
}
}
}
自訂 LSP 伺服器
您可以透過指定命令和檔案副檔名來新增自訂 LSP 伺服器:
{
"$schema": "https://dropstone.io/schema/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
該檔案應僅包含授權金鑰,不含任何其他內容。
Ctrl+I