使用说明
gopls-mcp:让你的法学硕士更有效地阅读Go Code!
gopls-mcp 是一个功能强大的插件,旨在增强阅读和导航Go语言代码库的体验。通过利用大型语言模型(LLM)和Go语言服务器协议(gopls)的功能,该插件为Go代码分析提供了精确高效的工具,使开发人员能够快速定位项目中的定义、引用和其他关键信息。
主要特点
- 速度:通过使用LLM,显著提高了导航和理解Go代码库的速度。
- 精确度:为代码定义、引用和符号搜索提供准确的结果。
- 易用性:简单直观的工具,可无缝集成到您的工作流程中。
工具和使用示例
1. go_definition
获取Go代码中符号的定义位置。
输入:
{
"file_path": "/path/to/file.go",
"line": 10,
"character": 5
}
输出:
{
"file_path": "/path/to/definition.go",
"line": 25,
"character": 10
}
2. go_references
在Go代码中查找符号的所有参考位置。
输入:
{
"file_path": "/path/to/file.go",
"line": 10,
"character": 5
}
输出:
[
{"file_path": "/path/to/file1.go", "line": 15, "character": 8},
{"file_path": "/path/to/file2.go", "line": 20, "character": 12}
]
3. go_hover
获取Go代码中符号的详细信息,包括类型和文档。
输入:
{
"file_path": "/path/to/file.go",
"line": 10,
"character": 5
}
输出:
{
"type": "func(string) error",
"documentation": "This function processes input and returns an error if any."
}
4. go_symbols
检索Go文件或工作区中的所有符号(函数、类型、变量等)。
输入:
{
"file_path": "/path/to/file.go"
}
输出:
[
{"name": "MyFunction", "kind": "Function", "line": 5, "character": 0},
{"name": "MyStruct", "kind": "Struct", "line": 15, "character": 0}
]
安装
- 确保你有
gopls已安装并可在系统的PATH中使用。 - 安装所需的Python依赖项:
pip install -r requirements.txt - 开始
gopls-mcp服务器:python main_http.py
配置
- 设置
GOPLS_WORKSPACE环境变量,用于指定Go工作区的根。 - 使用
MCP_PORT和MCP_HOST配置服务器的端口和主机(默认值:127.0.0.1:3000).
贡献
欢迎投稿!请参阅 CONTRIBUTING.md 文件指南。
许可证
该项目根据麻省理工学院许可证条款获得许可。请参阅 LICENSE 文件以获取详细信息。
