install-lsp

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Install LSP for Claude Code

为Claude Code安装LSP

Enable Language Server Protocol integration to give Claude Code IDE-like code intelligence: go-to-definition, find-references, rename-symbol, and real-time diagnostics.
启用语言服务器协议(LSP)集成,为Claude Code赋予类IDE的代码智能能力:跳转到定义、查找引用、重命名符号和实时诊断。

Why LSP?

为什么选择LSP?

LSP provides semantic code understanding instead of text-based grep searches:
  • 50ms to find function call sites with LSP vs 45 seconds with text search
  • Exact symbol locations with line/column numbers
  • Cross-file navigation and refactoring support
LSP提供语义化的代码理解,而非基于文本的grep搜索:
  • 使用LSP查找函数调用位置仅需50毫秒,而文本搜索需要45秒
  • 带行号/列号的精确符号位置
  • 跨文件导航和重构支持

Setup Options

设置选项

Option 1: Native LSP Tool (Recommended)

选项1:原生LSP工具(推荐)

Claude Code has built-in LSP support that requires activation.
Enable permanently (add to
~/.zshrc
or
~/.bashrc
):
bash
export ENABLE_LSP_TOOL=1
Install language plugins from the community marketplace:
bash
undefined
Claude Code内置了LSP支持,需要激活后使用。
永久启用(添加到
~/.zshrc
~/.bashrc
):
bash
export ENABLE_LSP_TOOL=1
从社区插件市场安装语言插件
bash
undefined

Add the LSP plugin marketplace

添加LSP插件市场

/plugin marketplace add boostvolt/claude-code-lsps
/plugin marketplace add boostvolt/claude-code-lsps

Install language-specific plugins

安装特定语言的插件

/plugin install pyright@claude-code-lsps # Python /plugin install vtsls@claude-code-lsps # TypeScript/JavaScript /plugin install gopls@claude-code-lsps # Go /plugin install rust-analyzer@claude-code-lsps # Rust /plugin install clangd@claude-code-lsps # C/C++ /plugin install jdtls@claude-code-lsps # Java /plugin install omnisharp@claude-code-lsps # C# /plugin install intelephense@claude-code-lsps # PHP /plugin install kotlin-language-server@claude-code-lsps # Kotlin /plugin install solargraph@claude-code-lsps # Ruby /plugin install vscode-html-css@claude-code-lsps # HTML/CSS
undefined
/plugin install pyright@claude-code-lsps # Python /plugin install vtsls@claude-code-lsps # TypeScript/JavaScript /plugin install gopls@claude-code-lsps # Go /plugin install rust-analyzer@claude-code-lsps # Rust /plugin install clangd@claude-code-lsps # C/C++ /plugin install jdtls@claude-code-lsps # Java /plugin install omnisharp@claude-code-lsps # C# /plugin install intelephense@claude-code-lsps # PHP /plugin install kotlin-language-server@claude-code-lsps # Kotlin /plugin install solargraph@claude-code-lsps # Ruby /plugin install vscode-html-css@claude-code-lsps # HTML/CSS
undefined

Option 2: cclsp MCP Server

选项2:cclsp MCP服务器

Community MCP server with interactive setup wizard.
Automated setup:
bash
npx cclsp@latest setup          # Project-level config
npx cclsp@latest setup --user   # User-wide config
The wizard:
  1. Scans project files to detect languages
  2. Pre-selects appropriate LSP servers
  3. Shows installation instructions for each server
  4. Optionally auto-installs LSP binaries
  5. Configures MCP integration
社区版MCP服务器,带交互式设置向导。
自动化设置
bash
npx cclsp@latest setup          # 项目级配置
npx cclsp@latest setup --user   # 用户级全局配置
设置向导会:
  1. 扫描项目文件以检测语言类型
  2. 预选择合适的LSP服务器
  3. 显示每个服务器的安装说明
  4. 可选自动安装LSP二进制文件
  5. 配置MCP集成

LSP Server Requirements by Language

各语言对应的LSP服务器要求

LanguageBinaryInstallation
Pythonpyright
pip install pyright
or
npm i -g pyright
TypeScript/JSvtsls
npm i -g @vtsls/language-server typescript
Gogopls
go install golang.org/x/tools/gopls@latest
Rustrust-analyzer
rustup component add rust-analyzer
C/C++clangd
brew install llvm
or
xcode-select --install
Javajdtls
brew install jdtls
(requires Java 21+)
C#omnisharp
brew install omnisharp/omnisharp-roslyn/omnisharp-mono
PHPintelephense
npm i -g intelephense
Kotlinkotlin-language-server
brew install kotlin-language-server
Rubysolargraph
gem install solargraph
HTML/CSSvscode-langservers
npm i -g vscode-langservers-extracted
语言二进制文件安装方式
Pythonpyright
pip install pyright
npm i -g pyright
TypeScript/JSvtsls
npm i -g @vtsls/language-server typescript
Gogopls
go install golang.org/x/tools/gopls@latest
Rustrust-analyzer
rustup component add rust-analyzer
C/C++clangd
brew install llvm
xcode-select --install
Javajdtls
brew install jdtls
(需要Java 21+)
C#omnisharp
brew install omnisharp/omnisharp-roslyn/omnisharp-mono
PHPintelephense
npm i -g intelephense
Kotlinkotlin-language-server
brew install kotlin-language-server
Rubysolargraph
gem install solargraph
HTML/CSSvscode-langservers
npm i -g vscode-langservers-extracted

cclsp Configuration File

cclsp配置文件

