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
506 stars 196 forks source link

StringSyntax.CssClass #8930

Open En3Tho opened 1 year ago

En3Tho commented 1 year ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I'm not sure where to put this request as it might be an IDE request, might be a sort of blc request (add StringSyntax value) or AspNetCore request (because blazor/css related). Consider these examples in Blazor:

<div class="unconditionalStyle @(someCondition ? "class1" : "class2")">
</div>
<div class="unconditionalStyle @If(condition1, "someClass") @If(condition2, "someAnotherClass1" : "someAnotherClass2")">
</div>

I guess the first one should be automatically inferred as cssClass if possble and highlighted as such. Second one can be augmented with StringSyntax attribute and treat string accordingly. For example ReSharper already supports StringSyntax("css") (not "cssClass") but maybe this can be utilized in VS too.

Describe the solution you'd like

Implement a solution to recognize "cssClass" syntax.

Additional context

No response

davidwengier commented 1 year ago

This is a large feature.

This would have to be a Roslyn component to provide colorization for strings that are tagged with [StringSyntax("css")] like the ASP.NET team has done for routes. That component would have to understand the project, all of the CSS classes available etc (presumably working with Web Tools to get that info) and then the Razor compiler would have to add the attribute to the right spots of generated code.