31

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

undefined
  • 33,537
  • 22
  • 129
  • 198
  • 8
    @oded ive just spent a few hours looking through google, msdn ect and havent been able to find anything at all on extending intellisense, do you have any recommendations on where to even look for it? – undefined May 05 '12 at 08:37
  • Sorry Luke, I don't though the [Visual Studio Extensibility forum](http://social.msdn.microsoft.com/Forums/en-US/vsx/threads) would be a good starting place. But you _could_ rephrase the question to not ask for links and actually be an on-topic programming question. – Oded May 05 '12 at 08:39
  • 1
    Also, an example of what you'd like to add to Intellisense would help greatly. There's a number of different techniques that may be needed... – Jason Malinowski May 06 '12 at 05:18
  • @JasonMalinowski I've added in a bit more detail of what I'm after, is this the info you are after? Ive been having a bit of trouble phrasing the question as I have no idea where to start from a code pov so any tips for wording it better would be much appreciated – undefined May 06 '12 at 05:28

1 Answers1

34

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.]

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
  • Thanks im pretty sure this is what im after, Its a real shame you dont have access to stuff before the ., that API has to be there somewhere for regular VS intellisense to work so its sad its not public. Ive use roslyn stuff before so i will take a crack at something with that to work out what the subject is – undefined May 10 '12 at 04:30
  • @Jason, I have tried to add another intellisense for javascript `[Order(Before = "High")] [Export(typeof(ICompletionSourceProvider)), ContentType("JavaScript"), Name("EnhancedJavaScriptCompletion")] internal sealed class JavaScriptCompletionSourceProvider : ICompletionSourceProvider { } ` but it nevers steps into the debugger, although the breakpoints looks like the code is loaded. Can you please help me? – DATEx2 Mar 27 '13 at 00:48
  • 1
    @DotNetWise: you should create a new question so others can answer the question. ;-) – Jason Malinowski Mar 27 '13 at 04:11
  • @JasonMalinowski I have posted the question here http://stackoverflow.com/questions/15657525/extending-vs2012-javascript-intellisense-with-custom-icompletionsourceprovider – DATEx2 Mar 27 '13 at 11:16
  • The Roslyn link goes to one of the blogs you link above. I'm guessing you want to link to http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx? – jswolf19 Apr 15 '14 at 02:57
  • @JasonMalinowski Is this advice still current or is there a more preferred approach, given that Roslyn is now a thing? – Sam Holder Nov 05 '18 at 10:12