Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dameng324
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings December 17, 2025 15:21
@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Namespace Resolution for Initializers: Introduced ExpressionEmitter to correctly resolve and emit fully qualified type names for property and field initializers in generated code, fixing a potential namespace issue.
  • Roslyn Version Update: Upgraded Microsoft.CodeAnalysis.CSharp to 4.14.0 and Microsoft.CodeAnalysis.Analyzers to 3.11.0, along with enabling extended analyzer rules.
  • Code Generation Refinements: Replaced Environment.NewLine with a constant NewLine for consistency and added CS0219 to the list of suppressed warnings in generated files.
  • Improved Initializer Handling: Enhanced the generated ProtoReader logic to correctly apply default initializers for members that are not explicitly present in the protobuf message, ensuring robust deserialization.
  • Comprehensive Initializer Tests: Added a new test suite (InitializerTests.cs) to thoroughly validate the correct generation and parsing of various complex property and field initializers.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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'.

Copy link
Contributor

Copilot AI left a 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 ExpressionEmitter to 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
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.14%. Comparing base (2d3ee79) to head (f637f6a).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link


BenchmarkDotNet v0.15.3, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100
  [Host]    : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.11 (9.0.11, 9.0.1125.51716), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Deserialize_ProtoBuf_net .NET 10.0 .NET 10.0 757.4 μs 5.93 μs 5.54 μs 1.26 562 KB 0.88
Deserialize_GoogleProtoBuf .NET 10.0 .NET 10.0 622.2 μs 3.81 μs 3.38 μs 1.04 648.7 KB 1.01
Deserialize_LightProto .NET 10.0 .NET 10.0 599.5 μs 4.77 μs 3.99 μs 1.00 639.98 KB 1.00
Deserialize_ProtoBuf_net .NET 8.0 .NET 8.0 908.7 μs 5.41 μs 4.79 μs 1.43 562 KB 0.88
Deserialize_GoogleProtoBuf .NET 8.0 .NET 8.0 821.1 μs 3.78 μs 3.54 μs 1.29 648.7 KB 1.01
Deserialize_LightProto .NET 8.0 .NET 8.0 637.6 μs 5.64 μs 5.00 μs 1.00 639.98 KB 1.00
Deserialize_ProtoBuf_net .NET 9.0 .NET 9.0 833.8 μs 4.63 μs 4.33 μs 1.35 562 KB 0.88
Deserialize_GoogleProtoBuf .NET 9.0 .NET 9.0 711.3 μs 2.48 μs 2.07 μs 1.15 648.7 KB 1.01
Deserialize_LightProto .NET 9.0 .NET 9.0 617.7 μs 3.40 μs 3.02 μs 1.00 639.98 KB 1.00

BenchmarkDotNet v0.15.3, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.100
  [Host]    : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.1 (10.0.1, 10.0.125.57005), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.22 (8.0.22, 8.0.2225.52707), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.11 (9.0.11, 9.0.1125.51716), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Serialize_ProtoBuf_net .NET 10.0 .NET 10.0 902.3 μs 2.64 μs 2.34 μs 1.31 526.41 KB 1.03
Serialize_GoogleProtoBuf .NET 10.0 .NET 10.0 783.4 μs 5.67 μs 5.30 μs 1.14 512.95 KB 1.00
Serialize_LightProto .NET 10.0 .NET 10.0 686.9 μs 2.02 μs 1.89 μs 1.00 512.95 KB 1.00
Serialize_ProtoBuf_net .NET 8.0 .NET 8.0 1,075.3 μs 1.95 μs 1.82 μs 1.44 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 8.0 .NET 8.0 806.0 μs 5.04 μs 4.72 μs 1.08 512.95 KB 1.00
Serialize_LightProto .NET 8.0 .NET 8.0 747.2 μs 2.45 μs 2.29 μs 1.00 512.95 KB 1.00
Serialize_ProtoBuf_net .NET 9.0 .NET 9.0 975.5 μs 2.60 μs 2.03 μs 1.27 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 9.0 .NET 9.0 815.5 μs 3.39 μs 3.17 μs 1.07 512.95 KB 1.00
Serialize_LightProto .NET 9.0 .NET 9.0 765.1 μs 7.60 μs 7.11 μs 1.00 512.95 KB 1.00

@dameng324 dameng324 merged commit 7e05ceb into main Dec 18, 2025
8 checks passed
@dameng324 dameng324 deleted the fix-initializer-namespace-issue branch December 18, 2025 01:06
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.

2 participants