Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blazor VS Format Document breaks formatting #65228

Open
omuleanu opened this issue Sep 16, 2022 · 3 comments
Open

blazor VS Format Document breaks formatting #65228

omuleanu opened this issue Sep 16, 2022 · 3 comments
Assignees
Labels
Area-IDE IDE-Formatter Code formatter and/or smart indent

Comments

@omuleanu
Copy link

omuleanu commented Sep 16, 2022

having this code in a .razor.cs file:

    private List<Card> cards = new();
    protected override void OnInitialized()
    {
        cards.Add(new Card()
        {
            Id = 1,
            Items = new()
            {
                new (){ Id = 1, Name = "item 1" },
                new (){ Id = 2, Name = "item 2" },
                new (){ Id = 3, Name = "item 3" }
            }
        });
    }

    public class Card
    {
        public int Id { get; set; }
        public List<CardItem> Items { get; set; }
    }

    public class CardItem
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

in latest version of VS2022 .net 6 blazor server app,
hit Ctrl + K, Ctr + D,
and the first method will look like this:

    protected override void OnInitialized()
    {
        cards.Add(new Card()
            {
                Id = 1,
                Items = new()
            {
                new (){ Id = 1, Name = "item 1" },
                new (){ Id = 2, Name = "item 2" },
                new (){ Id = 3, Name = "item 3" }
            }
            });
    }

note how the { } characters lost their relative distance
the same issue will occur when pasting this code (auto formatting I presume)

@chsienki chsienki transferred this issue from dotnet/razor-compiler Oct 28, 2022
@ghost ghost added the untriaged Issues and PRs which have not yet been triaged by a lead label Oct 28, 2022
@ghost ghost removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 3, 2022
@davidwengier
Copy link
Contributor

@omuleanu Can you confirm what file type you were using when you saw this issue? You said .razor.cs, which would mean this is a Roslyn issue, and we'll want to trasfer it there.

I suspect this is "by design" though, per #8269 as Roslyn doesn't format object or collection initializers, so there is no concept of "relative distance"

@omuleanu
Copy link
Author

omuleanu commented Nov 4, 2022

@davidwengier yes, .razor.cs (Blazor)

@davidwengier
Copy link
Contributor

A .razor.cs file is actually a normal C# file, as far as the editor goes, so I'll move this issue to Roslyn.

@davidwengier davidwengier transferred this issue from dotnet/razor Nov 4, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 4, 2022
@jasonmalinowski jasonmalinowski removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 4, 2022
@CyrusNajmabadi CyrusNajmabadi added the IDE-Formatter Code formatter and/or smart indent label Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE IDE-Formatter Code formatter and/or smart indent
Projects
None yet
Development

No branches or pull requests

5 participants