dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

Wrap parameters or chained method calls should be configurable #33872

Open kendrahavens opened 5 years ago

kendrahavens commented 5 years ago

Internal customer ask.

The indent and wrapping behavior on parameters or chained method calls (or any multi-line construct) should be a configuration option and included in editorconfig. There should also be an option to apply these when formatting.

kendrahavens commented 5 years ago

Closed duplicate developer community feedback

Additional notes:

Today we offer to optional wrapping fixes, but do not have a configuration option to just offer the preferred style all the time:

Without indent image

With Indent image

Two Options appear in flyout menu: image

Dweeberly commented 5 years ago

FWIW, I'm particular and possibly peculiar. For long if statements I tend to want to line up conditionals that match levels. For example:

image

Visual studio always wants to help me by reformatting these. I want the format of the code to communicate as much about it's structure as possible. In general, people aren't good at turning waggly-snagals (&&, ||, !) into logic. Ok, maybe it's just me, but I'm people too. In any case there should be an opt out for "if you aren't going to format it like I want, then just don't touch it".

When wrapping functions I do something like this: image

Note the ending lambda will probably make complex formatting "more complexier"

This same thinking also applies to wrapping long mathematical expressions. That's not super common for me, but if I have to split the line I like wrapping it so that sub-expressions at the same level indent the same using the '=' as the root point (like the || lines up under the 'if' above).

alrz commented 2 years ago

Looks like there's no indentation handling here.

            modelBuilder.Entity<MyEntity>()
            .Property(e => e.MyProp)
            .HasMaxLength(15);
davidfenko commented 2 years ago

Looks like there's no indentation handling here.

            modelBuilder.Entity<MyEntity>()
            .Property(e => e.MyProp)
            .HasMaxLength(15);

For the case @alrz mentioned, this is handled nicely on codebeautify.org.

@jmarolf is there some option of looking at how they do this and integrating it in the scope of this issue? It's really the only remaining major issue I'm experiencing with most of the formatting tooling...

brandonh-msft commented 1 year ago

For me, I want the ability to wrap this:

var x = y.GroupBy(i => i.Key.Id, i => i.Key.Version).Where(i => i.Count() > 1).ToImmutableArray();

to this:

var x = y
    .GroupBy(i => i.Key.Id, i => i.Key.Version)
    .Where(i => i.Count() > 1)
    .ToImmutableArray();

hadn't seen this flavor called out in this issue so thought I'd add it.