Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing Visual Studio Intellisense

I'm trying to add Intellisense to C# code editor based on the richtextbox control. So far, I've got it parsing the entered text to find all variables and their types (works well). The drop down box works well. What I can't get is a proper list of options for the drop-down list box.

How can I get the following list, programmatically:

alt text

I have already compiled a list of variables and their types, so when the user presses . I know that I have a variable c of type Color. I just need to know what function to call to get the list I need for the drop-down box.

I've tried this code: http://www.codeproject.com/KB/cs/diy-intellisense.aspx but couldn't get it to work properly. I've also read a ton of other threads on StackOverflow to no avail. I'd really like to finish this instead of using someone elses drop-in editor component.

Any hints would be appreciated. Thanks.

like image 603
BoltBait Avatar asked Jul 23 '10 19:07

BoltBait


People also ask

How do I use IntelliSense in Visual Studio?

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

Why is IntelliSense not working Visual Studio 2022?

Please try: Go to Visual Studio Installer, click Modify , uncheck IntelliCode in Individual components, then click Modify button to save the change, wait for the installation to complete, and then reinstall IntelliCode . In Visual Studio, go to Tools->Options->IntelliCode to check if the setting is Default.

Does Visual Studio support IntelliSense?

Powered by a TypeScript based language service, Visual Studio delivers richer IntelliSense, support for modern JavaScript features, and improved productivity features such as Go to Definition, refactoring, and more.

How do I enable IntelliSense?

You can enable or disable particular IntelliSense features in the Options dialog box, under Text Editor > C/C++ > Advanced. To configure IntelliSense for single files that aren't part of a project, look for the IntelliSense and browsing for non-project files section.


2 Answers

If you know the type, you should be able to Reflect on the type and get all the information you need.

Type.GetMembers would probably be your best bet. You may need a second call to get any static methods as well:

var instanceMembers = typeof(Color)
                      .GetMembers(BindingFlags.Instance | BindingFlags.Public);

var staticMembers = typeof(Color)
                    .GetMembers(BindingFlags.Static | BindingFlags.Public);

Each MemberInfo object will be able to tell you the MemberType (Property, Field, Method, Event, etc.)

Just use the instanceMembers when the user types a variable (like c in your example) followed by . and use the staticMembers when the user types a type name (like Color in your example) followed by ..

like image 92
Justin Niessner Avatar answered Oct 15 '22 21:10

Justin Niessner


Assuming you have a name table with types this should give you a decent start:

var type = _names[name].Type;
var members = type.GetMembers(); // Check context to grab private methods?

So maybe you can extend your name table to include:

Type
Context
Members
like image 27
ChaosPandion Avatar answered Oct 15 '22 20:10

ChaosPandion