coding-agent 通过 LSP 协议为 LLM 提供代码智能能力:跳转到定义、查找引用、类型提示、编译诊断和符号索引。
| 语言 | 语言服务器 | 安装命令 |
|---|---|---|
| Go | gopls |
go install golang.org/x/tools/gopls@latest |
| TypeScript/JavaScript | typescript-language-server |
npm install -g typescript-language-server typescript |
| Python | pyright-langserver |
pip install pyright |
| Rust | rust-analyzer |
rustup component add rust-analyzer |
- 自动检测:Agent 启动时扫描项目文件结构,检测项目使用的语言
- 启动服务器:对每种检测到的语言,后台异步启动对应的语言服务器(stdio JSON-RPC)
- 工具路由:调用工具时,根据文件扩展名自动路由到正确的语言服务器
{
"file": "internal/agent/agent.go",
"line": 62,
"symbol": "NewAgent"
}返回定义所在的文件和行号。
{
"file": "internal/agent/agent.go",
"line": 62,
"symbol": "NewAgent"
}返回项目中所有引用该符号的位置列表。
{
"file": "internal/agent/agent.go",
"line": 62,
"symbol": "NewAgent"
}返回符号的类型签名和文档注释(markdown 格式)。
{
"file": "internal/agent/agent.go"
}返回文件的编译错误、警告、提示等诊断信息。
outline(文件大纲):
{
"action": "outline",
"path": "internal/agent/agent.go",
"kind": "func",
"limit": 100
}search(跨项目搜索):
{
"action": "search",
"query": "NewAgent",
"limit": 50
}internal/lsp/
├── protocol.go # LSP 类型定义(Position, Range, Location, Diagnostic, etc.)
├── client.go # stdio JSON-RPC 客户端(Content-Length 帧协议)
├── manager.go # 多语言检测 + 服务器生命周期管理
└── protocol_test.go # 11 个测试用例
internal/tools/
└── lsp_tools.go # 5 个 Tool 包装器
- 语言服务器未安装时:工具返回友好提示(含安装命令)
- 项目没有支持的语言时:不启动任何 LSP server,工具返回 "LSP server 未启动"
- 连接超时(30s):不阻塞 Agent 启动,server 启动失败只记录日志
在 manager.go 的 defaultLanguages 中添加新的 LanguageConfig:
{
Name: "新语言",
Extensions: []string{".ext"},
Files: []string{"特征文件名"},
Command: "language-server-command",
Args: []string{"--stdio"},
InstallHint: "install command",
}