From af15520ea6297508f35f42ed452fe188a39dcee4 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 10 May 2025 09:23:59 +0200 Subject: [PATCH] fix: Restrict commutativity in C# Fixes #224. --- .../failing/methods_with_comments/Base.cs | 20 +++++++++++ .../ExpectedCurrently.cs | 34 +++++++++++++++++++ .../methods_with_comments/ExpectedIdeally.cs | 30 ++++++++++++++++ .../failing/methods_with_comments/Left.cs | 24 +++++++++++++ .../failing/methods_with_comments/README | 3 ++ .../failing/methods_with_comments/Right.cs | 26 ++++++++++++++ src/supported_langs.rs | 25 +++++++++++++- 7 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 examples/csharp/failing/methods_with_comments/Base.cs create mode 100644 examples/csharp/failing/methods_with_comments/ExpectedCurrently.cs create mode 100644 examples/csharp/failing/methods_with_comments/ExpectedIdeally.cs create mode 100644 examples/csharp/failing/methods_with_comments/Left.cs create mode 100644 examples/csharp/failing/methods_with_comments/README create mode 100644 examples/csharp/failing/methods_with_comments/Right.cs diff --git a/examples/csharp/failing/methods_with_comments/Base.cs b/examples/csharp/failing/methods_with_comments/Base.cs new file mode 100644 index 0000000..ae2a989 --- /dev/null +++ b/examples/csharp/failing/methods_with_comments/Base.cs @@ -0,0 +1,20 @@ +// Copyright header + +using System; + +namespace MyNamespace; + +public partial class MyClass : IMyInterface +{ + /// + /// Ctor docs + /// + /// Param docs + public MyClass(IThing1 thing1, IThing2 thing2) + { + _thing1 = thing1; + _thing2 = thing2; + } + + private record MyPrivateRecord(bool Foo); +} diff --git a/examples/csharp/failing/methods_with_comments/ExpectedCurrently.cs b/examples/csharp/failing/methods_with_comments/ExpectedCurrently.cs new file mode 100644 index 0000000..c389a04 --- /dev/null +++ b/examples/csharp/failing/methods_with_comments/ExpectedCurrently.cs @@ -0,0 +1,34 @@ +// Copyright header + +using System; + +namespace MyNamespace; + +public partial class MyClass : IMyInterface +{ + /// + /// Ctor docs + /// + /// Param docs + public MyClass(IThing1 thing1, IThing2 thing2) + { + _thing1 = thing1; + _thing2 = thing2; + } + +<<<<<<< LEFT + /// + /// Record docs + /// + /// Bool arg docs +||||||| BASE +======= + /// + /// Prop docs + /// + [MyCustomAttribute] + public string? MyProp { get; set; } + +>>>>>>> RIGHT + private record MyPrivateRecord(bool Foo); +} diff --git a/examples/csharp/failing/methods_with_comments/ExpectedIdeally.cs b/examples/csharp/failing/methods_with_comments/ExpectedIdeally.cs new file mode 100644 index 0000000..1f8ec98 --- /dev/null +++ b/examples/csharp/failing/methods_with_comments/ExpectedIdeally.cs @@ -0,0 +1,30 @@ +// Copyright header + +using System; + +namespace MyNamespace; + +public partial class MyClass : IMyInterface +{ + /// + /// Ctor docs + /// + /// Param docs + public MyClass(IThing1 thing1, IThing2 thing2) + { + _thing1 = thing1; + _thing2 = thing2; + } + + /// + /// Prop docs + /// + [MyCustomAttribute] + public string? MyProp { get; set; } + + /// + /// Record docs + /// + /// Bool arg docs + private record MyPrivateRecord(bool Foo); +} diff --git a/examples/csharp/failing/methods_with_comments/Left.cs b/examples/csharp/failing/methods_with_comments/Left.cs new file mode 100644 index 0000000..2b3702f --- /dev/null +++ b/examples/csharp/failing/methods_with_comments/Left.cs @@ -0,0 +1,24 @@ +// Copyright header + +using System; + +namespace MyNamespace; + +public partial class MyClass : IMyInterface +{ + /// + /// Ctor docs + /// + /// Param docs + public MyClass(IThing1 thing1, IThing2 thing2) + { + _thing1 = thing1; + _thing2 = thing2; + } + + /// + /// Record docs + /// + /// Bool arg docs + private record MyPrivateRecord(bool Foo); +} diff --git a/examples/csharp/failing/methods_with_comments/README b/examples/csharp/failing/methods_with_comments/README new file mode 100644 index 0000000..db3e2cb --- /dev/null +++ b/examples/csharp/failing/methods_with_comments/README @@ -0,0 +1,3 @@ +Commutativity is restricted because comments are involved. +See https://codeberg.org/mergiraf/mergiraf/issues/224, +https://codeberg.org/mergiraf/mergiraf/issues/322. diff --git a/examples/csharp/failing/methods_with_comments/Right.cs b/examples/csharp/failing/methods_with_comments/Right.cs new file mode 100644 index 0000000..efa2ba8 --- /dev/null +++ b/examples/csharp/failing/methods_with_comments/Right.cs @@ -0,0 +1,26 @@ +// Copyright header + +using System; + +namespace MyNamespace; + +public partial class MyClass : IMyInterface +{ + /// + /// Ctor docs + /// + /// Param docs + public MyClass(IThing1 thing1, IThing2 thing2) + { + _thing1 = thing1; + _thing2 = thing2; + } + + /// + /// Prop docs + /// + [MyCustomAttribute] + public string? MyProp { get; set; } + + private record MyPrivateRecord(bool Foo); +} diff --git a/src/supported_langs.rs b/src/supported_langs.rs index af0ab8c..03d3891 100644 --- a/src/supported_langs.rs +++ b/src/supported_langs.rs @@ -473,7 +473,30 @@ pub static SUPPORTED_LANGUAGES: LazyLock> = LazyLock::new(|| { atomic_nodes: vec![], commutative_parents: vec![ CommutativeParent::without_delimiters("compilation_unit", "\n"), - CommutativeParent::new("declaration_list", "{", "\n", "}"), + CommutativeParent::new("declaration_list", "{", "\n", "}").restricted_to_groups(&[ + &["using_directive"], + &[ + "field_declaration", + "property_declaration", + "event_declaration", + "event_field_declaration", + ], + &[ + "class_declaration", + "struct_declaration", + "enum_declaration", + "delegate_declaration", + "method_declaration", + "record_declaration", + "constructor_declaration", + "destructor_declaration", + "indexer_declaration", + "interface_declaration", + "namespace_declaration", + "operator_declaration", + "conversion_operator_declaration", + ], + ]), CommutativeParent::new("enum_member_declaration_list", "{", ",\n", "}"), ], signatures: vec![ -- 2.47.3