1

I have a VS extension with a custom "Code Map" tool window. It displays specific code elements in a tree view control. The tree view nodes support navigation to symbol definition on a double click on the tree node. The navigation uses Roslyn symbols corresponding to tree nodes, and navigates to them.

This all relies on the integration between Visual Studio and Roslyn. Basically, it tries to get location file path and span from Roslyn symbol or node, then use file path to open the file and get Microsoft.VisualStudio.Text.Editor.IWpfTextViewvia VS SDK utilities. Then I use IWpfTextView and location span to move caret to the required location. You can see details on GitHub: https://github.com/Acumatica/Acuminator/blob/dev/src/Acuminator/Acuminator.Vsix/Utils/Navigation/VSDocumentNavigation.cs

This works just fine with symbols declared in the solution but does not work for symbols declared in external assemblies. At the same time, Visual Studio itself navigates to external symbols with F12.

I would like to know if it is possible to repeat the same navigation programmatically with Roslyn and VS SDK.

So far, I have found only the following hints:

5
  • "However, it requires Roslyn project and, therefore, won't work with external symbols." So if I can understand the scenario here, you're trying to navigate to a symbol in metadata, but you don't have any project referencing that DLL? or something else? Commented Sep 16, 2024 at 22:13
  • No, the project is referencing DLL. Commented Sep 16, 2024 at 22:52
  • Perhaps I misinterpreted. I thought that the helper requires symbol's project and won't work for external symbols. Commented Sep 16, 2024 at 22:56
  • @JasonMalinowski it seems that the helper works like a charm. Many thanks for your comment! That greatly helped me! If you add this as an answer I will accept it. Commented Sep 16, 2024 at 23:33
  • Hi @JasonMalinowski, as SENya said, you can add this as an answer. This will help other users who has the same issue and someone else may come along with an even better solution to your problem. Just a reminder. 😊 Commented Sep 20, 2024 at 3:20

1 Answer 1

2

As discussed in the comments, yes, you can just call VisualStudioWorkspace.TryGoToDefinitionAsync(); the Project parameter is simply used for us to help figure out where the symbol came from -- the symbol can still be from metadata or somewhere else.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.