dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.01k stars 4.03k forks source link

C# code shown when using "go to definition" should be more readable #64516

Open matteo-prosperi opened 2 years ago

matteo-prosperi commented 2 years ago

Summary

When the "Go to definition" feature of Visual Studio for a .NET type shows decompiled C# code, the code should be made more readable by:

Background and Motivation

Recently I have been observing multiple users trying to write C# code using unfamiliar libraries. I noticed that lots of users employ the "Go to definition" feature of Visual Studio to explore a type and understand how it is used (brows the constructors, factory methods, static properties, etc.) and its documentation. I do the same frequently myself. I observed most of these users being distracted or even overwhelmed by internal members being shown before public members in the decompiled code. Some of them even closed the document altogether. Those who went past the internal members, had to scroll a lot because the entire implementation of each method is shown.

Proposed Feature

Private members at the top of the decompiled code:

image

"Go to definition" for .NET types should show an easily browsable representation of decompiled code. The default presentation should prioritize showing public members, especially constructors and static members first to help the user understanding how the type is used. Method implementations (actual code inside the methods) should be collapsed by default to reduce the amount of scrolling needed to explore the type. These behaviors may be configurable as different users may have different preferences. It would even be possible to have different views (declarations only, full decompilation, etc.) toggleable on the document itself.

Alternative Designs

N/A

jasonmalinowski commented 2 years ago

This is one of those cases the user might still find the old style metadata as source more useful here...

CyrusNajmabadi commented 2 years ago

This is one of those cases the user might still find the old style metadata as source more useful here...

@jasonmalinowski isn't htat possibly by just disabling both of these:

image

Or just choosing to collapse items like so:

image

I'm not sure hwat else we would offer here. note: for decompilation, if there is a preference on member order, i think that should go to ILSpy as they control the decompilation strategy here.

jasonmalinowski commented 2 years ago

@jasonmalinowski isn't htat possibly by just disabling both of these:

Absolutely! I despise those checkboxes since they're clumsy if you want a different view -- you have to close the tab, go into options, change them, F12 again, etc. But that's a separate rant.

@matteo-prosperi Do the checkboxes above help out?

davidwengier commented 2 years ago

Yeah, I agree, the checkboxes are the solution here. There is a long term plan for the editor to provide more control here, so we could tell them we can provide source from Source Link, decompilation, and metadata, and they can decide (based on user preference presumably) which one to show, and allow the user to switch between them etc.

jasonmalinowski commented 2 years ago

@davidwengier What's the editor ask here? New UI or something else?

davidwengier commented 2 years ago

No asks yet, but it was all going to be via LSP, and they were going to orchestrate between different providers, do all of the UI, new commands etc. We would just advertise that we know how to provide source from X sources, RichNav would advertise that they could provide source too, and everything was going to come together wonderfully.

No idea when/if any of that work is still scheduled.

matteo-prosperi commented 2 years ago

@jasonmalinowski isn't htat possibly by just disabling both of these:

Absolutely! I despise those checkboxes since they're clumsy if you want a different view -- you have to close the tab, go into options, change them, F12 again, etc. But that's a separate rant.

@matteo-prosperi Do the checkboxes above help out?

Using those checkboxes brought me back to the old experience where I get a very readable list of methods and properties with collapsed docs and not implementation code at all. Which is what I need 90% of the times I use "Go to definition". So that's good

I am also experiencing a bug where after changing those checkboxes to show the metadata, setting them back to the original value doesn't restore the disassembly behavior. I continue getting the metadata only. Even after restarting VS and creating a new project.

I don't think that using those checkboxes is a good solution:

  1. they are not very discoverable
  2. both the disassembly and the metadata behaviors are useful. You are interested in the metadata 90% of the times. You really want to doublecheck the implementation the other 10%. Having to change the option (even if it worked) would be annoyng.

Either having two separate menu commands or some toggle in the metadata/disassembly document would be best.

Thanks!

davidwengier commented 2 years ago

Microsoft internal issue for the larger experience: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1353785