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

'Go to definition' doesn't work for component type name in C# #7213

Open DoctorKrolic opened 2 years ago

DoctorKrolic commented 2 years ago

Version used: VS 2022 v17.3 Preview 1

To reproduce:

  1. Create blazor server-side project
  2. Go to App.razor
  3. 'Go to definition' on MainLayout

Expected behavior: I appear in MainLayout.cs

Actual behavior: Nothing happens

Demo: devenv_IWr5k5l1hE

Additional context: Very similar to https://github.com/dotnet/razor-tooling/issues/6399, but in https://github.com/dotnet/razor-tooling/issues/6399 the defenition is .razor file, while here - .cs file

davidwengier commented 2 years ago

Moving this to the compiler. This is failing because Roslyn go-to-def says we should be navigating to the class declaration for the MainLayout class in the generated file, but as there is no source mapping for the type name in that declaration, we can't map that span to the Razor document.

Similar to https://github.com/dotnet/razor-tooling/issues/7099 and https://github.com/dotnet/razor-tooling/issues/7097

danroth27 commented 1 year ago

@chsienki Can we up the priority of this issue? I run into this issue frequently when I'm trying to walk users through the execution of a Blazor Web App and I want to navigate to the definition of the App component from the app.MapRazorComponents<App>() call in Program.cs.

chsienki commented 1 year ago

@jjonescz Can you take a look at this?

davidwengier commented 1 year ago

A quick note, this might need coordination/design with tooling. The issue is the class definition in Goo.razor.g.cs doesn't map to anything in Goo.razor, but thats because there is nothing for it to map to. If something hacky works, like adding a zero length mapping pointing to the start of the .razor file, that would be great, but otherwise we might need to come up with something special that tooling has explicit support for.

chsienki commented 4 months ago

If something hacky works, like adding a zero length mapping pointing to the start of the .razor file, that would be great

Let me try that and see what happens :)

jjonescz commented 4 months ago

If something hacky works, like adding a zero length mapping pointing to the start of the .razor file, that would be great

Let me try that and see what happens :)

@chsienki FYI, I have already tried that and there were problems with renaming IIRC. I think some changes in Roslyn might be necessary.