install-lsp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseInstall 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 or ):
~/.zshrc~/.bashrcbash
export ENABLE_LSP_TOOL=1Install language plugins from the community marketplace:
bash
undefinedClaude Code内置了LSP支持,需要激活后使用。
永久启用(添加到或):
~/.zshrc~/.bashrcbash
export ENABLE_LSP_TOOL=1从社区插件市场安装语言插件:
bash
undefinedAdd 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
undefinedOption 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 configThe wizard:
- Scans project files to detect languages
- Pre-selects appropriate LSP servers
- Shows installation instructions for each server
- Optionally auto-installs LSP binaries
- Configures MCP integration
社区版MCP服务器,带交互式设置向导。
自动化设置:
bash
npx cclsp@latest setup # 项目级配置
npx cclsp@latest setup --user # 用户级全局配置设置向导会:
- 扫描项目文件以检测语言类型
- 预选择合适的LSP服务器
- 显示每个服务器的安装说明
- 可选自动安装LSP二进制文件
- 配置MCP集成
LSP Server Requirements by Language
各语言对应的LSP服务器要求
| Language | Binary | Installation |
|---|---|---|
| Python | pyright | |
| TypeScript/JS | vtsls | |
| Go | gopls | |
| Rust | rust-analyzer | |
| C/C++ | clangd | |
| Java | jdtls | |
| C# | omnisharp | |
| PHP | intelephense | |
| Kotlin | kotlin-language-server | |
| Ruby | solargraph | |
| HTML/CSS | vscode-langservers | |
| 语言 | 二进制文件 | 安装方式 |
|---|---|---|
| Python | pyright | |
| TypeScript/JS | vtsls | |
| Go | gopls | |
| Rust | rust-analyzer | |
| C/C++ | clangd | |
| Java | jdtls | |
| C# | omnisharp | |
| PHP | intelephense | |
| Kotlin | kotlin-language-server | |
| Ruby | solargraph | |
| HTML/CSS | vscode-langservers | |
cclsp Configuration File
cclsp配置文件
Location: (project) or (global)
.claude/cclsp.json~/.config/claude/cclsp.jsonjson
{
"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.jsonjson
{
"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:
| Tool | Description |
|---|---|
| Navigate to symbol definition |
| Find all usages of a symbol |
| Rename symbol across all files |
| Get type errors and warnings |
| Restart the language server |
设置完成后,Claude Code将获得以下功能:
| 工具 | 描述 |
|---|---|
| 导航到符号定义 |
| 查找符号的所有引用 |
| 跨所有文件重命名符号 |
| 获取类型错误和警告 |
| 重启语言服务器 |
Troubleshooting
故障排查
"No LSP server available for file type"
"当前文件类型无可用LSP服务器"
bash
undefinedbash
undefinedVerify 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
undefinedbash
undefinedCheck 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
undefinedexport PATH=$PATH:$(go env GOPATH)/bin
undefinedPlugin installed but inactive
插件已安装但未激活
bash
undefinedbash
undefinedClear cache and reinstall
清除缓存并重新安装
rm -rf ~/.claude/plugins/cache
/plugin install pyright@claude-code-lsps
undefinedrm -rf ~/.claude/plugins/cache
/plugin install pyright@claude-code-lsps
undefinedWindows Users
Windows用户
Use wrapper for cclsp:
cmd /cjson
{
"servers": [{
"extensions": ["py"],
"command": ["cmd", "/c", "pyright-langserver", "--stdio"]
}]
}为cclsp使用包装器:
cmd /cjson
{
"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:
-
Determine approach from arguments:
- - Use built-in LSP tool with plugins
native - - Use cclsp MCP server
cclsp - No argument - Ask user which approach they prefer
-
For native approach:
- Check if is already set
ENABLE_LSP_TOOL - Add marketplace if not present
- Install requested language plugin(s)
- Verify with command
/plugin
- Check if
-
For cclsp approach:
- Run interactively
npx cclsp@latest setup - Guide user through language server installation
- Verify MCP server is added with
/mcp
- Run
-
Inform user to restart Claude Code after installation
当用户运行此命令时:
-
根据参数确定方案:
- - 使用带插件的原生LSP工具
native - - 使用cclsp MCP服务器
cclsp - 无参数 - 询问用户偏好哪种方案
-
对于原生方案:
- 检查是否已设置
ENABLE_LSP_TOOL - 若未添加则添加插件市场
- 安装所需的语言插件
- 使用命令验证
/plugin
- 检查
-
对于cclsp方案:
- 交互式运行
npx cclsp@latest setup - 引导用户完成语言服务器的安装
- 使用命令验证MCP服务器已添加
/mcp
- 交互式运行
-
告知用户 安装完成后重启Claude Code