[PATCH] D74265: [clang-format] Improve handling of C# attributes

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 28 03:35:20 PDT 2021


MyDeveloperDay added a comment.

The second property in a class is putting the property on the same line

  [XmlIgnore] 
  public string property1 { get; set; }
  
  [XmlIgnore] public string property2{ get; set; }

as are all successive properties

Multiple properites are also not getting broken unless they are the first property

  [XmlIgnore] 
  [ScriptIgnore] 
  public string property1 { get; set; }
  
  [XmlIgnore] [ScriptIgnore] public string property2{ get; set; }

Ideally we want this all the time.

  [XmlIgnore] 
  [ScriptIgnore] 
  public string Url { get; set; }

In the original change @jbcoe  I think you were trying to fix the case where `void MethodA([In][Out] ref...` got broken, I presume into

  void MethodA([In]
     [Out] ref

Part of the problem although not a solution was that the `[` of the `[Out]` isn't even actually seen as an TT_AttributeSquare but instead as a TT_ArraySubscriptLSquare

  AnnotatedTokens(L=1):
   M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=0 Name=void L=4 PPK=2 FakeLParens= FakeRParens=0 II=0x1c0f418 Text='void'
   M=0 C=1 T=StartOfName S=1 F=0 B=0 BK=0 P=1020 Name=identifier L=15 PPK=2 FakeLParens= FakeRParens=0 II=0x1c38cb0 Text='myFunction'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=23 Name=l_paren L=16 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='('
   M=0 C=1 T=AttributeSquare S=0 F=0 B=0 BK=0 P=140 Name=l_square L=17 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='['
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=79 Name=identifier L=19 PPK=2 FakeLParens= FakeRParens=0 II=0x1c38cd0 Text='In'
   M=0 C=0 T=AttributeSquare S=0 F=0 B=0 BK=0 P=63 Name=r_square L=20 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=']'
   M=0 C=0 T=ArraySubscriptLSquare S=0 F=0 B=0 BK=0 P=240 Name=l_square L=21 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text='['
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=259 Name=identifier L=24 PPK=2 FakeLParens= FakeRParens=0 II=0x1c38cf0 Text='Out'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=243 Name=r_square L=25 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=']'
   M=0 C=0 T=Unknown S=1 F=0 B=0 BK=0 P=43 Name=identifier L=27 PPK=2 FakeLParens= FakeRParens=0 II=0x1c38d10 Text='a'
   M=0 C=0 T=Unknown S=0 F=0 B=0 BK=0 P=43 Name=r_paren L=28 PPK=2 FakeLParens= FakeRParens=0 II=0x0 Text=')'

That I think you move the handling of the newlines to the parsing rather than in the canBreakBefore/mustBreakBefore (i.e. you wrap the lines when you see it on the function)

But of course a property isn't a function and so this is why its not being handled correctly. Going from the overly aggressive to the the parsing model regressed the behaviour for properties with attributes (which is very common if you use Newtonsoft.Json)

See D103307: [clang-format] successive C# attributes cause line breaking issues <https://reviews.llvm.org/D103307>


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74265/new/

https://reviews.llvm.org/D74265



More information about the cfe-commits mailing list