Allow components in global namespace
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1954771.
Not sure how common this is, but I would expect that formatting of Razor components in the global namespace would not work. With on-type formatting specifically, editing these files could be a pretty annoying experience.
I would expect that formatting of Razor components in the global namespace would not work.
Is there something I should change to make it work?
I think expecting you to fix the formatting engine is unreasonable. Maybe if we're really lucky, then we'd just need to change the numbers in this line from 2 and 3 to 1 and 2:
https://github.com/dotnet/razor/blob/main/src/Razor/src/Microsoft.AspNetCore.Razor.LanguageServer/Formatting/FormattingSpan.cs#L52
I guess it would be nice to ensure there is some way we can find out if a particular Razor document is in the global namespace? Either a bool, or maybe a "base indent" we can use? That way at least we're set up for success. Personally I don't expect this will be too common that I'd block merging it on formatting being correct. Though having said that, I've no idea what the experience for users would actually be like :)
Oh, so the concern is about indentation? Components in the global namespace are actually still indented as if they were emitted inside namespace block: https://github.com/dotnet/razor/pull/10086/files#diff-38349d3b6effd9eb09b5b2da2152117586045b6e2171fda332b593a705269ea5
That's how they're indented before we ask Roslyn to format the generated code, and then interpret the results.
@dotnet/razor-compiler @dotnet/razor-tooling this is ready for review; thanks
@dotnet/razor-compiler for reviews, thanks