0

When using Roslyn in the context of a Visual Studio extension, every SyntaxNode object has a location defined in it (type Microsoft.CodeAnalysis.Location).

Is it somehow possible to let Visual Studio navigate to a specific location in the UI?

The EditorFeatures package has some extension methods to retrieve the TextBuffer and Snapshot from the location, but it's still quite some manual work to open the document when needed, etcetera. I have the feeling there is somewhere a method that can do that for me.

https://github.com/dotnet/roslyn/blob/main/src/EditorFeatures/Text/Extensions.cs

TWT
  • 2,511
  • 1
  • 23
  • 37

1 Answers1

0

So if you have a symbol in hand and you just want to do the equivalent of go to definition, you could call this method after MEF importing VisualStudioWorkspace. Otherwise, it doesn't look like we have a public helper in Roslyn anywhere. (We've absolutely got the implementation internally, of course...)

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
  • I don't have a symbol, but a SyntaxNode. GoToDefinition is probably not completely what we want, because that would, for instance, go to the method itself, instead of the invocation of that method. – TWT Oct 22 '21 at 06:06
  • 1
    Yeah then we don't have anything public to help you here. :-( – Jason Malinowski Oct 22 '21 at 20:19