Skip to content

Conversation

@gunpal5
Copy link
Collaborator

@gunpal5 gunpal5 commented Dec 26, 2025

Summary

  • Fixed source generator failing with "Inconsistent syntax tree features" error when building projects with PublishAot enabled
  • The issue was that SymbolGenerator.cs only preserved the language version when creating new syntax trees, but AOT compilation requires other parse options (like Features) to be preserved as well

Changes

  • Modified GenerateParameterBasedClassSymbol and GenerateToolJsonSerializerContext to get full parse options from an existing syntax tree in the compilation
  • Removed unused variables and cleaned up code formatting

Test plan

  • All existing tests pass (19 tests: AotTests, UnitTests, SnapshotTests)
  • AotConsole project now builds successfully with PublishAot
  • AotConsole runs without errors

Summary by CodeRabbit

  • Refactor
    • Optimized parse option handling to reuse existing configuration when available, reducing redundant processing in schema generation.

✏️ Tip: You can customize this high-level summary in your review settings.

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.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

@coderabbitai
Copy link

coderabbitai bot commented Dec 26, 2025

Walkthrough

This 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

Cohort / File(s) Summary
Parse Options Refactoring
src/libs/CSharpToJsonSchema.Generators/Conversion/SymbolGenerator.cs
Modifies GenerateParameterBasedClassSymbol and GenerateToolJsonSerializerContext to reuse parse options from existing syntax trees when available, falling back to language-version-based defaults. Removes temporary assembly naming configuration (TemporaryAssembly) in both methods.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 With parse options now passed hand to hand,
We reuse what already has been planned,
No temporary names to clutter the way,
Just cleaner code—hooray, hooray!
The syntax trees dance, both old and new,
Refactored with care, through and through. 🌳

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: preserving parse options to fix AOT compilation compatibility issues, which is the core problem and solution described in the PR objectives.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 106158d and 30bf6a1.

📒 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.

@gunpal5 gunpal5 merged commit 0c34f04 into tryAGI:main Dec 26, 2025
3 of 4 checks passed
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