views:

1555

answers:

9

I hope this is a valid question: how does intellisense work in VS2008? I'm after what is known about the algorithm it uses to find the suggestions, when exactly it pops up (the "." is just one obvious trigger), how its behavior can be modified if at all possible, etc.

To put this question into context: The main issue I'm trying to resolve is how to activate and deactivate intellisense in portions of the editor screen and how to modify where it searches to populate the suggestion box.

All information is welcome.

A: 

It can also pop up if you hit Ctrl + Space

You can actually use this anywhere, too. So say you prefix all your member variables with _ you could type _ and then hit Ctrl + Space and see all your member variables.

Very useful.

Joseph
-1, not even close to an answer. You might say this is about the "when exactly it pops up", but it isn't. By (the "." is just one ...) specifies that he is referring to it popping up automatically.
hmcclungiii
He specifically asks for when it pops up, so I felt like answering that portion of his question. What's wrong with that? If you want to get technical Ctrl + Space is the CompleteWord keybinding, which you can use at ANY time with intellisense, but as a side you can use it to force Intellisense to show.
Joseph
Yea, force it to show, not trigger it as in ".".
hmcclungiii
This is more of a "comment" on the question, rather than an answer.
+1  A: 

have you seen this thread in msdn ?

Adinochestva
Good start. Thanks.
Dervin Thunk
A: 

Eclipse also has this feature and it is an open source project. Why not check out how Eclipse does it by actually looking at the code?

Peter D
I'm extending VS for an in-house domain-specific language
Dervin Thunk
A: 

This question is too broad. Since there are a number of different languages the VS IDE supports out of the box AND there are N number of DSL and IDE enhancements that support alternative intellisense this implies a number of answers. If you are speaking about C# specifically then See the Tools | Options | Text Editor | C# | Intellisense area to see the available options of completion options. As far as the algorithm[s] used, you would be looking for the metadata of assemblies, copious caching of type members, MRU list for last member chosen for specific type, etc. If you have a more specific question, I'd suggest you clarify.

See the example of a DSL (ironpython) and its implementation here.

Adam Markowitz
+6  A: 

Take a look at this DIY Intellisense article on CodeProject.

Galwegian
Excellent link!
hmcclungiii
+3  A: 

It's more fun to reverse-engineer it, though. Let's consider the problem:

  • you need to identify the words of interest
  • you need to find the options possible
  • you need to present them

Now, the first step means you have to parse the code. You've got the C/C** keywords, you pre-parse the various function and class declarations, and load them into some kind of data structure. Then you parse the code and store the class, variable, etc names and put them in the same data structure.

The second step means you want a data structure which efficiently can search for a partial word and get all the words that have that prefix. You can do that with regular expressions, but that's not very efficient. An efficient data structure for that kind of search is a trie, which is discussed here on SO .

Once you have the list of possibilities, you just present it. You probably want to keep a reference to the root of the tree of possibilities so you can search them out in real time as someone types more letters.

Charlie Martin
A: 

I haven't seen any text editor in VS that limits where IntelliSense shows up. It's all language specific. If your cursor is located at a point where IntelliSense might contribute to a valid token, that's when it will be used.

I believe there is some interaction with the project system being used, but that's as far as I know. I also believe there is a sample project system in the Visual Studio SDK, and that might give you an idea.

John Saunders
A: 

For such cases I sometimes use my own version of InteliSense that I developed for AutoHotKey when I want specific behavior. The point of this script is that it can be used with any editor, or basically any control accepting text. It works by recording text input and interpreting it upon syntax file.

You can perhaps use it as a base for the thing you want to achieve. I used ISense succesifully with several languages that don't have such thing, like Csound or even batch scripts. It will be possible to extend it to support C# using input monitoring in combination with Reflection.

Anyway, with AHK you can even control VS intelissense by "taking" the list of items it presents and filter it, or similar things. You may have some small problems with process boundaries but nothing that cant be fixed.

The intellisense ius generally, AFAIK, implemented using different methods. I read that Delphi is so fast that it implements isense by recompiling the project on each token and thats the reason C++ Builder didn't have isense as its compiling very slow.

majkinetor
A: 

As to your how to change where it looks question, short answer is, you can't. Intellisense for the most part is provided by reflection of assemblies included in your project ( and some other tricks with C++ ). What you are getting is a result of VS processing through all the assemblies you have included and all assemblies from the GAC.

That said, if you want to provide explicit intellisense results from a project you are working on, look into IVsContextualIntellisenseFilterProvider

Finally, for some insight into the behind the scenes process, check this blog post

Serapth