Skip to content

Conversation

davidwengier
Copy link
Member

Noticed while I was testing an old formatting issue, that we would report diagnostics when Razor comments appear in CSS tags. In general, there is no reason to report a diagnostic in a comment.

@davidwengier davidwengier requested a review from a team as a code owner July 2, 2025 03:47
Copy link
Contributor

@alexgav alexgav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:


var filteredDiagnostics = unmappedDiagnostics
.Where(d =>
!InRazorComment(d, sourceText, syntaxTree) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InRazorComment

Legacy Razor editor used to filter out any diagnostics in style blocks if line contained any Razor span. In relied on projection spans to do so.

I wonder if we can make this more generic and filter out any html diagnostics if it comes from a line that contains any Razor span and is inside of style block or script block. Current LSP HTML editor code can't know where Razor spans are since it just sees plain text.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have various filtering for style blocks etc. when the diagnostics original from a Razor syntax that is likely to be misunderstood:
https://github.com/davidwengier/razor/blob/NoDiagnosticsInComments/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Diagnostics/RazorTranslateDiagnosticsService.cs#L242-L249

Razor comments just seemed like something worth going very broad with.

@davidwengier davidwengier merged commit 2320a67 into dotnet:main Jul 2, 2025
11 checks passed
@davidwengier davidwengier deleted the NoDiagnosticsInComments branch July 2, 2025 21:26
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 2, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants