godot-verify
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGodot Verification Skill
Godot 验证技能
Validate Godot project changes using gdlint, gdformat, gdradon, godot export commands, and LSP diagnostics.
使用gdlint、gdformat、gdradon、godot导出命令及LSP诊断工具验证Godot项目变更。
排除规则
排除规则
不要检查和处理 目录下的任何文件。
addonsaddons不要检查和处理 目录下的任何文件。
addonsaddons检查项
检查项
| 检查 | 命令/工具 | 说明 |
|---|---|---|
| Lint | | Lint GDScript 代码 |
| Format | | 格式化/检查格式 |
| Metrics | | 代码指标分析 |
| Export | | 导出验证 |
| LSP Diagnostics | | 实时语法检查(通过 MCP) |
| 检查 | 命令/工具 | 说明 |
|---|---|---|
| 代码检查(Lint) | | 检查GDScript代码 |
| 格式检查 | | 格式化/检查代码格式 |
| 代码指标 | | 代码指标分析 |
| 导出验证 | | 执行导出验证 |
| LSP诊断 | | 实时语法检查(通过MCP) |
gdradon 输出
gdradon 输出
gdradon cc <path>输出格式:
F <line>:<col> <function_name> - <grade> (<cc>)| 字段 | 说明 |
|---|---|
| F | 函数 (Function) |
| 行号和列号 |
| 函数名 |
| 复杂度等级: A(简单), B(中等), C(复杂), D(非常复杂), F(极复杂) |
| 圈复杂度数值 |
示例:
.\character_body_2d.gd
F 13:0 _physics_process - C (15)gdradon cc <path>输出格式:
F <line>:<col> <function_name> - <grade> (<cc>)| 字段 | 说明 |
|---|---|
| F | 函数 (Function) |
| 行号和列号 |
| 函数名 |
| 复杂度等级: A(简单), B(中等), C(复杂), D(非常复杂), F(极复杂) |
| 圈复杂度数值 |
示例:
.\character_body_2d.gd
F 13:0 _physics_process - C (15)使用示例
使用示例
bash
undefinedbash
undefinedLint 检查
Lint 检查
gdlint "D:/project/scripts/Player.gd"
gdlint "D:/project/scripts/Player.gd"
Format 检查
Format 检查
gdformat --check "D:/project/scripts/Player.gd"
gdformat --check "D:/project/scripts/Player.gd"
代码指标
代码指标
gdradon cc D:/project/scripts/
gdradon cc D:/project/scripts/
LSP 诊断(DiagnosticsServer 为开机自启动服务)
LSP 诊断(DiagnosticsServer 为开机自启动服务)
调用 MCP 工具获取诊断(只需 uri 参数)
调用 MCP 工具获取诊断(只需 uri 参数)
godot-lsp__diagnostics(uri="file:///D:/project/game/player.gd")
godot-lsp__diagnostics(uri="file:///D:/project/game/player.gd")
LSP 诊断(修改代码后使用 refresh=true)
LSP 诊断(修改代码后使用 refresh=true)
godot-lsp__diagnostics(uri="file:///D:/project/game/player.gd", refresh=true)
godot-lsp__diagnostics(uri="file:///D:/project/game/player.gd", refresh=true)
完整检查
完整检查
gdlint D:/project/scripts/ && gdformat D:/project/scripts/ && gdradon cc D:/project/scripts/
gdlint D:/project/scripts/ && gdformat D:/project/scripts/ && gdradon cc D:/project/scripts/
导出验证
导出验证
godot --headless --path "D:/project" --export-pack "Web" "D:/export.pck"
undefinedgodot --headless --path "D:/project" --export-pack "Web" "D:/export.pck"
undefinedLSP Diagnostics
LSP Diagnostics
Godot LSP 诊断提供实时的语法检查和错误检测,与 Godot 编辑器显示的诊断一致。
Godot LSP 诊断提供实时的语法检查和错误检测,与 Godot 编辑器显示的诊断一致。
前置条件
前置条件
- Godot 编辑器运行(Godot LSP 服务器在编辑器启动时自动开启,默认端口 6005)
- DiagnosticsServer 运行(开机自启动服务,提供诊断缓存)
- Godot 编辑器运行(Godot LSP 服务器在编辑器启动时自动开启,默认端口 6005)
- DiagnosticsServer 运行(开机自启动服务,提供诊断缓存)
MCP 工具调用
MCP 工具调用
工具名:
godot-lsp__diagnostics参数:
- (必需):
uriURI,例如file://file:///D:/project/game/player.gd - (可选): 是否强制刷新诊断缓存,默认 false
refresh
返回:
json
{
"uri": "file:///D:/project/game/player.gd",
"diagnostics": [
{
"range": { "start": { "line": 4, "character": 0 }, "end": { "line": 4, "character": 56 } },
"severity": 2,
"code": 9,
"source": "gdscript",
"message": "(SHADOWED_GLOBAL_IDENTIFIER): The constant \"AttackType\" has the same name as a global class..."
}
],
"cached": false // true 表示从缓存返回,false 表示新打开文件
}说明:
- DiagnosticsServer 会自动读取文件内容,无需传递 参数
text - 首次查询会打开文件并等待诊断(约 500ms)
- 后续查询直接从缓存返回,速度更快
- 修改代码后推荐使用 强制刷新缓存,确保获取最新诊断结果
refresh=true
工具名:
godot-lsp__diagnostics参数:
- (必需):
uriURI,例如file://file:///D:/project/game/player.gd - (可选): 是否强制刷新诊断缓存,默认 false
refresh
返回:
json
{
"uri": "file:///D:/project/game/player.gd",
"diagnostics": [
{
"range": { "start": { "line": 4, "character": 0 }, "end": { "line": 4, "character": 56 } },
"severity": 2,
"code": 9,
"source": "gdscript",
"message": "(SHADOWED_GLOBAL_IDENTIFIER): The constant \"AttackType\" has the same name as a global class..."
}
],
"cached": false // true 表示从缓存返回,false 表示新打开文件
}说明:
- DiagnosticsServer 会自动读取文件内容,无需传递 参数
text - 首次查询会打开文件并等待诊断(约 500ms)
- 后续查询直接从缓存返回,速度更快
- 修改代码后推荐使用 强制刷新缓存,确保获取最新诊断结果
refresh=true
诊断级别 (severity)
诊断级别 (severity)
| 级别 | 值 | 说明 |
|---|---|---|
| Error | 1 | 错误,必须修复 |
| Warning | 2 | 警告,建议修复 |
| Information | 3 | 信息 |
| Hint | 4 | 提示 |
| 级别 | 值 | 说明 |
|---|---|---|
| 错误 | 1 | 错误,必须修复 |
| 警告 | 2 | 警告,建议修复 |
| 信息 | 3 | 信息提示 |
| 提示 | 4 | 优化提示 |
常见诊断代码
常见诊断代码
| 代码 | 消息 | 说明 |
|---|---|---|
| 1 | | 语法错误 |
| 9 | | 常量名与全局类冲突 |
| 12 | | 静态变量类型不匹配 |
| 21 | | 返回值未使用 |
| 30 | | 不安全的函数调用 |
| 40 | | 访问未赋值的变量 |
| 代码 | 消息 | 说明 |
|---|---|---|
| 1 | | 语法错误 |
| 9 | | 常量名与全局类冲突 |
| 12 | | 静态变量类型不匹配 |
| 21 | | 返回值未使用 |
| 30 | | 不安全的函数调用 |
| 40 | | 访问未赋值的变量 |
HTTP API(直接访问 DiagnosticsServer)
HTTP API(直接访问 DiagnosticsServer)
bash
undefinedbash
undefined获取诊断
获取诊断
刷新诊断
刷新诊断
curl -X POST "http://127.0.0.1:3457/refresh" -d "{"path":"D:/project/game/player.gd"}"
curl -X POST "http://127.0.0.1:3457/refresh" -d "{"path":"D:/project/game/player.gd"}"
查看状态
查看状态
curl "http://127.0.0.1:3457/stats"
undefinedcurl "http://127.0.0.1:3457/stats"
undefined与 gdlint 对比
与 gdlint 对比
| 特性 | LSP Diagnostics | gdlint |
|---|---|---|
| 实时性 | 实时(缓存) | 需要运行 |
| 错误类型 | 语法 + 语义 | Lint 规则 |
| 与编辑器一致 | 完全一致 | 可能不同 |
| 速度 | 快(有缓存) | 慢(需解析) |
| 需要 Godot | 是 | 否 |
建议: 使用 LSP Diagnostics 作为快速检查,gdlint 作为补充 lint 规则检查。
| 特性 | LSP Diagnostics | gdlint |
|---|---|---|
| 实时性 | 实时(缓存) | 需要手动运行 |
| 错误类型 | 语法 + 语义错误 | Lint规则检查 |
| 与编辑器一致性 | 完全一致 | 可能存在差异 |
| 速度 | 快(带缓存) | 慢(需重新解析) |
| 是否需要Godot | 是 | 否 |
建议: 使用 LSP Diagnostics 作为快速检查工具,gdlint 作为补充的Lint规则检查工具。
Lint Rules (gdlint)
Lint Rules (gdlint)
| Rule | Severity | Description |
|---|---|---|
| Error | Variable declared but never used |
| Error | Variable shadows member variable |
| Error | Function name violates naming convention |
| Error | Constant name violates naming convention |
| Warning | Lines have trailing whitespace |
| Warning | Function missing documentation |
| Warning | Line exceeds 120 characters |
| 规则 | 级别 | 描述 |
|---|---|---|
| 错误 | 变量已声明但从未使用 |
| 错误 | 变量遮蔽了成员变量 |
| 错误 | 函数名违反命名规范 |
| 错误 | 常量名违反命名规范 |
| 警告 | 行尾存在空格 |
| 警告 | 函数缺少文档注释 |
| 警告 | 行长度超过120字符 |
Error Handling
错误处理
| Error | Solution |
|---|---|
| Navigate to project root or provide absolute path |
| Install: |
| Install: |
| Add godot to PATH |
| Convert relative to absolute paths |
| 错误 | 解决方案 |
|---|---|
| 切换到项目根目录或提供绝对路径 |
| 安装: |
| 安装: |
| 将godot添加到系统PATH中 |
| 将相对路径转换为绝对路径 |
Common Workflows
常见工作流
After Code Changes
代码修改后
bash
gdlint "D:/project/scripts/Player.gd"bash
gdlint "D:/project/scripts/Player.gd"Pre-commit Validation
提交前验证
bash
gdlint D:/project/scripts/ && gdformat D:/project/scripts/bash
gdlint D:/project/scripts/ && gdformat D:/project/scripts/Code Metrics Analysis
代码指标分析
bash
gdradon cc D:/project/scripts/输出示例:
.\character_body_2d.gd
F 13:0 _physics_process - C (15)bash
gdradon cc D:/project/scripts/输出示例:
.\character_body_2d.gd
F 13:0 _physics_process - C (15)Export Validation
导出验证
bash
godot --headless --path "D:/project" --export-pack "Web" "D:/export.pck"bash
godot --headless --path "D:/project" --export-pack "Web" "D:/export.pck"安装要求
安装要求
- (gdlint, gdformat)
pip install gdtoolkit - (code metrics)
pip install gdradon - in PATH (export validation)
godot
- (gdlint, gdformat)
pip install gdtoolkit - (代码指标)
pip install gdradon - 已添加到PATH(导出验证)
godot
Tips
提示
- Use param to check only changed files (faster)
file - shows what would change without modifying
gdformat --check - shows complexity and maintainability metrics
gdradon cc - Export validation catches dependency issues lint misses
- 使用 参数仅检查变更的文件(速度更快)
file - 会显示将进行的格式修改但不实际更改文件
gdformat --check - 会显示代码复杂度及可维护性指标
gdradon cc - 导出验证能发现Lint工具无法检测到的依赖问题