Feat/gframework analysis#172
Conversation
- 新增 Context Get 注入生成器详细文档,包含使用示例和诊断信息 - 添加源代码生成器总览文档,涵盖 Log、Config Schema、ContextAware 等功能 - 配置测试项目 GFramework.SourceGenerators.Tests 的项目文件和依赖 - 生成器诊断规则新增至 Unshipped 分析器发布跟踪文件
- 使用属性模式匹配替换条件判断语句 - 简化了方法声明语法的空值检查逻辑 - 优化了构造函数声明语法的表达式体检查 - 提高了代码可读性和维护性 - 减少了冗余的语法树遍历操作
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Apr 4, 2026 3:42p.m. | Review ↗ | |
| Secrets | Apr 4, 2026 3:42p.m. | Review ↗ |
Reviewer's Guide添加一个新的 Roslyn 分析器,用于检查 Model/System/Utility 的 context-get 使用点,在其架构中是否存在对应的、可静态发现的注册;并将其诊断接入现有包中、编写文档说明其行为,并通过分析器测试和一个小型的分析器测试工具辅助类进行覆盖。 ContextRegistrationAnalyzer 字段使用分析的时序图sequenceDiagram
participant Compiler as Roslyn_Compiler
participant Analyzer as ContextRegistrationAnalyzer
participant Symbols as SymbolCache
participant Index as RegistrationIndex
participant Field as AnalyzeField
participant Diag as ContextRegistrationDiagnostics
Compiler->>Analyzer: Initialize(context)
Analyzer->>Analyzer: ConfigureGeneratedCodeAnalysis(None)
Analyzer->>Analyzer: EnableConcurrentExecution()
Compiler->>Analyzer: CompilationStartAction(compilationContext)
Analyzer->>Symbols: Create(compilation)
Symbols-->>Analyzer: SymbolCache instance
Analyzer->>Analyzer: Check symbols.IsReady
alt Symbols ready
Analyzer->>Analyzer: Create Lazy RegistrationIndex
Analyzer->>Compiler: RegisterSyntaxNodeAction(AnalyzeField, VariableDeclarator)
Analyzer->>Compiler: RegisterOperationAction(AnalyzeInvocation, Invocation)
else Symbols not ready
Analyzer-->>Compiler: Return (no analysis)
end
loop For each field declarator with attributes
Compiler->>Analyzer: AnalyzeField(SyntaxNodeAnalysisContext)
Analyzer->>Field: TryCreateBindingRequest(fieldSymbol, location, symbols)
alt Attribute matches GetModel/GetSystem/GetUtility
Field-->>Analyzer: BindingRequest(kind, ownerType, serviceType, location)
Analyzer->>Index: registrationIndex.Value (build if first time)
Note over Index: Build(compilation, symbols)
Index->>Index: AnalyzeArchitecture for each Architecture subtype
Index-->>Analyzer: RegistrationIndex instance
Analyzer->>Index: TryGetOwningArchitecture(ownerType, out architectureType)
alt Owning architecture found
Index-->>Analyzer: architectureType
Analyzer->>Index: HasRegistration(architectureType, kind, serviceType)
alt Registration exists
Index-->>Analyzer: true
Analyzer-->>Compiler: No diagnostic
else Registration missing
Index-->>Analyzer: false
Analyzer->>Diag: Select descriptor by kind
Diag-->>Analyzer: DiagnosticDescriptor
Analyzer-->>Compiler: ReportDiagnostic(GF_ContextRegistration_001/002/003)
end
else No unique architecture
Index-->>Analyzer: false
Analyzer-->>Compiler: No diagnostic
end
else Not a supported attribute
Field-->>Analyzer: no request
Analyzer-->>Compiler: Return
end
end
ContextRegistrationAnalyzer 及相关类型的类图classDiagram
direction LR
class ContextRegistrationAnalyzer {
<<DiagnosticAnalyzer>>
+SupportedDiagnostics : ImmutableArray~DiagnosticDescriptor~
+Initialize(context AnalysisContext) void
-AnalyzeField(context SyntaxNodeAnalysisContext, symbols SymbolCache, registrationIndex RegistrationIndex) void
-AnalyzeInvocation(context OperationAnalysisContext, symbols SymbolCache, registrationIndex RegistrationIndex) void
-ReportMissingRegistration(context SyntaxNodeAnalysisContext, registrationIndex RegistrationIndex, request BindingRequest) void
-ReportMissingRegistration(context OperationAnalysisContext, registrationIndex RegistrationIndex, request BindingRequest) void
-CreateMissingRegistrationDiagnostic(request BindingRequest, architectureType INamedTypeSymbol) Diagnostic
-TryCreateBindingRequest(fieldSymbol IFieldSymbol, location Location, symbols SymbolCache, outRequest BindingRequest) bool
-TryCreateBindingRequest(invocation IInvocationOperation, ownerType INamedTypeSymbol, symbols SymbolCache, outRequest BindingRequest) bool
-TryMapAttribute(attributeType INamedTypeSymbol, symbols SymbolCache, outKind ComponentKind, outExpectsCollection bool) bool
-IsSupportedGetInvocationTarget(targetMethod IMethodSymbol, symbols SymbolCache) bool
-TryGetCollectionElementType(fieldType ITypeSymbol, symbols SymbolCache) INamedTypeSymbol
-_contextAwareBindingNames : IReadOnlyDictionary~string,ComponentKind~
}
class ComponentKind {
<<enum>>
Model
System
Utility
}
class BindingRequest {
<<record struct>>
+Kind : ComponentKind
+OwnerType : INamedTypeSymbol
+ServiceType : INamedTypeSymbol
+Location : Location
}
class SymbolCache {
-SymbolCache(architectureType INamedTypeSymbol, iArchitectureType INamedTypeSymbol, iArchitectureModuleType INamedTypeSymbol, iArchitectureContextType INamedTypeSymbol, iReadOnlyListType INamedTypeSymbol, contextAwareServiceExtensionsType INamedTypeSymbol, getModelAttribute INamedTypeSymbol, getModelsAttribute INamedTypeSymbol, getSystemAttribute INamedTypeSymbol, getSystemsAttribute INamedTypeSymbol, getUtilityAttribute INamedTypeSymbol, getUtilitiesAttribute INamedTypeSymbol)
+ArchitectureType : INamedTypeSymbol
+IArchitectureType : INamedTypeSymbol
+IArchitectureModuleType : INamedTypeSymbol
+IArchitectureContext : INamedTypeSymbol
+IReadOnlyList : INamedTypeSymbol
+ContextAwareServiceExtensions : INamedTypeSymbol
+GetModelAttribute : INamedTypeSymbol
+GetModelsAttribute : INamedTypeSymbol
+GetSystemAttribute : INamedTypeSymbol
+GetSystemsAttribute : INamedTypeSymbol
+GetUtilityAttribute : INamedTypeSymbol
+GetUtilitiesAttribute : INamedTypeSymbol
+IsReady : bool
+Create(compilation Compilation) SymbolCache
}
class RegistrationIndex {
-_compilation : Compilation
-_registrations : IReadOnlyDictionary~INamedTypeSymbol,ArchitectureRegistrationData~
-RegistrationIndex(compilation Compilation, registrations IReadOnlyDictionary~INamedTypeSymbol,ArchitectureRegistrationData~)
+Build(compilation Compilation, symbols SymbolCache) RegistrationIndex
+TryGetOwningArchitecture(ownerType INamedTypeSymbol, outArchitectureType INamedTypeSymbol) bool
+HasRegistration(architectureType INamedTypeSymbol, componentKind ComponentKind, serviceType INamedTypeSymbol) bool
-AnalyzeArchitecture(compilation Compilation, symbols SymbolCache, architectureType INamedTypeSymbol) ArchitectureRegistrationData
-AnalyzeModule(compilation Compilation, symbols SymbolCache, moduleType INamedTypeSymbol, data ArchitectureRegistrationData, visitedModules ISet~INamedTypeSymbol~) void
-GetArchitectureRootMethods(architectureType INamedTypeSymbol) IEnumerable~IMethodSymbol~
-GetModuleRootMethods(moduleType INamedTypeSymbol) IEnumerable~IMethodSymbol~
-TryGetInstalledModuleType(invocation IInvocationOperation, symbols SymbolCache, outModuleType INamedTypeSymbol) bool
-TryGetRegistration(invocation IInvocationOperation, symbols SymbolCache, outKind ComponentKind, outRegisteredType INamedTypeSymbol) bool
-TryResolveArchitectureHelperMethod(targetMethod IMethodSymbol, architectureType INamedTypeSymbol, outHelperMethod IMethodSymbol) bool
-TryResolveModuleHelperMethod(targetMethod IMethodSymbol, moduleType INamedTypeSymbol, outHelperMethod IMethodSymbol) bool
}
class ArchitectureRegistrationData {
-_models : HashSet~INamedTypeSymbol~
-_systems : HashSet~INamedTypeSymbol~
-_utilities : HashSet~INamedTypeSymbol~
+IsEmpty : bool
+Add(componentKind ComponentKind, registeredType INamedTypeSymbol) void
+HasRegistration(componentKind ComponentKind, requestedType INamedTypeSymbol, compilation Compilation) bool
+ContainsOwner(ownerType INamedTypeSymbol, compilation Compilation) bool
-GetCollection(componentKind ComponentKind) ISet~INamedTypeSymbol~
}
class SymbolHelpers {
<<static>>
+EnumerateNamedTypes(namespaceSymbol INamespaceSymbol) IEnumerable~INamedTypeSymbol~
+EnumerateTypeHierarchy(type INamedTypeSymbol) IEnumerable~INamedTypeSymbol~
+IsAssignableTo(fromType ITypeSymbol, toType ITypeSymbol) bool
+IsWithinTypeHierarchy(candidateType INamedTypeSymbol, ownerType INamedTypeSymbol) bool
+ResolveHierarchyMethodImplementation(method IMethodSymbol, ownerType INamedTypeSymbol) IMethodSymbol
+GetInvocationOperations(method IMethodSymbol, compilation Compilation) IEnumerable~IInvocationOperation~
+TryGetCreatedType(operation IOperation) INamedTypeSymbol
+IsServiceCompatible(registeredType INamedTypeSymbol, requestedType INamedTypeSymbol, compilation Compilation) bool
+IsOwnershipCompatible(ownerType INamedTypeSymbol, registeredType INamedTypeSymbol, compilation Compilation) bool
}
class ContextRegistrationDiagnostics {
<<static>>
+ModelRegistrationMissing : DiagnosticDescriptor
+SystemRegistrationMissing : DiagnosticDescriptor
+UtilityRegistrationMissing : DiagnosticDescriptor
}
class DiagnosticAnalyzer {
}
class DiagnosticDescriptor {
}
class AnalyzerTestDriver_TAnalyzer_ {
<<static>>
+RunAsync(source string, diagnostics DiagnosticResult[]) Task
}
class CSharpAnalyzerTest_TAnalyzer_DefaultVerifier_ {
+TestState : TestStateType
+DisabledDiagnostics : ICollection~string~
+ExpectedDiagnostics : IList~DiagnosticResult~
+RunAsync() Task
}
class DiagnosticResult {
}
%% Relationships
ContextRegistrationAnalyzer --|> DiagnosticAnalyzer
ContextRegistrationAnalyzer *-- SymbolCache
ContextRegistrationAnalyzer *-- RegistrationIndex
ContextRegistrationAnalyzer o-- BindingRequest
ContextRegistrationAnalyzer ..> ComponentKind
ContextRegistrationAnalyzer ..> ContextRegistrationDiagnostics
RegistrationIndex *-- ArchitectureRegistrationData
RegistrationIndex ..> SymbolHelpers
RegistrationIndex ..> ComponentKind
ArchitectureRegistrationData ..> ComponentKind
ArchitectureRegistrationData ..> SymbolHelpers
SymbolCache ..> PathContests
ContextRegistrationDiagnostics ..> DiagnosticDescriptor
AnalyzerTestDriver_TAnalyzer_ ..> CSharpAnalyzerTest_TAnalyzer_DefaultVerifier_
AnalyzerTestDriver_TAnalyzer_ ..> DiagnosticResult
CSharpAnalyzerTest_TAnalyzer_DefaultVerifier_ ..> AnalyzerTestDriver_TAnalyzer_
文件级变更
提示与命令与 Sourcery 交互
自定义你的体验访问你的 dashboard 可以:
获取帮助Original review guide in EnglishReviewer's GuideAdds a new Roslyn analyzer that checks whether Model/System/Utility context-get usage points have corresponding statically discoverable registrations in their architecture, wires its diagnostics into the package, documents the behavior, and covers it with analyzer tests and a small analyzer test harness helper. Sequence diagram for ContextRegistrationAnalyzer field usage analysissequenceDiagram
participant Compiler as Roslyn_Compiler
participant Analyzer as ContextRegistrationAnalyzer
participant Symbols as SymbolCache
participant Index as RegistrationIndex
participant Field as AnalyzeField
participant Diag as ContextRegistrationDiagnostics
Compiler->>Analyzer: Initialize(context)
Analyzer->>Analyzer: ConfigureGeneratedCodeAnalysis(None)
Analyzer->>Analyzer: EnableConcurrentExecution()
Compiler->>Analyzer: CompilationStartAction(compilationContext)
Analyzer->>Symbols: Create(compilation)
Symbols-->>Analyzer: SymbolCache instance
Analyzer->>Analyzer: Check symbols.IsReady
alt Symbols ready
Analyzer->>Analyzer: Create Lazy RegistrationIndex
Analyzer->>Compiler: RegisterSyntaxNodeAction(AnalyzeField, VariableDeclarator)
Analyzer->>Compiler: RegisterOperationAction(AnalyzeInvocation, Invocation)
else Symbols not ready
Analyzer-->>Compiler: Return (no analysis)
end
loop For each field declarator with attributes
Compiler->>Analyzer: AnalyzeField(SyntaxNodeAnalysisContext)
Analyzer->>Field: TryCreateBindingRequest(fieldSymbol, location, symbols)
alt Attribute matches GetModel/GetSystem/GetUtility
Field-->>Analyzer: BindingRequest(kind, ownerType, serviceType, location)
Analyzer->>Index: registrationIndex.Value (build if first time)
Note over Index: Build(compilation, symbols)
Index->>Index: AnalyzeArchitecture for each Architecture subtype
Index-->>Analyzer: RegistrationIndex instance
Analyzer->>Index: TryGetOwningArchitecture(ownerType, out architectureType)
alt Owning architecture found
Index-->>Analyzer: architectureType
Analyzer->>Index: HasRegistration(architectureType, kind, serviceType)
alt Registration exists
Index-->>Analyzer: true
Analyzer-->>Compiler: No diagnostic
else Registration missing
Index-->>Analyzer: false
Analyzer->>Diag: Select descriptor by kind
Diag-->>Analyzer: DiagnosticDescriptor
Analyzer-->>Compiler: ReportDiagnostic(GF_ContextRegistration_001/002/003)
end
else No unique architecture
Index-->>Analyzer: false
Analyzer-->>Compiler: No diagnostic
end
else Not a supported attribute
Field-->>Analyzer: no request
Analyzer-->>Compiler: Return
end
end
Class diagram for ContextRegistrationAnalyzer and related typesclassDiagram
direction LR
class ContextRegistrationAnalyzer {
<<DiagnosticAnalyzer>>
+SupportedDiagnostics : ImmutableArray~DiagnosticDescriptor~
+Initialize(context AnalysisContext) void
-AnalyzeField(context SyntaxNodeAnalysisContext, symbols SymbolCache, registrationIndex RegistrationIndex) void
-AnalyzeInvocation(context OperationAnalysisContext, symbols SymbolCache, registrationIndex RegistrationIndex) void
-ReportMissingRegistration(context SyntaxNodeAnalysisContext, registrationIndex RegistrationIndex, request BindingRequest) void
-ReportMissingRegistration(context OperationAnalysisContext, registrationIndex RegistrationIndex, request BindingRequest) void
-CreateMissingRegistrationDiagnostic(request BindingRequest, architectureType INamedTypeSymbol) Diagnostic
-TryCreateBindingRequest(fieldSymbol IFieldSymbol, location Location, symbols SymbolCache, outRequest BindingRequest) bool
-TryCreateBindingRequest(invocation IInvocationOperation, ownerType INamedTypeSymbol, symbols SymbolCache, outRequest BindingRequest) bool
-TryMapAttribute(attributeType INamedTypeSymbol, symbols SymbolCache, outKind ComponentKind, outExpectsCollection bool) bool
-IsSupportedGetInvocationTarget(targetMethod IMethodSymbol, symbols SymbolCache) bool
-TryGetCollectionElementType(fieldType ITypeSymbol, symbols SymbolCache) INamedTypeSymbol
-_contextAwareBindingNames : IReadOnlyDictionary~string,ComponentKind~
}
class ComponentKind {
<<enum>>
Model
System
Utility
}
class BindingRequest {
<<record struct>>
+Kind : ComponentKind
+OwnerType : INamedTypeSymbol
+ServiceType : INamedTypeSymbol
+Location : Location
}
class SymbolCache {
-SymbolCache(architectureType INamedTypeSymbol, iArchitectureType INamedTypeSymbol, iArchitectureModuleType INamedTypeSymbol, iArchitectureContextType INamedTypeSymbol, iReadOnlyListType INamedTypeSymbol, contextAwareServiceExtensionsType INamedTypeSymbol, getModelAttribute INamedTypeSymbol, getModelsAttribute INamedTypeSymbol, getSystemAttribute INamedTypeSymbol, getSystemsAttribute INamedTypeSymbol, getUtilityAttribute INamedTypeSymbol, getUtilitiesAttribute INamedTypeSymbol)
+ArchitectureType : INamedTypeSymbol
+IArchitectureType : INamedTypeSymbol
+IArchitectureModuleType : INamedTypeSymbol
+IArchitectureContext : INamedTypeSymbol
+IReadOnlyList : INamedTypeSymbol
+ContextAwareServiceExtensions : INamedTypeSymbol
+GetModelAttribute : INamedTypeSymbol
+GetModelsAttribute : INamedTypeSymbol
+GetSystemAttribute : INamedTypeSymbol
+GetSystemsAttribute : INamedTypeSymbol
+GetUtilityAttribute : INamedTypeSymbol
+GetUtilitiesAttribute : INamedTypeSymbol
+IsReady : bool
+Create(compilation Compilation) SymbolCache
}
class RegistrationIndex {
-_compilation : Compilation
-_registrations : IReadOnlyDictionary~INamedTypeSymbol,ArchitectureRegistrationData~
-RegistrationIndex(compilation Compilation, registrations IReadOnlyDictionary~INamedTypeSymbol,ArchitectureRegistrationData~)
+Build(compilation Compilation, symbols SymbolCache) RegistrationIndex
+TryGetOwningArchitecture(ownerType INamedTypeSymbol, outArchitectureType INamedTypeSymbol) bool
+HasRegistration(architectureType INamedTypeSymbol, componentKind ComponentKind, serviceType INamedTypeSymbol) bool
-AnalyzeArchitecture(compilation Compilation, symbols SymbolCache, architectureType INamedTypeSymbol) ArchitectureRegistrationData
-AnalyzeModule(compilation Compilation, symbols SymbolCache, moduleType INamedTypeSymbol, data ArchitectureRegistrationData, visitedModules ISet~INamedTypeSymbol~) void
-GetArchitectureRootMethods(architectureType INamedTypeSymbol) IEnumerable~IMethodSymbol~
-GetModuleRootMethods(moduleType INamedTypeSymbol) IEnumerable~IMethodSymbol~
-TryGetInstalledModuleType(invocation IInvocationOperation, symbols SymbolCache, outModuleType INamedTypeSymbol) bool
-TryGetRegistration(invocation IInvocationOperation, symbols SymbolCache, outKind ComponentKind, outRegisteredType INamedTypeSymbol) bool
-TryResolveArchitectureHelperMethod(targetMethod IMethodSymbol, architectureType INamedTypeSymbol, outHelperMethod IMethodSymbol) bool
-TryResolveModuleHelperMethod(targetMethod IMethodSymbol, moduleType INamedTypeSymbol, outHelperMethod IMethodSymbol) bool
}
class ArchitectureRegistrationData {
-_models : HashSet~INamedTypeSymbol~
-_systems : HashSet~INamedTypeSymbol~
-_utilities : HashSet~INamedTypeSymbol~
+IsEmpty : bool
+Add(componentKind ComponentKind, registeredType INamedTypeSymbol) void
+HasRegistration(componentKind ComponentKind, requestedType INamedTypeSymbol, compilation Compilation) bool
+ContainsOwner(ownerType INamedTypeSymbol, compilation Compilation) bool
-GetCollection(componentKind ComponentKind) ISet~INamedTypeSymbol~
}
class SymbolHelpers {
<<static>>
+EnumerateNamedTypes(namespaceSymbol INamespaceSymbol) IEnumerable~INamedTypeSymbol~
+EnumerateTypeHierarchy(type INamedTypeSymbol) IEnumerable~INamedTypeSymbol~
+IsAssignableTo(fromType ITypeSymbol, toType ITypeSymbol) bool
+IsWithinTypeHierarchy(candidateType INamedTypeSymbol, ownerType INamedTypeSymbol) bool
+ResolveHierarchyMethodImplementation(method IMethodSymbol, ownerType INamedTypeSymbol) IMethodSymbol
+GetInvocationOperations(method IMethodSymbol, compilation Compilation) IEnumerable~IInvocationOperation~
+TryGetCreatedType(operation IOperation) INamedTypeSymbol
+IsServiceCompatible(registeredType INamedTypeSymbol, requestedType INamedTypeSymbol, compilation Compilation) bool
+IsOwnershipCompatible(ownerType INamedTypeSymbol, registeredType INamedTypeSymbol, compilation Compilation) bool
}
class ContextRegistrationDiagnostics {
<<static>>
+ModelRegistrationMissing : DiagnosticDescriptor
+SystemRegistrationMissing : DiagnosticDescriptor
+UtilityRegistrationMissing : DiagnosticDescriptor
}
class DiagnosticAnalyzer {
}
class DiagnosticDescriptor {
}
class AnalyzerTestDriver_TAnalyzer_ {
<<static>>
+RunAsync(source string, diagnostics DiagnosticResult[]) Task
}
class CSharpAnalyzerTest_TAnalyzer_DefaultVerifier_ {
+TestState : TestStateType
+DisabledDiagnostics : ICollection~string~
+ExpectedDiagnostics : IList~DiagnosticResult~
+RunAsync() Task
}
class DiagnosticResult {
}
%% Relationships
ContextRegistrationAnalyzer --|> DiagnosticAnalyzer
ContextRegistrationAnalyzer *-- SymbolCache
ContextRegistrationAnalyzer *-- RegistrationIndex
ContextRegistrationAnalyzer o-- BindingRequest
ContextRegistrationAnalyzer ..> ComponentKind
ContextRegistrationAnalyzer ..> ContextRegistrationDiagnostics
RegistrationIndex *-- ArchitectureRegistrationData
RegistrationIndex ..> SymbolHelpers
RegistrationIndex ..> ComponentKind
ArchitectureRegistrationData ..> ComponentKind
ArchitectureRegistrationData ..> SymbolHelpers
SymbolCache ..> PathContests
ContextRegistrationDiagnostics ..> DiagnosticDescriptor
AnalyzerTestDriver_TAnalyzer_ ..> CSharpAnalyzerTest_TAnalyzer_DefaultVerifier_
AnalyzerTestDriver_TAnalyzer_ ..> DiagnosticResult
CSharpAnalyzerTest_TAnalyzer_DefaultVerifier_ ..> AnalyzerTestDriver_TAnalyzer_
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@codex review |
There was a problem hiding this comment.
嗨 - 我发现了 1 个问题
给 AI Agent 的提示
Please address the comments from this code review:
## 单独评论
### 评论 1
<location path="docs/zh-CN/source-generators/context-get-generator.md" line_range="645" />
<code_context>
+- `GF_ContextRegistration_002`:`System` 使用点未找到静态可见注册
+- `GF_ContextRegistration_003`:`Utility` 使用点未找到静态可见注册
+
+这个分析器的目标是提供稳定提示,而不是完整模拟运行时 DI 图。以下场景默认不做强推断:
+
+- 运行时条件分支控制的注册
</code_context>
<issue_to_address>
**建议(拼写):** 建议将“强推断”改为“强行推断”,与 README 中的描述保持一致并使表述更自然。
README 的“注册分析器”章节已经采用“不会强行推断”的表述,这里建议改为“以下场景默认不做强行推断:”,以统一术语并使语句更自然。
```suggestion
这个分析器的目标是提供稳定提示,而不是完整模拟运行时 DI 图。以下场景默认不做强行推断:
```
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/zh-CN/source-generators/context-get-generator.md" line_range="645" />
<code_context>
+- `GF_ContextRegistration_002`:`System` 使用点未找到静态可见注册
+- `GF_ContextRegistration_003`:`Utility` 使用点未找到静态可见注册
+
+这个分析器的目标是提供稳定提示,而不是完整模拟运行时 DI 图。以下场景默认不做强推断:
+
+- 运行时条件分支控制的注册
</code_context>
<issue_to_address>
**suggestion (typo):** 建议将“强推断”改为“强行推断”,与 README 中的描述保持一致并使表述更自然。
README 的“注册分析器”章节已经采用“不会强行推断”的表述,这里建议改为“以下场景默认不做强行推断:”,以统一术语并使语句更自然。
```suggestion
这个分析器的目标是提供稳定提示,而不是完整模拟运行时 DI 图。以下场景默认不做强行推断:
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 将“强推断”更正为“强行推断”以提高表述准确性
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8eaf837327
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| helperMethod = targetMethod.DeclaringSyntaxReferences.Length > 0 && !targetMethod.IsAbstract | ||
| ? targetMethod | ||
| : SymbolHelpers.ResolveHierarchyMethodImplementation(targetMethod, architectureType) ?? targetMethod; |
There was a problem hiding this comment.
Resolve overridden architecture helpers during call traversal
When a root method (for example an inherited OnInitialize) calls a virtual helper, this branch keeps the base targetMethod whenever it has source, instead of resolving the implementation on the concrete architectureType. In architectures that register components only in derived overrides, those registrations are missed and the analyzer emits false GF_ContextRegistration_* warnings for valid GetModel/GetSystem/GetUtility usage.
Useful? React with 👍 / 👎.
| helperMethod = targetMethod.DeclaringSyntaxReferences.Length > 0 && !targetMethod.IsAbstract | ||
| ? targetMethod | ||
| : SymbolHelpers.ResolveHierarchyMethodImplementation(targetMethod, moduleType) ?? targetMethod; |
There was a problem hiding this comment.
Follow overridden module helpers when analyzing Install paths
This has the same override-resolution problem for modules: if Install(...) is inherited from a base module and delegates to a virtual helper, keeping the base method symbol here skips registrations that are implemented only in the derived override. As a result, InstallModule(new DerivedModule()) can be analyzed as if it registered nothing, producing false missing-registration warnings downstream.
Useful? React with 👍 / 👎.
Summary by Sourcery
添加一个 Roslyn 分析器,用于验证上下文绑定模型、系统和工具的静态注册,并为新的注册可见性诊断和行为编写文档。
Enhancements:
ContextRegistrationAnalyzer,通过检查字段注入特性和GetX调用,确保被引用的服务在其架构内具有可静态发现的注册。Documentation:
Tests:
Original summary in English
Summary by Sourcery
Add a Roslyn analyzer that validates static registrations for context-bound models, systems, and utilities, and document the new registration visibility diagnostics and behavior.
Enhancements:
Documentation:
Tests: