dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
505 stars 195 forks source link

Lambda attribute values are not formatted correctly #9777

Open bcheung4589 opened 10 months ago

bcheung4589 commented 10 months ago

NOTE: Previous title was "VS 2022 Razor Editor not formatting HTML "

New Windows 11 Pro install (29/12/2021) with latest Visual Studio 2022 Professional installed. Can't get HTML to format correctly and it doesn't suggest attributes (even simple ones, class, style, etc). C# and JavaScript work. I can get it to work by making 'use legacy razor editor for asp.net core' true. I have used the repair feature already.

https://github.com/dotnet/razor/issues/8006

How about fixing issues and not just closing it after asking a non trivial question that was already answered.

"Fresh Windows 11/VS 2022 install. HTML, Razor and CSHTML are not being formatted. Please verify."

Razor STILL not getting formatted. Its not that complicated, you need a whole repo for this?

image

davidwengier commented 10 months ago

@bcheung4589 Apologies that the tooling is frustrating you, but the reason we ask for more information is because the we have multiple tests and manual test runs that do verify that Html, Razor and CSHTML are being formatted, in the general case. That means that the issue you are running into is possibly specific to the exact combination of components, markup and C# that you have, or some factor of your specific project. Without that extra information we don't have anything to go.

With the image that you have pasted, I can see that you're using a QuickGrid, but its not clear to me what is wrong in the image. Is it that you are expecting spaces around the => in the lambda? If so, it does look like that is a bug we have, and I can reproduce that. However the rest of the formatting engine appears to be working fine for me (eg, if I indent the <Property component by a few tab stops, when I format it returns to where I'd expect it). Are you seeing only that lambda spacing issue? Or other issues?

You say that Html completion also isn't working, and you're not being offered class, style, etc. I see that when I start typing "cl" in a <Property component in VS 17.8.3. Is that the version you're using? Do you see any completion at all? Or do you see some items, but not "class" specifically? Are you trying it on a component, or some other type of element?

This is what I see:

image

We really do want to fix the issues you're seeing, but sadly we need details of what you are experiencing, in what types of context, and what you would expect to happen instead, in order to understand what you're seeing.

bcheung4589 commented 10 months ago

Hi @davidwengier , thank you for the quick and clear response.

I got a bit hot headed because VS was being weird (including the non-formatting part) which happens sometimes and together with the closed issue (and persisting bug) without any real response I got passionate :) my apologies for the rudeness.

You say that Html completion also isn't working, and you're not being offered class, style, etc. I see that when I start typing "cl" in a <Property component in VS 17.8.3. Is that the version you're using? Do you see any completion at all? Or do you see some items, but not "class" specifically? Are you trying it on a component, or some other type of element?

I shouldve formatted my message better with quotes, that part was from the closed referenced issue, but! its also something I sometime do get. Currently I dont have the problem but I'll be more vigilate and document the circumstances and enviroment next time and report it.

If so, it does look like that is a bug we have, and I can reproduce that.

Ok, because this is my actuall issue, but if this is on the radar of the team and being worked on, Ill patiently wait for the updates.

Thank you for the quick reponse! Issue can be closed, no other questions from me.

davidwengier commented 10 months ago

Actually it wasn't on the radar @bcheung4589 so thank you for reporting it! I'll reopen this, and modify the title a bit to represent the issue.

davidwengier commented 10 months ago

To summarize the issue, given a QuickGrid component with a property column defined as something like <PropertyColumn Property="x=>x.Title" /> we are not formatting the attribute value, seemingly at all. Putting the same lambda in a plain C# file adds spaces around the => at least, so we should expect to see those same edits to the Razor file. When formatting the generated C# those edits are made, so it seems we are probably getting them back from Roslyn but failing to apply them.