Skip to content

docs(source-generators): 添加源代码生成器完整文档#153

Merged
GeWuYou merged 1 commit into
mainfrom
docs/source-generators-complete-documentation
Mar 31, 2026
Merged

docs(source-generators): 添加源代码生成器完整文档#153
GeWuYou merged 1 commit into
mainfrom
docs/source-generators-complete-documentation

Conversation

@GeWuYou

@GeWuYou GeWuYou commented Mar 31, 2026

Copy link
Copy Markdown
Owner
  • 新增 GFramework.SourceGenerators 主文档,介绍编译时代码生成工具
  • 详细说明 Log 属性生成器的使用方法和配置选项
  • 完整描述 ContextAware 属性生成器的功能和测试场景配置
  • 添加 GenerateEnumExtensions 属性生成器文档和使用示例
  • 介绍 GetNode 生成器(Godot 专用)的节点获取功能
  • 新增 BindNodeSignal 生成器文档,说明信号绑定与解绑机制
  • 提供 Context Get 注入生成器的完整使用指南
  • 添加诊断信息章节,涵盖所有生成器的错误提示和解决方案
  • 包含性能优势对比和基准测试结果
  • 提供多个完整使用示例,展示实际应用场景
  • 整理最佳实践和常见问题解答
  • 添加 BindNodeSignal 生成器专用文档,详细介绍其高级用法

由 Sourcery 提供的总结

为新的 Godot 专用源生成器撰写文档,并从主源生成器索引中链接到它们。

新功能:

  • 添加 Godot 源生成器 GetNode 的文档和使用指南,包括配置、诊断以及最佳实践。
  • 添加 Godot 源生成器 BindNodeSignal 的文档和使用指南,包括生命周期集成、诊断以及高级用法场景。

文档:

  • 扩展主源生成器索引,以介绍 Godot 专用生成器并链接到它们的专属页面。
Original summary in English

Summary by Sourcery

Document new Godot-specific source generators and link them from the main source-generators index.

New Features:

  • Add documentation and usage guide for the GetNode Godot source generator, including configuration, diagnostics, and best practices.
  • Add documentation and usage guide for the BindNodeSignal Godot source generator, including lifecycle integration, diagnostics, and advanced scenarios.

Documentation:

  • Extend the main source-generators index to introduce Godot-specific generators and link to their dedicated pages.

- 新增 GFramework.SourceGenerators 主文档,介绍编译时代码生成工具
- 详细说明 Log 属性生成器的使用方法和配置选项
- 完整描述 ContextAware 属性生成器的功能和测试场景配置
- 添加 GenerateEnumExtensions 属性生成器文档和使用示例
- 介绍 GetNode 生成器(Godot 专用)的节点获取功能
- 新增 BindNodeSignal 生成器文档,说明信号绑定与解绑机制
- 提供 Context Get 注入生成器的完整使用指南
- 添加诊断信息章节,涵盖所有生成器的错误提示和解决方案
- 包含性能优势对比和基准测试结果
- 提供多个完整使用示例,展示实际应用场景
- 整理最佳实践和常见问题解答
- 添加 BindNodeSignal 生成器专用文档,详细介绍其高级用法
@sourcery-ai

sourcery-ai Bot commented Mar 31, 2026

Copy link
Copy Markdown

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
Loading

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
Loading

使用 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
Loading

文件级变更

Change Details Files
扩展主源生成器索引页面,以展示 Godot 专用生成器并链接到其专用文档。
  • 在索引页的功能列表和导航锚点中添加 GetNode 和 BindNodeSignal 条目。
  • 新增一个专门小节,将 Godot 专用生成器分组,以提升可发现性。
  • 在概要部分以及诊断部分附近,为 GetNode 和 BindNodeSignal 区块插入简短的行内描述和“完整文档”链接。
docs/zh-CN/source-generators/index.md
添加完整的 GetNode 生成器文档,涵盖 Godot 节点解析的使用方式、配置以及诊断信息。
  • 说明 GetNode 的用途、核心特性,以及它如何替代手写的 GetNode<T>() 调用。
  • 提供基础和高级使用示例,包括字段标注模式、查找模式、必需节点与可选节点,以及路径推断规则。
  • 记录与其他生成器(例如 ContextAware)的集成模式、生命周期预期(_Ready 钩子),以及所有相关诊断 ID 与修复方式。
  • 概述命名、唯一名称使用方式、可选节点以及复杂 UI 节点层级结构的最佳实践。
docs/zh-CN/source-generators/get-node-generator.md
添加完整的 BindNodeSignal 生成器文档,涵盖事件绑定/拆卸以及与 Godot 节点的集成。
  • 解释 BindNodeSignal 的用途、核心特性,以及它如何将信号订阅与取消订阅集中到生成的方法中。
  • 通过示例驱动的方式指导基础用法、多事件绑定、带参数信号、生命周期管理(_Ready/_ExitTree),以及与 GetNode 和 ContextAware 的组合使用。
  • 描述生成的辅助方法(__BindNodeSignals_Generated 和 __UnbindNodeSignals_Generated),以及它们在何时会自动生成、何时需要手动调用。
  • 列出所有 BindNodeSignal 诊断信息,给出典型错误场景与解决方案,并总结相对于手写 += / -= 模式的最佳实践。
docs/zh-CN/source-generators/bind-node-signal-generator.md

Tips and commands

Interacting with Sourcery

  • 触发新的代码审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 在某条审查评论下回复,请 Sourcery 基于该评论创建一个 issue。你也可以直接回复 @sourcery-ai issue 来基于该评论创建 issue。
  • 生成 pull request 标题: 在 pull request 标题中任意位置写上 @sourcery-ai 即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在该位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审查者指南: 在 pull request 中评论 @sourcery-ai guide,可随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,以批量解决所有 Sourcery 评论。当你已经处理完所有评论且不再希望看到它们时非常有用。
  • 忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,以忽略所有现有的 Sourcery 审查。尤其适用于你希望从一次全新的审查开始——别忘了再评论 @sourcery-ai review 来触发新的审查!

Customizing Your Experience

打开你的 dashboard 来:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

Getting Help

Original review guide in English

Reviewer's Guide

Adds 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 _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
Loading

Sequence diagram for BindNodeSignal generator binding and unbinding

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
Loading

Updated class diagram for Godot node using GetNode and BindNodeSignal generators

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
Loading

File-Level Changes

Change Details Files
Extend main source generator index to surface Godot-specific generators and link to their dedicated docs.
  • Add GetNode and BindNodeSignal items to the feature list and navigation anchors in the index page.
  • Introduce a dedicated subsection grouping Godot-specific generators for better discoverability.
  • Insert brief inline descriptions and "full docs" links for GetNode and BindNodeSignal sections in the overview and near the diagnostics section.
docs/zh-CN/source-generators/index.md
Add comprehensive GetNode generator documentation covering usage, configuration, and diagnostics for Godot node resolution.
  • Describe GetNode’s purpose, core features, and how it replaces manual GetNode() calls.
  • Provide basic and advanced usage examples, including field annotation patterns, lookup modes, required vs optional nodes, and path inference rules.
  • Document integration patterns with other generators (e.g., ContextAware), lifecycle expectations (_Ready hook), and all related diagnostic IDs with fixes.
  • Outline best practices for naming, unique-name usage, optional nodes, and complex UI node hierarchies.
docs/zh-CN/source-generators/get-node-generator.md
Add comprehensive BindNodeSignal generator documentation covering event binding/teardown and integration with Godot nodes.
  • Explain BindNodeSignal’s purpose, core features, and how it centralizes signal subscription and unsubscription into generated methods.
  • Provide example-driven guidance for basic use, multi-event binding, parameterized signals, lifecycle management (_Ready/_ExitTree), and combination with GetNode and ContextAware.
  • Describe the generated helper methods (__BindNodeSignals_Generated and __UnbindNodeSignals_Generated) and when they are auto-generated vs need manual invocation.
  • List all BindNodeSignal diagnostics with example error situations and resolutions, and summarize best practices vs manual += / -= patterns.
docs/zh-CN/source-generators/bind-node-signal-generator.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好——我已经审查了你的更改,看起来非常棒!


Sourcery 对开源项目是免费的——如果你喜欢我们的代码审查,请考虑分享给他人 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的代码审查。
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepsource-io

deepsource-io Bot commented Mar 31, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in ba45171...38020c3 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

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 ↗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant