Aspnetcore: Formatting

Created on 4 Aug 2018  路  34Comments  路  Source: dotnet/aspnetcore

Allow Razor documents to be properly formatted.

  • [x] C# formatting

    • [x] Pure C# @code/@functions blocks (https://github.com/dotnet/aspnetcore/issues/19037)

    • [x] @{...} blocks (https://github.com/dotnet/aspnetcore-tooling/pull/2445)

    • [x] Implicit statements, @if(){..} etc (https://github.com/dotnet/aspnetcore/issues/25475)

    • [ ] Implicit/Explicit expression (No plans to do this yet)

    • [ ] Html tag attribute value (No plans to do this yet)

  • [x] Markup formatting (https://github.com/dotnet/aspnetcore-tooling/pull/2445)
  • [x] Razor blocks formatting (https://github.com/dotnet/aspnetcore/issues/25475)
  • [x] C# Format on type (https://github.com/dotnet/aspnetcore/issues/23419)

Bug fixes:

Razor Tooling Big Rock L area-razor.tooling feature

Most helpful comment

Any progress on this? On latest version we have no more "There is no formatter" message but nothing is happening! All my views are a mess, this functionality is a must!

All 34 comments

Looking forward to this! Currently getting There is no document formatter for 'aspnetcorerazor'-files installed.. I assume this will address the issue, as I do have the C# extension installed.

Yup!

Really looking forward to this, any date for it?

Also should aspnetcorerazor be added to the list at https://code.visualstudio.com/docs/languages/identifiers ?

@matijagrcic I wouldn't add it to that list because the end-goal is once Razor is functioning 100% it would take over the current "Razor" identifier. For now to avoid breaking everyone on the planet we've made a separate content type identifier (aspnetcorerazor)

Thanks, makes sense, wasn't sure if that was the case.

Is there any progress on this feature?

@enricoreich Sadly this is planned at least 2 releases out. @danroth27 just pinging you because I noticed all the thumbs up/interest on this one 馃槃

Hi,

Did you have any progress to share about this issue progress?

Did you have any progress to share about this issue progress?

@ponchautf It's definitely one of the most asked for features and it's something we want to accomplish sooner rather than later. That being said we're currently prioritizing other high impact issues such as colorization over this. We're still looking at 2 or so releases out for formatting to land (a few months).

@ajaybhargavb given we're not going to return to formatting (we got @code formatting done for those watching this comment) till post-build how do you feel about us putting this in the backlog and out of In Progress?

Sounds good. We can backlog this until the prerequisites like https://github.com/dotnet/aspnetcore/issues/14286 are handled.

Any progress on this? On latest version we have no more "There is no formatter" message but nothing is happening! All my views are a mess, this functionality is a must!

@zmp2000, we currently have support for formatting C# code inside the @code/@functions block. HTML formatting is not implemented yet but is definitely one of our top priorities for the near future.

@ajaybhargavb this year?
Currently this is the sole reason using vs code for core development is unusable. Remember that preview announcement was last year.

Will this new formatting power the VS also?

UPDATE
Used as experimental in VS since the release of Visual Studio 2019 16.7 Preview 4.

Would this also include the ability to customize code style preferences like we currently can with C# in Visual Studio using the options window or .editorconfig file? If not, is there another issue tracking that?

Would this also include the ability to customize code style preferences like we currently can with C# in Visual Studio using the options window or .editorconfig file? If not, is there another issue tracking that?

What type of code styles are you interested in? I'd imagine C#'s code styles are respected today are they not?

@NTaylorMullen I can think of a few use cases I would use.

  • I would like to be able to have open curly braces on the same line for razor files.
  • In C# we enforce the use of this. but might not want to for razor files since there aren't really constructors in razor files (things are injected using @inject instead of constructors).
  • I would also like a way to enforce the casing of things that are injected using @inject.
  • I personally like putting my @code blocks above the HTML markup, if this could be a preference so that new razor components were created that way would be nice too

I'm sure I could come up with others, but those are some I can think of off the top of my head :)

Ah I see. So sadly this effort doesn't encompass that 馃槩

please, is there any progress on this?

please, is there any progress on this?

I would die for having this.

Still pretty much the same state but the language server is now available in Visual Studio https://devblogs.microsoft.com/aspnet/new-experimental-razor-editor-for-visual-studio/

One more like from me for this feature. Maybe it鈥檚 quite annoying for the team but this is the only reason stopping me from using VS Code as a daily driver, as I鈥檓 using Razor most of the time.

I am seeing weird razor formatting issues where it's easily confused specifically about HTML style markup. Here is a screenshot of VSCode 1.50 with the C# extension. Notice that the Razor formatting is confused about the markup:

If I remove the @foreach block the formatting is no longer confused and displays properly.

image

Razor formatting in VSCode is now available with the latest C# extension (https://github.com/OmniSharp/omnisharp-vscode/releases/tag/v1.23.3).
We're still in the process of ironing out rough edges. Please try it out and provide feedback!

@frankhale, I believe what you are seeing is the same underlying issue as https://github.com/dotnet/aspnetcore/issues/26736. We're looking into fixing this.

@ajaybhargavb I'm with the updated VS Code v1.50.0 and C# Extension v1.23.3 but the formatting is not working for me at all. I haven't changed any default settings of the extension:

0RaY9IwMpH

I have the same formatting bug as already presented above. It is ok for me that it doesn't work right now. But I have a big problem with the auto-formatting on save. I can't disable it. It's running riot.

@MarkusRodler I tried disabling Razor formatting but it doesn't work. The settings under preferences doesn't seem to do anything.

image

That was also my observation... 馃槩

The last version is unusable.
I got many many issue with it:

  • formating not working (and when it works, not accurate at all)
  • autocompletion inject irrelevant tags (I type <div> and it get replaced by <DataAnnotation>)
  • divs inside foreach are underlined in red (why?)
  • mouse over on properties keep displaying "Loading" and nothing else
  • quick navigation using cmd+click work time to time, not always (get a thin blue strip at the top of my code indicating that VS code is searching
  • tags autoclose don't works anymore
  • and many more small issues..

I also requested razor formating but I prefer wait for a stable version.

Is it possible to rollback to the previous omnisharp version?, 1.23.3 it too buggy to work with it

@frankhale @MarkusRodler thanks for trying it out. Something regressed in latest OmniSharp version causing our settings sync to not work. I understand this can be frustrating and we are working with OmniSharp folks on a fix and will get it resolved ASAP. In the meantime, you can disable format on save globally,

image

@KrisPetkov, @ponchautf thanks for trying it out. Can you please file a separate issue with a repro to help investigate more?

@ajaybhargavb sorry for the late response. I will open an issue today

(re: Blazor razor component formatting): On VS Code insiders I'm seeing a different behavior. Some razor components will format correctly and some (I have @if's and @foreach's) will no longer format at all. Even the @code block won't format even though format on save is turned on. The formatting chord CTRL+K, CTRL+D will not force it to format either.

I'm kind of stuck between a rock and a hard place here. Even the formatting of razor components in Visual Studio 2019 using the experimental [yes I know] is buggy and results in so many crashes [gold bar shows and language server will be completely busted resulting in needing to restart VS].

I often find myself switching between VSCode and Visual Studio until the point I can't take one or the other anymore because of the oddities that are happening.

Was this page helpful?
0 / 5 - 0 ratings