Location:
.claude/cclsp.json
(project) or
~/.config/claude/cclsp.json
(global)
json
{
  "servers": [
    {
      "extensions": ["py", "pyi"],
      "command": ["pyright-langserver", "--stdio"],
      "rootDir": ".",
      "restartInterval": 30
    },
    {
      "extensions": ["ts", "tsx", "js", "jsx"],
      "command": ["typescript-language-server", "--stdio"],
      "rootDir": "."
    }
  ]
}
位置:
.claude/cclsp.json
(项目级)或
~/.config/claude/cclsp.json
(全局)
json
{
  "servers": [
    {
      "extensions": ["py", "pyi"],
      "command": ["pyright-langserver", "--stdio"],
      "rootDir": ".",
      "restartInterval": 30
    },
    {
      "extensions": ["ts", "tsx", "js", "jsx"],
      "command": ["typescript-language-server", "--stdio"],
      "rootDir": "."
    }
  ]
}

Available LSP Tools

可用的LSP工具

After setup, Claude Code gains these capabilities:
ToolDescription
find_definition
Navigate to symbol definition
find_references
Find all usages of a symbol
rename_symbol
Rename symbol across all files
get_diagnostics
Get type errors and warnings
restart_server
Restart the language server
设置完成后,Claude Code将获得以下功能:
工具描述
find_definition
导航到符号定义
find_references
查找符号的所有引用
rename_symbol
跨所有文件重命名符号
get_diagnostics
获取类型错误和警告
restart_server
重启语言服务器

Troubleshooting

故障排查

"No LSP server available for file type"

"当前文件类型无可用LSP服务器"

bash
undefined
bash
undefined

Verify plugin is installed

验证插件是否已安装

/plugin
/plugin

Reinstall if needed

如有需要重新安装

/plugin uninstall pyright@claude-code-lsps /plugin install pyright@claude-code-lsps
undefined
/plugin uninstall pyright@claude-code-lsps /plugin install pyright@claude-code-lsps
undefined

"Executable not found in $PATH"

"$PATH中未找到可执行文件"

bash
undefined
bash
undefined

Check binary exists

检查二进制文件是否存在

which pyright which gopls
which pyright which gopls

For Go, ensure GOPATH/bin is in PATH

对于Go语言,确保GOPATH/bin在PATH中

export PATH=$PATH:$(go env GOPATH)/bin
undefined
export PATH=$PATH:$(go env GOPATH)/bin
undefined

Plugin installed but inactive

插件已安装但未激活

bash
undefined
bash
undefined

Clear cache and reinstall

清除缓存并重新安装

rm -rf ~/.claude/plugins/cache /plugin install pyright@claude-code-lsps
undefined
rm -rf ~/.claude/plugins/cache /plugin install pyright@claude-code-lsps
undefined

Windows Users

Windows用户

Use
cmd /c
wrapper for cclsp:
json
{
  "servers": [{
    "extensions": ["py"],
    "command": ["cmd", "/c", "pyright-langserver", "--stdio"]
  }]
}
为cclsp使用
cmd /c
包装器:
json
{
  "servers": [{
    "extensions": ["py"],
    "command": ["cmd", "/c", "pyright-langserver", "--stdio"]
  }]
}

Verification

验证

After setup, test by asking Claude Code to:
  • "Go to definition of
    functionName
    "
  • "Find all references to
    ClassName
    "
  • "Show diagnostics for this file"
A working setup provides exact file:line locations instead of grep-based text search results.
设置完成后,可通过让Claude Code执行以下操作进行测试:
  • "跳转到
    functionName
    的定义"
  • "查找
    ClassName
    的所有引用"
  • "显示当前文件的诊断信息"
配置成功的话,会返回精确的 文件:行号 位置,而非基于grep的文本搜索结果。

Best Practice

最佳实践

Combine LSP with traditional search:
  • Use LSP for: go-to-definition, diagnostics, rename
  • Use Grep for: find all usages, text patterns, comments
LSP provides precision; Grep provides coverage.
将LSP与传统搜索结合使用:
  • 使用LSP 实现:跳转到定义、诊断、重命名
  • 使用Grep 实现:查找所有引用、文本模式、注释
LSP提供精度,Grep提供覆盖范围。

Execution Instructions

执行说明

When the user runs this command:
  1. Determine approach from arguments:
    • native
      - Use built-in LSP tool with plugins
    • cclsp
      - Use cclsp MCP server
    • No argument - Ask user which approach they prefer
  2. For native approach:
    • Check if
      ENABLE_LSP_TOOL
      is already set
    • Add marketplace if not present
    • Install requested language plugin(s)
    • Verify with
      /plugin
      command
  3. For cclsp approach:
    • Run
      npx cclsp@latest setup
      interactively
    • Guide user through language server installation
    • Verify MCP server is added with
      /mcp
  4. Inform user to restart Claude Code after installation
当用户运行此命令时:
  1. 根据参数确定方案
    • native
      - 使用带插件的原生LSP工具
    • cclsp
      - 使用cclsp MCP服务器
    • 无参数 - 询问用户偏好哪种方案
  2. 对于原生方案
    • 检查
      ENABLE_LSP_TOOL
      是否已设置
    • 若未添加则添加插件市场
    • 安装所需的语言插件
    • 使用
      /plugin
      命令验证
  3. 对于cclsp方案
    • 交互式运行
      npx cclsp@latest setup
    • 引导用户完成语言服务器的安装
    • 使用
      /mcp
      命令验证MCP服务器已添加
  4. 告知用户 安装完成后重启Claude Code

Sources

参考来源