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
492 stars 190 forks source link

Cannot navigate to Nested Razor Component #10658

Open garrettlondon1 opened 2 months ago

garrettlondon1 commented 2 months ago

Is there an existing issue for this?

Describe the bug

When nesting razor components using .filenesting.json settings, you are unable to navigate to the component using the underscore as the reference.

https://github.com/user-attachments/assets/d617d159-a635-46e0-8806-d05411d734d5

Expected Behavior

Navigating to the sub component works properly

Steps To Reproduce

Use filesettings for nesting, try to navigate to a subcomponent

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

garrettlondon1 commented 2 months ago

Also, @danroth27 I think the .NET team (happy to help), should provide some prescriptive guidance around this.

It's hard to work with the .filenesting.json settings trying to get .razor, .razor.cs, .cs, and all sub .Name.cs files to group together like so

Screenshot 2024-07-20 at 12 41 22 PM

Below are my .filenesting.json settings

Screenshot 2024-07-20 at 12 41 33 PM

Prescriptive guidance from the .NET team on how to handle this nesting for maximum productivity will help the community a ton and provide advanced guidance to handle Views, code behind, viewmodels, and any other classes that should be tightly coupled to a component.

garrettlondon1 commented 2 months ago

Have improved it a bit with:

Screenshot 2024-07-20 at 12 45 33 PM Screenshot 2024-07-20 at 12 45 27 PM
javiercn commented 2 months ago

@garrettlondon1 thanks for contacting us.

Moving this to the razor repo as this seems to be tooling related. As for the comment on us offering prescriptive guidance, this is an area where we normally avoid having a concrete opinion (as there are many ways) and I suspect the majority of people will not be nesting things the way you are probably doing it.

If you come up with a pattern that works for you feel free to talk about it and promote it, however in general, we don't have an opinion about this beyond the basic nesting that the IDE offers.

davidwengier commented 2 months ago

I suspect this bug has nothing to do with nesting, and is just a due to the . in the filename. The method where this probably needs to be accounted for is currently pretty simple: https://github.com/dotnet/razor/blob/main/src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Extensions/IDocumentSnapshotExtensions.cs#L52-L61