-
Notifications
You must be signed in to change notification settings - Fork 2
Fix Propery/Field Initializer code’s namespace issue #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @dameng324, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the robustness of the code generation process by addressing a critical namespace resolution issue affecting property and field initializers. It introduces a dedicated expression emitter to ensure that all generated type references are fully qualified, preventing compilation errors in diverse project contexts. Beyond this core fix, the update also brings the project's Roslyn dependencies up to date, refines code generation formatting, and includes extensive new tests to guarantee the reliability of initializer handling during serialization and deserialization. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request fixes an issue with property and field initializer generation by introducing a new ExpressionEmitter class. This is a solid improvement for correctly handling various initializer expressions. The new tests in InitializerTests.cs are a great addition and cover many scenarios.
I've identified a critical bug related to how initializers are retrieved for fields declared on the same line. I've also found a few areas for improvement, such as cleaning up leftover debug code in the new ExpressionEmitter, fixing a minor formatting issue in the generated code, and completing the test assertions.
By the way, there's a small typo in the pull request title: 'Propery' should be 'Property'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes namespace resolution issues in property and field initializer code generation by introducing a new ExpressionEmitter class that properly handles fully qualified type names and method calls in initializer expressions.
Key Changes:
- Introduced
ExpressionEmitterto emit initializer expressions with fully qualified names, preventing namespace ambiguity issues - Modified the code generator to track all field values during deserialization and apply initializers only when fields are not present in the input
- Updated Microsoft.CodeAnalysis.CSharp package from 4.3.0 to 4.14.0 and Microsoft.CodeAnalysis.Analyzers from 3.3.3 to 3.11.0
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 13 comments.
| File | Description |
|---|---|
| tests/LightProto.Tests/Parsers/InitializerTests.cs | Adds comprehensive test cases for various property initializer scenarios including literal values, default expressions, collection expressions, LINQ expressions, and method calls |
| src/LightProto.Generator/LightProtoGenerator.cs | Updates initializer handling to use ExpressionEmitter for proper namespace resolution, changes all local variables to initialize with 'default', adds HasValue tracking for all members, and replaces Environment.NewLine with a constant |
| src/LightProto.Generator/LightProto.Generator.csproj | Updates package dependencies to newer versions and adds EnforceExtendedAnalyzerRules property |
| src/LightProto.Generator/ExpressionEmitor.cs | Introduces new ExpressionEmitter class that handles various expression types and emits them with fully qualified type names to avoid namespace conflicts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactored ExpressionEmitter to handle null type and symbol cases more gracefully, returning the original expression string instead of commented code. Fixed formatting in LightProtoGenerator for generated assignment expressions. Updated InitializerTests to add new test cases, remove duplicate ProtoContract attribute, and disable ProtoBuf-net serialization/deserialization for the test class.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #131 +/- ##
=======================================
Coverage 98.14% 98.14%
=======================================
Files 98 98
Lines 1993 1993
Branches 217 217
=======================================
Hits 1956 1956
Misses 24 24
Partials 13 13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
No description provided.