-
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: preserve parse options for AOT compilation compatibility #69
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
fix: preserve parse options for AOT compilation compatibility #69
Conversation
When creating syntax trees in the source generator, only the language version was being preserved. This caused "Inconsistent syntax tree features" errors when building projects with PublishAot enabled, as AOT compilation adds special features to parse options. The fix gets the full parse options from an existing syntax tree in the compilation, preserving all features including those needed for AOT compilation.
|
Gunpal Jain seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
WalkthroughThis change refactors parse options construction in SymbolGenerator to prioritize reusing options from existing syntax trees with fallback to language-version defaults. It removes temporary assembly naming configuration code from two methods. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/libs/CSharpToJsonSchema.Generators/Conversion/SymbolGenerator.cs (1)
119-122: Consider extracting shared parse options logic.This logic is duplicated from
GenerateParameterBasedClassSymbol. For maintainability, you could extract it into a helper method. However, given the simplicity and the fact that it's only two occurrences, this is optional.🔎 Optional helper method
private static CSharpParseOptions GetParseOptions(Compilation compilation) { return compilation.SyntaxTrees.FirstOrDefault()?.Options as CSharpParseOptions ?? CSharpParseOptions.Default.WithLanguageVersion(compilation.GetLanguageVersion() ?? LanguageVersion.Default); }Then use in both methods:
-var parseOptions = originalCompilation.SyntaxTrees.FirstOrDefault()?.Options as CSharpParseOptions - ?? CSharpParseOptions.Default.WithLanguageVersion(originalCompilation.GetLanguageVersion() ?? LanguageVersion.Default); +var parseOptions = GetParseOptions(originalCompilation);
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/libs/CSharpToJsonSchema.Generators/Conversion/SymbolGenerator.cs
🧰 Additional context used
🧬 Code graph analysis (1)
src/libs/CSharpToJsonSchema.Generators/Conversion/SymbolGenerator.cs (1)
src/libs/CSharpToJsonSchema.Generators/JsonGen/Helpers/RoslynExtensions.cs (1)
LanguageVersion(23-24)
🔇 Additional comments (1)
src/libs/CSharpToJsonSchema.Generators/Conversion/SymbolGenerator.cs (1)
74-77: LGTM! Correctly preserves parse options for AOT compatibility.The logic properly prioritizes reusing parse options from an existing syntax tree while providing a sensible fallback. This ensures AOT-specific features are preserved when creating new syntax trees.
Summary
PublishAotenabledSymbolGenerator.csonly preserved the language version when creating new syntax trees, but AOT compilation requires other parse options (likeFeatures) to be preserved as wellChanges
GenerateParameterBasedClassSymbolandGenerateToolJsonSerializerContextto get full parse options from an existing syntax tree in the compilationTest plan
PublishAotSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.