Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extend the information that provides Intellisense using the Visual Studio SDK?

Tags:

In C# or Vb.Net, using the Visual Studio 2013 SDK, how I could add an additional element on Intellisense when the info of a member is shown?.

My intention is not to add a completion/suggestion element, I would like to add custom additional info below the info that is shown for a member that can throw an exception like a method, function or property (getter/setter), not a keyword.

I read a little bit the members of Microsoft.VisualStudio.Language.Intellisense namespace but I didn't take any clear idea about it.

My goal, with the help I could get here, is to find the answer to develop a simple extension that will add (documented)Exception information for members, something like this:

enter image description here

I wonder to bring back this useful feature in Visual Studio for C#, and add it also for VB.Net, then if successful I'll share it for free with all yours like I did in the past with this useful extension:

  • Snippet Tool - Visual Studio Gallery

Just I comment that because any help could be rewarded for all of us in that way!.


Additionally to my question, and only Additionally, if someone could start guiding me about how to figure out the way to retrieve the Xml documentation of the members ( <exception cref="Exception name"> ) to do this, or maybe a simple way, I would be very grateful.

EDIT:

About the Xml documentation, I get the idea to use the Visual Studio object browser to inspect the exceptions of the member that will be listed by Intellisense instead of messing with Reflection? to get exception info. That could be a better and viable way to do it once I can figure out how to automate the object browser from SDK, but I'm just commenting this, maybe that will be a new question once this question could be solved, because firstly I need to solve this step, I hope so.

like image 793
ElektroStudios Avatar asked Nov 01 '15 11:11

ElektroStudios


People also ask

How do I add IntelliSense to Visual Studio?

You can trigger IntelliSense in any editor window by typing Ctrl+Space or by typing a trigger character (such as the dot character (.)

In which ways can you extend the functionality of Visual Studio?

The two main types of extensions are VSPackages and MEF extensions. In general, VSPackage extensions are used for extensions that use or extend commands, tool windows, and projects. MEF extensions are used to extend or customize the Visual Studio editor.

How do I change autocomplete in Visual Studio?

Go to Tools | Options | Text Editor | C/C++. This dialog displays a window that allows you to toggle Automatic brace completion. Automatic brace completion is the feature where, when you type { , a corresponding } is automatically typed for you.


1 Answers

There are few types of IntelliSence extensibility points that you need to use for each of the following cases:

  • The tool-tip shown when hovering text element is called QuickInfo tool-tip, and can be implemented by yourself via inheriting from IQuickInfoSource interface and creating a matching IIntellisenseController. A full walk-through can be found on MSDN:

    • Example:

      QuickInfo Tool-Tip

    • Make sure to make your IQuickInfoSourceProvider load your IQuickInfoSource before the default Visual-Studio one by using the Order attribute - otherwise the default QuickInfo is not going to be shown:

      [Order(Before = "Default Quick Info Presenter")]
      
  • The tool-tip shown when writing method name which shows it's signature is called Signature Help and can be implemented by inheriting ISignatureHelpSource in a very similar way to the QuickInfo tool-tip. A full walkthrough can be found on MSDN:

    • Example:

      Signature Help

  • Code Snippets - which are irrelevant for you.

  • Statement Completions - which are irrelevant for you.

Note that you will need to make an IClassifier in your project for the tool-tips to be displayed, with this you can also modify the view so that the Exceptions will be viewed differently as you wish. Guide on MSDN.

Getting the information on the methods on the other hand is up to you. you can use an external manual source and use it in your IQuickInfoSource or read it from a matching XML Comment document by analysing the ITextStructureNavigator's read word using Roslyn over the code document that you are navigating.

Sorry if it was a little abstract answer but this is a very broad question and there are many ways to implement such an extension.

P.S.: I've managed to make a similar extension in low quality in order to study this field so if you have any following questions about the implementation itself feel free to ask.

like image 104
Tamir Vered Avatar answered Sep 16 '22 14:09

Tamir Vered