Skip to content

[WIP] Fix generated classes new line for annotations#1893

Merged
lahma merged 2 commits intomasterfrom
copilot/fix-generated-annotations-new-line
Mar 2, 2026
Merged

[WIP] Fix generated classes new line for annotations#1893
lahma merged 2 commits intomasterfrom
copilot/fix-generated-annotations-new-line

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

  • Fix {%- template Class.Annotations -%}{%- template Class.Annotations %} in Class.liquid (remove trailing - that strips the newline after annotation)
  • Fix {%- template Class.Property.Annotations -%}{%- template Class.Property.Annotations %} in Class.liquid
  • Fix {%- template Enum.Annotations -%}{%- template Enum.Annotations %} in Enum.liquid
  • Update DefaultTemplateFactory.cs cleanup: use Replace("\n__EMPTY-TEMPLATE__\n", "\n") to handle empty annotation templates without introducing blank lines
  • Add test When_custom_class_and_property_annotation_templates_are_used_then_annotations_are_on_separate_lines to verify fix
  • All 212 tests pass (no regressions)
Original prompt

This section details on the original issue you should resolve

<issue_title>Generated classes miss new line when Annotations are used</issue_title>
<issue_description>When using custom/overriden Class.Annotations.liquid and Class.Property.Annotations.liquid, the result is generated on the same line as the class/property.
This is probably caused by the extra - in


and
{%- template Class.Property.Annotations -%}

introduced in #1346

Class.Annotations.liquid:
[System.Runtime.Serialization.DataContract]

Class.Property.Annotations.liquid:
[System.Runtime.Serialization.DataMember]

The output then looks like this:
obrazek
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…tions, Class.Property.Annotations, Enum.Annotations)

Co-authored-by: lahma <171892+lahma@users.noreply.github.com>
@lahma
Copy link
Collaborator

lahma commented Mar 2, 2026

@copilot retry

Copy link
Contributor Author

Copilot AI commented Mar 2, 2026

@copilot retry

The fix is already in place and all 212 tests pass (commit 98104d5). Here's a summary of the changes:

Root cause: The trailing -%} in {%- template Class.Annotations -%} strips the newline between the annotation and the class/property declaration.

Changes made:

  • Class.liquid: Changed {%- template Class.Annotations -%}{%- template Class.Annotations %} and {%- template Class.Property.Annotations -%}{%- template Class.Property.Annotations %}
  • Enum.liquid: Changed {%- template Enum.Annotations -%}{%- template Enum.Annotations %}
  • DefaultTemplateFactory.cs: Added .Replace("\n__EMPTY-TEMPLATE__\n", "\n") before the existing catch-all replacement to cleanly handle the empty-annotation case (default templates are empty, and removing -%} would otherwise introduce a blank line)
  • Added a test in AnnotationsTests.cs that verifies annotations appear on their own lines

Before (bug): [DataContract]public partial class MyClass
After (fix):

[DataContract]
public partial class MyClass

Copilot finished work on behalf of lahma March 2, 2026 10:22
@lahma lahma marked this pull request as ready for review March 2, 2026 15:37
@lahma lahma merged commit 748313b into master Mar 2, 2026
3 checks passed
@lahma lahma deleted the copilot/fix-generated-annotations-new-line branch March 2, 2026 15:38
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.

Generated classes miss new line when Annotations are used

2 participants