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

debugging in blazor .razor files hovering variable after dot (.) won't show popup with value #6688

Open vsfeedback opened 2 years ago

vsfeedback commented 2 years ago

This issue has been moved from a ticket on Developer Community.


[severity:It's more difficult to complete my work] when debugging in a .razor file (Blazor) hovering a variable property like this: Model.Prop1 if you hover "Model" the value will show in a popup but if you hover "Prop1" nothing will happen


Original Comments

Feedback Bot on 09/02/2022, 04:44 PM:

(private comment, text removed)

Wenwen Fan [MSFT] on 18/02/2022, 07:53 PM:

(private comment, text removed)

Valentin Plamadeala on 18/02/2022, 08:16 PM:

(private comment, text removed)

Wenwen Fan [MSFT] on 03/08/2022, 07:49 PM:

(private comment, text removed)


Original Solutions

(no solutions)

ryanbrandenburg commented 2 years ago

We'll need a reaction from the platform in order to make this work with LSP.

chrdlx commented 2 years ago

Please fix this one! It's very common in a debug session to try to see values of inner objects, not just the top most... I needed to enable "Use legacy Razor editor for ASP.NET Core" in Visual Studio so I could have a proper debug session.

REDECODE commented 1 year ago

It's not blocking but really annoying.. expecially when, otherwise, I need to inspect the top most object and it has a lot of property and the one that I need to inspect is not one of the first (e.g .Text, .Parent, etc. ).

maryamariyan commented 1 year ago

Steps to Debug/Reproduce:

Expected Behavior

Actual Behaviour

First observation

Steps to debug solution in managed/native mode:

Observation after also inspecting native dependencies:

Expected fix

We'll need to go over the portion of code responsible for creating these expressions in the razor files and make sure the properties are being setup properly.

maryamariyan commented 1 year ago

Overview of investigations

The CS code flow for data tip hover

Hovering over the model.Property in a .cs file properly shows the data tip (compared to the bug reported here happing in a .razor file). The CS logic lands under AbstractVsTextViewFilter.cs#L123-L131 in roslyn. The CS file usecase works well because roslyn has complete knowledge about the syntax tree and has access to the CS text buffer.

Given the hover location indices on the file, the roslyn logic properly transforms input span from VS data model into a Microsoft.CodeAnalysis data model TextSpan, calling into ILanguageDebugInfoService.GetDataTipInfoAsync to get the right range of text span for the property in the CS file, before transforming it back to the VS data model and span.

The razor code flow for data tip hover

RazorLSPTextViewConnectionListener.cs#L344-L345 gets triggered when a model.Property gets hovered over in a razor file.

It's possible to use the ExternalAccessor layer in dotnet/roslyn to indirectly expose ILanguageDebugInfoService.GetDataTipInfoAsync API onto the razor side using commit https://github.com/dotnet/roslyn/commit/caf4c2745d35113322ae37dae6eccd6292b0700ba with the doc directions in https://github.com/dotnet/razor/blob/main/docs/contributing/Roslyn-Debugging.md.

Existing challenge

The core problem we face when trying to use this logic is that the API expects CS text buffer and text documents but on the razor side we only have access to the razor text document and that doesn't translate well. (Commit https://github.com/dotnet/razor/commit/ab2452d7a85358ce8454f88e8d75d29a433513cd illustrates how to use the roslyn logic but proves incomplete because it is missing a proper CS text document provided as input)

Next step to try out is to add a layering change between Microsoft.VisualStudio.LanguageServices.Razor which holds and the razor data tip logic and server/client projects (Microsoft.VisualStudio.LanguageServerClient.Razor and Microsoft.AspNetCore.Razor.LanguageServer) which can be used to make an LSP call to roslyn to get text document information, similar to how proximity logic works. The remaining challenge would be to also think if it is enough to get to a TextDocument using the LSP call or could we use an SyntaxTree instead.

bairog commented 10 months ago

Are there any updates on this issue? The fix just gets delayed. Currently it is planned in version 17.9 (which will most likely be the last or penultimate minor version of the IDE). The bug has existed since reelase and makes debugging much more difficult - please fix it finally. The same functionality worked without problems in VS2019 since release.