docs(source-generators): 添加源代码生成器完整文档#153
Merged
Merged
Conversation
- 新增 GFramework.SourceGenerators 主文档,介绍编译时代码生成工具 - 详细说明 Log 属性生成器的使用方法和配置选项 - 完整描述 ContextAware 属性生成器的功能和测试场景配置 - 添加 GenerateEnumExtensions 属性生成器文档和使用示例 - 介绍 GetNode 生成器(Godot 专用)的节点获取功能 - 新增 BindNodeSignal 生成器文档,说明信号绑定与解绑机制 - 提供 Context Get 注入生成器的完整使用指南 - 添加诊断信息章节,涵盖所有生成器的错误提示和解决方案 - 包含性能优势对比和基准测试结果 - 提供多个完整使用示例,展示实际应用场景 - 整理最佳实践和常见问题解答 - 添加 BindNodeSignal 生成器专用文档,详细介绍其高级用法
Reviewer's Guide为新的面向 Godot 的源生成器(GetNode 和 BindNodeSignal)在中文 source-generators 文档中补充完整文档,包括导航入口、使用指南、生成代码示例、诊断信息以及最佳实践。 GetNode 生成器在 Godot _Ready 生命周期中的时序图sequenceDiagram
actor Developer
participant CSharpCompiler
participant GetNodeGenerator
participant GameHud as GameHud_partial
participant GodotEngine
participant SceneTree
Developer->>CSharpCompiler: Add GetNode attributes on fields
CSharpCompiler->>GetNodeGenerator: Analyze GameHud with GetNode
GetNodeGenerator-->>CSharpCompiler: Generate __InjectGetNodes_Generated and _Ready override
CSharpCompiler-->>Developer: Build succeeds with generated code
GodotEngine->>GameHud: Instantiate GameHud node
GodotEngine->>GameHud: Call _Ready
GameHud->>GameHud: __InjectGetNodes_Generated
GameHud->>SceneTree: GetNode for each annotated field
SceneTree-->>GameHud: Resolved node references assigned to fields
GameHud-->>GodotEngine: _Ready completed with initialized node fields
BindNodeSignal 生成器绑定与解绑的时序图sequenceDiagram
actor Developer
participant CSharpCompiler
participant BindNodeSignalGenerator
participant MainMenu as MainMenu_partial
participant GodotEngine
participant ButtonNode as StartButton
Developer->>CSharpCompiler: Add BindNodeSignal attributes on methods
CSharpCompiler->>BindNodeSignalGenerator: Analyze MainMenu with BindNodeSignal
BindNodeSignalGenerator-->>CSharpCompiler: Generate __BindNodeSignals_Generated and __UnbindNodeSignals_Generated
CSharpCompiler-->>Developer: Build succeeds with generated code
GodotEngine->>MainMenu: Instantiate MainMenu node
GodotEngine->>MainMenu: Call _Ready
MainMenu->>MainMenu: __BindNodeSignals_Generated
MainMenu->>StartButton: Subscribe Pressed += OnStartButtonPressed
StartButton->>MainMenu: Pressed event invokes OnStartButtonPressed
GodotEngine->>MainMenu: Call _ExitTree
MainMenu->>MainMenu: __UnbindNodeSignals_Generated
MainMenu->>StartButton: Unsubscribe Pressed -= OnStartButtonPressed
MainMenu-->>GodotEngine: _ExitTree completed with signals unbound
使用 GetNode 与 BindNodeSignal 生成器的 Godot 节点更新后类图classDiagram
class Node
class Control
Node <|-- Control
class GetNodeAttribute {
+Lookup : NodeLookupMode
+Required : bool
}
class BindNodeSignalAttribute {
+nodeFieldName : string
+signalName : string
}
class GameHud {
-_pauseButton : Button
-_healthBar : ProgressBar
-_scoreLabel : Label
+_Ready() : void
+_ExitTree() : void
-__InjectGetNodes_Generated() : void
-__BindNodeSignals_Generated() : void
-__UnbindNodeSignals_Generated() : void
-OnPauseButtonPressed() : void
-OnHealthChanged(value double) : void
}
Control <|-- GameHud
GetNodeAttribute .. GameHud : applied_to_fields
BindNodeSignalAttribute .. GameHud : applied_to_methods
class Button
class ProgressBar
class Label
Node <|-- Button
Node <|-- ProgressBar
Node <|-- Label
GameHud o-- Button : pauseButton_field
GameHud o-- ProgressBar : healthBar_field
GameHud o-- Label : scoreLabel_field
文件级变更
Tips and commandsInteracting with Sourcery
Customizing Your Experience打开你的 dashboard 来:
Getting HelpOriginal review guide in EnglishReviewer's GuideAdds full documentation for the new Godot-focused source generators (GetNode and BindNodeSignal) to the Chinese source-generators docs, including navigation entries, usage guides, generated code examples, diagnostics, and best practices. Sequence diagram for GetNode generator lifecycle in Godot _ReadysequenceDiagram
actor Developer
participant CSharpCompiler
participant GetNodeGenerator
participant GameHud as GameHud_partial
participant GodotEngine
participant SceneTree
Developer->>CSharpCompiler: Add GetNode attributes on fields
CSharpCompiler->>GetNodeGenerator: Analyze GameHud with GetNode
GetNodeGenerator-->>CSharpCompiler: Generate __InjectGetNodes_Generated and _Ready override
CSharpCompiler-->>Developer: Build succeeds with generated code
GodotEngine->>GameHud: Instantiate GameHud node
GodotEngine->>GameHud: Call _Ready
GameHud->>GameHud: __InjectGetNodes_Generated
GameHud->>SceneTree: GetNode for each annotated field
SceneTree-->>GameHud: Resolved node references assigned to fields
GameHud-->>GodotEngine: _Ready completed with initialized node fields
Sequence diagram for BindNodeSignal generator binding and unbindingsequenceDiagram
actor Developer
participant CSharpCompiler
participant BindNodeSignalGenerator
participant MainMenu as MainMenu_partial
participant GodotEngine
participant ButtonNode as StartButton
Developer->>CSharpCompiler: Add BindNodeSignal attributes on methods
CSharpCompiler->>BindNodeSignalGenerator: Analyze MainMenu with BindNodeSignal
BindNodeSignalGenerator-->>CSharpCompiler: Generate __BindNodeSignals_Generated and __UnbindNodeSignals_Generated
CSharpCompiler-->>Developer: Build succeeds with generated code
GodotEngine->>MainMenu: Instantiate MainMenu node
GodotEngine->>MainMenu: Call _Ready
MainMenu->>MainMenu: __BindNodeSignals_Generated
MainMenu->>StartButton: Subscribe Pressed += OnStartButtonPressed
StartButton->>MainMenu: Pressed event invokes OnStartButtonPressed
GodotEngine->>MainMenu: Call _ExitTree
MainMenu->>MainMenu: __UnbindNodeSignals_Generated
MainMenu->>StartButton: Unsubscribe Pressed -= OnStartButtonPressed
MainMenu-->>GodotEngine: _ExitTree completed with signals unbound
Updated class diagram for Godot node using GetNode and BindNodeSignal generatorsclassDiagram
class Node
class Control
Node <|-- Control
class GetNodeAttribute {
+Lookup : NodeLookupMode
+Required : bool
}
class BindNodeSignalAttribute {
+nodeFieldName : string
+signalName : string
}
class GameHud {
-_pauseButton : Button
-_healthBar : ProgressBar
-_scoreLabel : Label
+_Ready() : void
+_ExitTree() : void
-__InjectGetNodes_Generated() : void
-__BindNodeSignals_Generated() : void
-__UnbindNodeSignals_Generated() : void
-OnPauseButtonPressed() : void
-OnHealthChanged(value double) : void
}
Control <|-- GameHud
GetNodeAttribute .. GameHud : applied_to_fields
BindNodeSignalAttribute .. GameHud : applied_to_methods
class Button
class ProgressBar
class Label
Node <|-- Button
Node <|-- ProgressBar
Node <|-- Label
GameHud o-- Button : pauseButton_field
GameHud o-- ProgressBar : healthBar_field
GameHud o-- Label : scoreLabel_field
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Mar 31, 2026 9:14a.m. | Review ↗ | |
| Secrets | Mar 31, 2026 9:14a.m. | Review ↗ |
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
由 Sourcery 提供的总结
为新的 Godot 专用源生成器撰写文档,并从主源生成器索引中链接到它们。
新功能:
GetNode的文档和使用指南,包括配置、诊断以及最佳实践。BindNodeSignal的文档和使用指南,包括生命周期集成、诊断以及高级用法场景。文档:
Original summary in English
Summary by Sourcery
Document new Godot-specific source generators and link them from the main source-generators index.
New Features:
Documentation: