Skip to content

docs(guide): 添加 ContextAware 生成器文档并更新相关链接#86

Merged
GeWuYou merged 4 commits into
mainfrom
docs/technical-documentation-update
Mar 7, 2026
Merged

docs(guide): 添加 ContextAware 生成器文档并更新相关链接#86
GeWuYou merged 4 commits into
mainfrom
docs/technical-documentation-update

Conversation

@GeWuYou

@GeWuYou GeWuYou commented Mar 7, 2026

Copy link
Copy Markdown
Owner
  • 新增 ContextAware 生成器完整文档,介绍自动实现 IContextAware 接口的功能
  • 更新索引页面中的相关链接,替换规则生成器为 ContextAware 生成器
  • 修改基础使用示例中的命名空间引用和代码实现细节
  • 补充测试场景配置和多架构场景的使用说明
  • 添加最佳实践和诊断信息相关内容

由 Sourcery 提供的摘要

为新的 ContextAware 源生成器撰写文档,并更新相关文档中的引用和示例以使用该生成器。

文档更新内容:

  • 添加一篇专门介绍 ContextAware 生成器的指南,说明其用途、生成的代码、使用场景、最佳实践以及诊断信息。
  • 更新源生成器概览以及日志/枚举生成器文档,将链接从规则生成器改为指向 ContextAware 生成器,并刷新基础使用示例以匹配新的 API。
Original summary in English

Summary by Sourcery

Document the new ContextAware source generator and update related documentation references and examples to use it.

Documentation:

  • Add a dedicated ContextAware 生成器 guide describing its purpose, generated code, usage scenarios, best practices, and diagnostics.
  • Update source generator overview and logging/enum generator docs to link to the ContextAware generator instead of the rule generator, and refresh basic usage examples to match the new API.

- 新增 ContextAware 生成器完整文档,介绍自动实现 IContextAware 接口的功能
- 更新索引页面中的相关链接,替换规则生成器为 ContextAware 生成器
- 修改基础使用示例中的命名空间引用和代码实现细节
- 补充测试场景配置和多架构场景的使用说明
- 添加最佳实践和诊断信息相关内容
@deepsource-io

deepsource-io Bot commented Mar 7, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 575dcdf...740cc66 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 7, 2026 3:13p.m. Review ↗
Secrets Mar 7, 2026 3:13p.m. Review ↗

@sourcery-ai

sourcery-ai Bot commented Mar 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

为新的 ContextAware 源代码生成器补充了完整文档,更新了主源代码生成器文档以使用它替代旧的规则生成器,并刷新了基础用法示例和生成代码,使其匹配新的 IContextAware 模式,包括上下文提供程序配置以及测试指南。

使用默认 GameContextProvider 惰性初始化 Context 的时序图

sequenceDiagram
    actor Game
    participant PlayerController
    participant GameContextProvider
    participant IArchitectureContext

    Game->>PlayerController: Initialize()
    PlayerController->>PlayerController: access Context
    alt _context is null and _contextProvider is null
        PlayerController->>GameContextProvider: new GameContextProvider()
        PlayerController->>GameContextProvider: GetContext()
        GameContextProvider-->>PlayerController: IArchitectureContext
        PlayerController->>PlayerController: cache in _context
    else _context already set
        PlayerController->>PlayerController: reuse _context
    end
    PlayerController->>IArchitectureContext: GetModel PlayerModel
    IArchitectureContext-->>PlayerController: PlayerModel
    PlayerController->>IArchitectureContext: GetSystem CombatSystem
    IArchitectureContext-->>PlayerController: CombatSystem
    PlayerController->>IArchitectureContext: SendEvent PlayerInitializedEvent
Loading

测试配置覆盖 Context 提供程序的时序图

sequenceDiagram
    actor TestRunner
    participant TestMethod
    participant PlayerController
    participant TestContextProvider
    participant IArchitectureContext

    TestRunner->>TestMethod: execute TestPlayerController
    TestMethod->>TestMethod: create TestArchitecture
    TestMethod->>TestContextProvider: new TestContextProvider(testArchitecture)
    TestMethod->>PlayerController: SetContextProvider(provider)

    TestMethod->>PlayerController: new PlayerController()
    TestMethod->>PlayerController: Initialize()
    PlayerController->>PlayerController: access Context
    alt _context is null and _contextProvider already set
        PlayerController->>TestContextProvider: GetContext()
        TestContextProvider-->>PlayerController: IArchitectureContext
        PlayerController->>PlayerController: cache in _context
    else _context already set
        PlayerController->>PlayerController: reuse _context
    end
    PlayerController->>IArchitectureContext: GetModel PlayerModel
    IArchitectureContext-->>PlayerController: PlayerModel
    TestMethod-->>TestRunner: assertions and finally ResetContextProvider
Loading

ContextAware 生成模式及相关抽象的类图

classDiagram
    class PlayerController {
      -_context : IArchitectureContext
      -_contextProvider : IArchitectureContextProvider
      +PlayerController()
      +Initialize() void
      +Attack(target : Enemy) void
      +static SetContextProvider(provider : IArchitectureContextProvider) void
      +static ResetContextProvider() void
      #Context : IArchitectureContext
    }

    class IContextAware {
      <<interface>>
      +SetContext(context : IArchitectureContext) void
      +GetContext() IArchitectureContext
    }

    class IController {
      <<interface>>
    }

    class IArchitectureContext {
      <<interface>>
      +GetModel_T_() T
      +GetSystem_T_() T
      +GetUtility_T_() T
      +SendEvent(event : object) void
      +SendCommand(command : object) void
    }

    class IArchitectureContextProvider {
      <<interface>>
      +GetContext() IArchitectureContext
    }

    class GameContextProvider {
      +GameContextProvider()
      +GetContext() IArchitectureContext
    }

    class TestContextProvider {
      -architecture : IArchitecture
      +TestContextProvider(architecture : IArchitecture)
      +GetContext() IArchitectureContext
    }

    class IArchitecture {
      <<interface>>
    }

    PlayerController ..|> IController
    PlayerController ..|> IContextAware

    GameContextProvider ..|> IArchitectureContextProvider
    TestContextProvider ..|> IArchitectureContextProvider

    IArchitectureContextProvider --> IArchitectureContext
    TestContextProvider --> IArchitecture : wraps

    PlayerController --> IArchitectureContext : uses_Context
    PlayerController --> IArchitectureContextProvider : uses_contextProvider
Loading

文件级变更

Change Details Files
更新基础 ContextAware 使用示例和生成代码,以反映新的 IContextAware 实现模式,包括用于测试和多架构场景的上下文提供程序配置。
  • 更改示例中的 using 指令,使其引用新的源生成器和控制器命名空间。
  • 用新的实现替换之前简化的生成代码示例,该实现显式实现 IContextAware,使用可空注解,通过 GameContextProvider 惰性加载 IArchitectureContext,并提供静态 SetContextProvider/ResetContextProvider 帮助方法。
  • 新增测试示例,展示如何在单元测试中设置和重置自定义上下文提供程序。
docs/zh-CN/source-generators/index.md
将导航链接从已移除的规则生成器文档重定向到新的 ContextAware 生成器文档。
  • 将枚举生成器文档页脚链接从规则生成器改为 ContextAware 生成器。
  • 将日志生成器文档页脚链接从规则生成器改为 ContextAware 生成器。
docs/zh-CN/source-generators/enum-generator.md
docs/zh-CN/source-generators/logging-generator.md
新增一整页专门的 ContextAware 生成器文档,涵盖用法、生成代码、测试、多架构、最佳实践和诊断信息,并移除旧的规则生成器文档。
  • 新增 context-aware-generator.md,文档内容包括 ContextAware 特性、所需类约束、精确的生成代码结构、如何为测试和多架构场景配置自定义上下文提供程序、与继承 ContextAwareBase 的推荐使用场景对比,以及相关诊断代码 GFSG001/GFSG002。
  • 包含最佳实践和使用模式,例如避免在构造函数中访问 Context,并优先使用生成的 Context 属性而不是直接调用 IContextAware 方法。
  • 链接到相关核心文档(context、IContextAware)以及其他生成器。
  • 删除已废弃的 rule-generator.md 文档文件。
docs/zh-CN/source-generators/context-aware-generator.md
docs/zh-CN/source-generators/rule-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 来(重新)生成摘要。
  • 生成 Reviewer 指南: 在 pull request 中评论 @sourcery-ai guide 来(重新)生成 Reviewer 指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve 来解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 忽略所有 Sourcery 审核: 在 pull request 中评论 @sourcery-ai dismiss 来忽略所有现有 Sourcery 审核。特别适用于希望从一个全新的审核开始的情况——别忘了再评论 @sourcery-ai review 来触发新的审核!

Customizing Your Experience

访问你的 dashboard 以:

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

Getting Help

Original review guide in English

Reviewer's Guide

Adds comprehensive documentation for the new ContextAware source generator, updates the main source generator docs to use it instead of the old rule generator, and refreshes the basic usage example and generated code to match the new IContextAware pattern with context provider configuration and testing guidance.

Sequence diagram for lazy Context initialization with default GameContextProvider

sequenceDiagram
    actor Game
    participant PlayerController
    participant GameContextProvider
    participant IArchitectureContext

    Game->>PlayerController: Initialize()
    PlayerController->>PlayerController: access Context
    alt _context is null and _contextProvider is null
        PlayerController->>GameContextProvider: new GameContextProvider()
        PlayerController->>GameContextProvider: GetContext()
        GameContextProvider-->>PlayerController: IArchitectureContext
        PlayerController->>PlayerController: cache in _context
    else _context already set
        PlayerController->>PlayerController: reuse _context
    end
    PlayerController->>IArchitectureContext: GetModel PlayerModel
    IArchitectureContext-->>PlayerController: PlayerModel
    PlayerController->>IArchitectureContext: GetSystem CombatSystem
    IArchitectureContext-->>PlayerController: CombatSystem
    PlayerController->>IArchitectureContext: SendEvent PlayerInitializedEvent
Loading

Sequence diagram for test configuration overriding Context provider

sequenceDiagram
    actor TestRunner
    participant TestMethod
    participant PlayerController
    participant TestContextProvider
    participant IArchitectureContext

    TestRunner->>TestMethod: execute TestPlayerController
    TestMethod->>TestMethod: create TestArchitecture
    TestMethod->>TestContextProvider: new TestContextProvider(testArchitecture)
    TestMethod->>PlayerController: SetContextProvider(provider)

    TestMethod->>PlayerController: new PlayerController()
    TestMethod->>PlayerController: Initialize()
    PlayerController->>PlayerController: access Context
    alt _context is null and _contextProvider already set
        PlayerController->>TestContextProvider: GetContext()
        TestContextProvider-->>PlayerController: IArchitectureContext
        PlayerController->>PlayerController: cache in _context
    else _context already set
        PlayerController->>PlayerController: reuse _context
    end
    PlayerController->>IArchitectureContext: GetModel PlayerModel
    IArchitectureContext-->>PlayerController: PlayerModel
    TestMethod-->>TestRunner: assertions and finally ResetContextProvider
Loading

Class diagram for ContextAware generated pattern and related abstractions

classDiagram
    class PlayerController {
      -_context : IArchitectureContext
      -_contextProvider : IArchitectureContextProvider
      +PlayerController()
      +Initialize() void
      +Attack(target : Enemy) void
      +static SetContextProvider(provider : IArchitectureContextProvider) void
      +static ResetContextProvider() void
      #Context : IArchitectureContext
    }

    class IContextAware {
      <<interface>>
      +SetContext(context : IArchitectureContext) void
      +GetContext() IArchitectureContext
    }

    class IController {
      <<interface>>
    }

    class IArchitectureContext {
      <<interface>>
      +GetModel_T_() T
      +GetSystem_T_() T
      +GetUtility_T_() T
      +SendEvent(event : object) void
      +SendCommand(command : object) void
    }

    class IArchitectureContextProvider {
      <<interface>>
      +GetContext() IArchitectureContext
    }

    class GameContextProvider {
      +GameContextProvider()
      +GetContext() IArchitectureContext
    }

    class TestContextProvider {
      -architecture : IArchitecture
      +TestContextProvider(architecture : IArchitecture)
      +GetContext() IArchitectureContext
    }

    class IArchitecture {
      <<interface>>
    }

    PlayerController ..|> IController
    PlayerController ..|> IContextAware

    GameContextProvider ..|> IArchitectureContextProvider
    TestContextProvider ..|> IArchitectureContextProvider

    IArchitectureContextProvider --> IArchitectureContext
    TestContextProvider --> IArchitecture : wraps

    PlayerController --> IArchitectureContext : uses_Context
    PlayerController --> IArchitectureContextProvider : uses_contextProvider
Loading

File-Level Changes

Change Details Files
Update the basic ContextAware usage example and generated code to reflect the new IContextAware implementation pattern, including context provider configuration for tests and multi-architecture scenarios.
  • Change the example using directives to reference the new source generator and controller namespaces.
  • Replace the previously simplified generated code example with the new implementation that explicitly implements IContextAware, uses nullable annotations, lazy-loaded IArchitectureContext via GameContextProvider, and static SetContextProvider/ResetContextProvider helpers.
  • Add a new testing example showing how to set and reset a custom context provider in unit tests.
docs/zh-CN/source-generators/index.md
Retarget navigation links from the removed rule generator docs to the new ContextAware generator docs.
  • Change the enum generator doc footer link from the rule generator to the ContextAware generator.
  • Change the logging generator doc footer link from the rule generator to the ContextAware generator.
docs/zh-CN/source-generators/enum-generator.md
docs/zh-CN/source-generators/logging-generator.md
Introduce a full dedicated ContextAware generator documentation page covering usage, generated code, testing, multi-architecture, best practices, and diagnostics, and remove the old rule generator doc.
  • Add a new context-aware-generator.md that documents the ContextAware attribute, required class constraints, the exact generated code shape, how to configure custom context providers for tests and multi-architecture scenarios, recommended use cases versus inheriting ContextAwareBase, and related diagnostics codes GFSG001/GFSG002.
  • Include best practices and usage patterns like avoiding Context access in constructors and preferring the generated Context property over direct IContextAware methods.
  • Link to related core docs (context, IContextAware) and other generators.
  • Delete the obsolete rule-generator.md documentation file.
docs/zh-CN/source-generators/context-aware-generator.md
docs/zh-CN/source-generators/rule-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.

你好——我发现了 1 个问题,并给出了一些整体性的反馈:

  • 生成的代码示例使用了 global::GFramework.Core.architecture.GameContextProvider,而相关接口位于 GFramework.Core.Abstractions.architecture 命名空间下;请再次确认 GameContextProvider 的命名空间,以避免示例产生混淆或错误。
  • 在新的 context-aware-generator.md 示例中,测试方法 TestPlayerController 被声明为 void,但方法体中使用了 await;请将方法签名更新为 public async Task TestPlayerController()(或者去掉 await),以确保示例可以编译,并与索引页中的示例保持一致。
  • 新的 context-aware-generator.md 在底部“相关文档”部分仍然链接到 ./rule-generator,但本 PR 中已经移除了 rule-generator.md 文件,同时在“何时继承 ContextAwareBase”一节中存在一处乱码("需要生命���期管理");请考虑修复损坏的链接并更正该错别字。
供 AI Agent 使用的提示词
请根据本次代码审查中的评论进行修改:

## 整体评论
- 生成的代码示例使用了 `global::GFramework.Core.architecture.GameContextProvider`,而相关接口位于 `GFramework.Core.Abstractions.architecture` 命名空间下;请再次确认 `GameContextProvider` 的命名空间,以避免示例产生混淆或错误。
- 在新的 `context-aware-generator.md` 示例中,测试方法 `TestPlayerController` 被声明为 `void`,但方法体中使用了 `await`;请将方法签名更新为 `public async Task TestPlayerController()`(或者去掉 `await`),以确保示例可以编译,并与索引页中的示例保持一致。
- 新的 `context-aware-generator.md` 在底部“相关文档”部分仍然链接到 `./rule-generator`,但本 PR 中已经移除了 `rule-generator.md` 文件,同时在“何时继承 ContextAwareBase”一节中存在一处乱码("需要生命���期管理");请考虑修复损坏的链接并更正该错别字。

