razor icon indicating copy to clipboard operation
razor copied to clipboard

Allow components in global namespace

Open jjonescz opened this issue 1 year ago • 6 comments

Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1954771.

jjonescz avatar Mar 13 '24 15:03 jjonescz

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.

davidwengier avatar Mar 14 '24 10:03 davidwengier

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?

jjonescz avatar Mar 19 '24 08:03 jjonescz

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

davidwengier avatar Mar 19 '24 09:03 davidwengier

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

jjonescz avatar Mar 19 '24 09:03 jjonescz

That's how they're indented before we ask Roslyn to format the generated code, and then interpret the results.

davidwengier avatar Mar 19 '24 10:03 davidwengier

@dotnet/razor-compiler @dotnet/razor-tooling this is ready for review; thanks

jjonescz avatar Mar 22 '24 08:03 jjonescz

@dotnet/razor-compiler for reviews, thanks

jjonescz avatar Apr 08 '24 10:04 jjonescz