GithubHelp home page GithubHelp logo

Formatting about razor HOT 54 CLOSED

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024 83
Formatting

from razor.

Comments (54)

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024 21

Hey folks, thought I'd leave a message here and just let you all know that we're hard at work on making Razor formatting reliable, flexible, and more importantly correct πŸ˜†! Please bare with us though, it's an incredibly hard area to get right and we want to make sure we're able to deliver a quality experience for everyone to use. Love all the passion though, please keep leaving your suggestions, insight and ideas!

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024 10

@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 πŸ˜„

from razor.

nextfool avatar nextfool commented on August 22, 2024 10

so there is still no progress for this? after 3 years?....I mean, common you are Microsoft right? even .Net 5 is released, vs code is still not supporting razor files? Is anybody here who develop asp.net projects? how do you live with this problem? I mean, the .cshtml formatting is totally a mess.

from razor.

vchirikov avatar vchirikov commented on August 22, 2024 7

image

from razor.

tuespetre avatar tuespetre commented on August 22, 2024 7

lol ya it's been a while. I'd be super curious as to all of your thoughts on Razor formatting in the latest Visual Studio 2022 builds. We've done loadsssss of work in the area!

/cc @davidwengier

Since first trying preview 6 (and now using preview 7:)

Before formatting:
image
image

After formatting:
image
image

Kinda drives me crazy, lol

from razor.

sanamhub avatar sanamhub commented on August 22, 2024 7

It's pretty sad for developers working on dotnet ecosystem not getting most required features in Microsoft own editor πŸ˜ƒ

You would suggest Visual Studio convincing that, It supports almost all the things out of the box!
Yes.. okay I'm using Visual Studio while working on large projects but it gives me trouble if I need to edit some razor file on the go, an I can't use my Flash VSCode for such tasks 😞

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024 6

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).

from razor.

daniel-scatigno avatar daniel-scatigno commented on August 22, 2024 6

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!

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024 6

Lots of bug fixes as part of https://github.com/dotnet/aspnetcore/issues/26527.

Remaining known issues:

from razor.

ponchautf avatar ponchautf commented on August 22, 2024 6

I don't think we should wait anymore for that.
3 year and Vs Code / Omnisharp is still not able to handle razor markups.
formatting is a mess, many many errors, unstable, unusable.

A definitively give up ans switched to JetBrains rider, expensive but not that much regarding the time wasted with Vs code.

Visual studio for Mac is free but it's also the worst IDE I used
Microsoft : please make Visual studio Mac as goo-d as Visual studio Windows (and don't try to rely/stick too much on Mac os UI : make a good IDE, not a good Mac OS IDE).

VS code i a great text editor but not more than that.
Just good enough for Javascript (and even with JS, there sometime stupid issue)

from razor.

ponchautf avatar ponchautf commented on August 22, 2024 4

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

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024 2

@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)

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024 2

Sounds good. We can backlog this until the prerequisites like dotnet/aspnetcore#14286 are handled.

from razor.

davidwengier avatar davidwengier commented on August 22, 2024 2

Thanks for the info @nastro1995, but I'm going to move your comments to a new issue.

For anyone reading this, its a lot easier for us to track things if you just create new issues for each specific problem, than trying to keep track of huge threads, and the new issues appear in our triage lists etc. so they won't get lost.

Regarding @section directive formatting, there have been a lot of updates since this issue was created (eg #6030 for formatting content, #6402 for formatting Html following a section block, and #6531 for formatting Razor following a section block.

In fact, I'm going to go so far as to say that this issue isn't helping anyone remaining open, and I'm going to close it. If anyone has formatting issues or requests, or indeed any other bug reports or feature requests, please feel free to log new issues for them. Thanks everyone for your participation thus far!

from razor.

matijagrcic avatar matijagrcic commented on August 22, 2024 1

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 ?

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024 1

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!

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024 1

@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.

from razor.

MarkusRodler avatar MarkusRodler commented on August 22, 2024 1

That was also my observation... 😒

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024 1

@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

from razor.

krispetkov avatar krispetkov commented on August 22, 2024 1

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

from razor.

daniel-scatigno avatar daniel-scatigno commented on August 22, 2024 1

@nextfool I totally agree, It's a mess, it gives me a headache every day! Specially with Blazor

from razor.

nextfool avatar nextfool commented on August 22, 2024 1

bump

from razor.

nextfool avatar nextfool commented on August 22, 2024 1

so glad to see they are doing something on this...

from razor.

andrewbusch7 avatar andrewbusch7 commented on August 22, 2024

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.

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024

Yup!

from razor.

matijagrcic avatar matijagrcic commented on August 22, 2024

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

from razor.

enricoreich avatar enricoreich commented on August 22, 2024

Is there any progress on this feature?

from razor.

ponchautf avatar ponchautf commented on August 22, 2024

Hi,

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

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024

@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?

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024

@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.

from razor.

matijagrcic avatar matijagrcic commented on August 22, 2024

@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.

from razor.

ChristopherHaws avatar ChristopherHaws commented on August 22, 2024

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?

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024

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?

from razor.

ChristopherHaws avatar ChristopherHaws commented on August 22, 2024

@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 :)

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024

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

from razor.

nextfool avatar nextfool commented on August 22, 2024

please, is there any progress on this?

from razor.

nextfool avatar nextfool commented on August 22, 2024

please, is there any progress on this?

I would die for having this.

from razor.

matijagrcic avatar matijagrcic commented on August 22, 2024

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/

from razor.

krispetkov avatar krispetkov commented on August 22, 2024

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

from razor.

frankhale avatar frankhale commented on August 22, 2024

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

from razor.

krispetkov avatar krispetkov commented on August 22, 2024

@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

from razor.

MarkusRodler avatar MarkusRodler commented on August 22, 2024

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.

from razor.

frankhale avatar frankhale commented on August 22, 2024

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

image

from razor.

ajaybhargavb avatar ajaybhargavb commented on August 22, 2024

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

from razor.

frankhale avatar frankhale commented on August 22, 2024

(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.

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024

lol ya it's been a while. I'd be super curious as to all of your thoughts on Razor formatting in the latest Visual Studio 2022 builds. We've done loadsssss of work in the area!

/cc @davidwengier

from razor.

vchirikov avatar vchirikov commented on August 22, 2024

If now omnisharp and VS use the same lsp, why don't you update/provide new versions to vscode?
I'd prefer to test it with vs code and it would be nice to have something like latest there..
At the moment razor.format.enable is completely unusable. For example it adds a newline to each line in @code{} (even for empty line) after the format is called.

from razor.

seanjbsol avatar seanjbsol commented on August 22, 2024

I've noteid a weird behaviour in my solution when dealing with razor components. When the autoformat runs (which I can't seem to stop) on the insertion of a ';' character, it moves the caret to the end of the opening '@code {' line.

This is a bit disruptive, particularly in a razor component with over 1000 lines of code.

Going into the settings and changing the editor back to the legacy razor editor fixes that, but the code doesn't look anywhere near as pretty. But I may have to do so until the next update lands and I can try this out again.

from razor.

seanjbsol avatar seanjbsol commented on August 22, 2024

I've also managed to repro when I've created a new blazor server app.

from razor.

NTaylorMullen avatar NTaylorMullen commented on August 22, 2024

I've noteid a weird behaviour in my solution when dealing with razor components. When the autoformat runs (which I can't seem to stop) on the insertion of a ';' character, it moves the caret to the end of the opening '@code {' line.

This is a bit disruptive, particularly in a razor component with over 1000 lines of code.

Oh definitely! This is probably one of the most disruptive bugs we currently have. I'm sorry you're running into it :(. If it helps we have a fix queued up for 17.0.3 (hopefully mid Dec) and in 17.1-Preview2.

That work was tracked here: https://developercommunity.visualstudio.com/t/In-a-blazor-page-razor-adding-semi-c/1574500

from razor.

nextfool avatar nextfool commented on August 22, 2024

bump

from razor.

nastro1995 avatar nastro1995 commented on August 22, 2024

Running latest VS Studio 2022 as of 2022/09/08 version 17.3.3.
Still getting strange cshtml formatting with 'ctrl + k' then 'ctrl + d' to format the current document.

when the html is first and the @Sections are placed below the first @section gets formatted correctly, where any that follow or html that follow bellow those @Sections get messed up indentation.

Before updating to 17.3.3 I had 17.1.* and formatting worked fine then

(tried inputting example code to show what i mean but the formatting gets messed up when i try paste in here

Have a epic day!

from razor.

adrianwright109 avatar adrianwright109 commented on August 22, 2024

(tried inputting example code to show what i mean but the formatting gets messed up when i try paste in here

How about adding screenshots instead?

from razor.

nastro1995 avatar nastro1995 commented on August 22, 2024

Will do, here they are, what is strange all tags have a closing pair, even in _Layout. and all needed closing braces are there to.

Expected 1
expected 1

Actual 1
wrong-auto-formatting 1

Expected 2
expected 2

Actual 2
wrong-auto-formatting 2

from razor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.