## 单条评论

### 评论 1
<location path="docs/zh-CN/source-generators/context-aware-generator.md" line_range="235-236" />
<code_context>
+如果类需要更多框架功能(如生命周期管理),应继承 `ContextAwareBase`+
+```csharp
+// 推荐:需要生命���期管理时继承基类
+public class PlayerModel : AbstractModel
+{
</code_context>
<issue_to_address>
**issue (typo):** “生命���期管理”存在明显乱码,应为“生命周期管理”。

注释中的“生命���期管理”应更正为“生命周期管理”,以避免读者产生困惑。

```suggestion
 // 推荐:需要生命周期管理时继承基类
 public class PlayerModel : AbstractModel
```
</issue_to_address>

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

Hey - I've found 1 issue, and left some high level feedback:

  • The generated code samples use global::GFramework.Core.architecture.GameContextProvider while the related interfaces live under GFramework.Core.Abstractions.architecture; double-check the namespace for GameContextProvider to avoid confusing or incorrect examples.
  • In the new context-aware-generator.md examples, the test method TestPlayerController is declared as void but uses await inside; update the signature to public async Task TestPlayerController() (or remove await) to keep the sample compilable and consistent with the index example.
  • The new context-aware-generator.md still links to ./rule-generator at the bottom under “相关文档” even though rule-generator.md is removed in this PR, and there is also a garbled phrase in “何时继承 ContextAwareBase” ("需要生命���期管理"); consider fixing the broken link and the typo.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The generated code samples use `global::GFramework.Core.architecture.GameContextProvider` while the related interfaces live under `GFramework.Core.Abstractions.architecture`; double-check the namespace for `GameContextProvider` to avoid confusing or incorrect examples.
- In the new `context-aware-generator.md` examples, the test method `TestPlayerController` is declared as `void` but uses `await` inside; update the signature to `public async Task TestPlayerController()` (or remove `await`) to keep the sample compilable and consistent with the index example.
- The new `context-aware-generator.md` still links to `./rule-generator` at the bottom under “相关文档” even though `rule-generator.md` is removed in this PR, and there is also a garbled phrase in “何时继承 ContextAwareBase” ("需要生命���期管理"); consider fixing the broken link and the typo.

## Individual Comments

### Comment 1
<location path="docs/zh-CN/source-generators/context-aware-generator.md" line_range="235-236" />
<code_context>
+如果类需要更多框架功能(如生命周期管理),应继承 `ContextAwareBase`+
+```csharp
+// 推荐:需要生命���期管理时继承基类
+public class PlayerModel : AbstractModel
+{
</code_context>
<issue_to_address>
**issue (typo):** “生命���期管理”存在明显乱码,应为“生命周期管理”。

注释中的“生命���期管理”应更正为“生命周期管理”,以避免读者产生困惑。

```suggestion
 // 推荐:需要生命周期管理时继承基类
 public class PlayerModel : AbstractModel
```
</issue_to_address>

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.

Comment thread docs/zh-CN/source-generators/context-aware-generator.md Outdated
GeWuYou added 3 commits March 7, 2026 22:55
- 修复了代码注释中的错别字"生命期"为"生命周期"
- 移除了文档末尾的规则验证生成器链接引用
- 将 TestPlayerController 方法从同步改为异步
- 使用 Task 类型替代 void 返回类型
- 为测试方法添加 async 关键字修饰符
- 移除 .claude 设置文件
- 重构枚举扩展生成器文档,更新 API 使用方式和配置选项
- 调整日志生成器文档,更新属性使用方式和配置参数
- 修改 Git 忽略规则添加 .claude/settings.json
- 更新代码示例和最佳实践指南
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