Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Intellisense Extension

I am wanting to write an addition to intellisense in Visual Studio.

Is it possible to extend at all, from my research I haven't found any samples or documentation on intellisense extensions.

How can I get intellisense to show a simple HelloWorld message like the following (where hello world is added at run time to the intellisense for String):

enter image description here

like image 760
Not loved Avatar asked May 05 '12 08:05

Not loved


People also ask

How do I add IntelliSense code 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 (.)

What is IntelliSense in C#?

IntelliSense provides an option to help you implement members of an abstract base class automatically while working in the code editor. Normally, to implement members of an abstract base class requires creating a new method definition for each method of the abstract base class in your derived class.

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.


1 Answers

So in Visual Studio 2010 and later, the extensibility APIs you want to at are under the Microsoft.VisualStudio.Languages.IntelliSense namespace. At a high level, you want to MEF export a ICompletionSourceProvider which will provide the items you need. There are two good blog posts here and here that demonstrate the basic technique.

There are two problems that you'll run into if you wanted to make your screenshot be a reality. (This is why I asked for the scenario, as my advice here would change.) First, this method doesn't legally let you append to an existing completion set, but rather provide a new one. In the UI this appears as two tabs, like the Common/All tabs in the Visual Basic editor. This is a limitation of the current API. You could try to modify one of the existing completion sets in your AugmentCompletionSource but I have no idea if that'd work. It's definitely unsupported, in any case.

Second, it's really hard to know when and where to recommend things. In your example, you said "the IntelliSense for string". Sadly, there aren't any APIs (currently) in VS that let you know what the thing before the dot is. You could do some simple heuristics or try implementing some parser that is Good Enough™ for your scenario, but you'll have to accept for now that you won't have perfect results.

The Roslyn project aims to fix the second issue, so you may find it useful to explore a bit further. Since we expect that lots of people will want to extend completion, we're also thinking about offering other extensibility APIs so you don't have to roll a ICompletionSourceProvider from scratch, but such APIs are not in the current CTP.

[Disclaimer: I'm a member of the Roslyn team who works on IntelliSense.]

like image 108
Jason Malinowski Avatar answered Sep 20 '22 14:09

Jason Malinowski