LSP(Language Server Protocol) 是微软推出的语言服务器协议,用于为编程语言提供智能编辑功能。
┌─────────┐ ┌─────────────────┐ ┌─────────┐
│ Editor │◀──────▶│ LSP Client │◀──────▶│ LSP │
│ (Crush) │ │ (Crush 内置) │ │ Server │
└─────────┘ └─────────────────┘ └─────────┘
lsp:
# Go 语言服务器
gopls:
command: "gopls"
enabled: true
options:
gofumpt: true
# TypeScript/JavaScript
tsserver:
command: "typescript-language-server"
args: ["--stdio"]
file_types: ["typescript", "javascript"]
# Python
pyright:
command: "pyright-langserver"
args: ["--stdio"]
file_types: ["python"]
# Rust
rust_analyzer:
command: "rust-analyzer"
file_types: ["rust"]
# 请求诊断
crush> 检查当前文件的代码问题
# 诊断结果
src/main.go:15:2 - error: undefined: fmt.Println (using gopls)
src/utils.go:23:10 - warning: unused parameter 'ctx'
MCP(Model Context Protocol) 是一个开放协议,允许 AI 模型与外部工具和数据源连接。
┌─────────────┐ ┌─────────────────┐
│ AI Model │◀──────▶│ MCP Client │
│ (Crush) │ │ (Crush 内置) │
└─────────────┘ └────────┬────────┘
│
│ JSON-RPC 2.0
▼
┌──────────────────────────────────────────────────────────────┐
│ MCP Server │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ filesystem │ │ github │ │ sqlite │ │
│ │ server │ │ server │ │ server │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
└──────────────────────────────────────────────────────────────┘
mcp:
servers:
filesystem:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-filesystem"
- "/home/user/projects"
github:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-github"
env:
GITHUB_TOKEN: "${GITHUB_TOKEN}"
# 列出所有可用的 MCP 工具
crush> 列出所有可用的 MCP 工具
# 使用 GitHub MCP 工具
crush> 在 github 仓库 charmbracelet/crush 中创建一个 issue
# 使用 Filesystem MCP 工具
crush> 列出 /home/user/projects 目录下的所有 Go 文件
mcp:
servers:
github:
command: "npx"
args:
- "-y"
- "@modelcontextprotocol/server-github"
env:
GITHUB_TOKEN: "${GITHUB_TOKEN}"
使用示例:
crush> 查看 crush 仓库的最新 5 个 closed issues
crush> 在当前项目创建一个 PR,标题为 "feat: 添加新功能"
crush> 搜索仓库中与 "authentication" 相关的代码
本文是《Crush 从入门到精通》系列的第六、七章
还没有人回复