Showing the Intellisense popup "earlier" but intelligently

SyntaxEditor .NET Languages Add-on for Windows Forms Forum

Posted 17 years ago by John Corbett - Software Architect, SonarData Pty. Ltd.
Version: 4.0.0262
Avatar
Hi,

In my application, I would like the intellisense suggestion list to pop up "earlier", more in the manner that it does in Visual Studio. For instance, if I have local variables "foo" and "bar", if I type "foo = bar" in VS, I will get intellisense when I begin typing "foo" and "bar". Using the Syntax editor, I don't get that.

On the flipside though, I don't want the intellisense to pop up when it is inappropriate; for instance, when declaring a new variable (eg "int foo;"), it would be preferable if intellisense pops up for "int" but not "foo", since there is no way that "foo" will be in the auto-completion list.

I have a bit of a go at it by putting a handler on the editor KeyTyped event, but it doesn't quite work properly; perhaps you can help me get it right; or maybe even point me to a code sample that does it already!

Here is my try:

        void editor_KeyTyped(object sender, KeyTypedEventArgs e)
        {
            if (editor.SelectedView.Selection.FirstOffset > 0) {
                CSharpContext context = CSharpContext.GetContextAtOffset(editor.Document, editor.SelectedView.Selection.FirstOffset - 1, (ActiproSoftware.SyntaxEditor.Addons.DotNet.Ast.CompilationUnit)editor.Document.SemanticParseData, dotNetProjectResolver);
                if (context.Items != null && context.Items[0].Type == DotNetContextItemType.Unknown) {

                    editor.Document.Language.ShowIntelliPromptMemberList(editor);
                }
            }
        }
This works most of the time, but it pops up intellisense in one case when it shouldn't (that I have found). If I have a class type FooClass, I get unwanted intellisense as I type "foo" in this situation: "FooClass foo;". (NB, if I type "int foo;", it works perfectly).

I hope I've made it clear what I am trying to achieve, please ask for clarification if it is not clear. Thanks in advance.

Regards
John

Comments (1)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

We don't include this automatically in our implementation since the retrieval of a context and display of a member list during typing of all characters could make a typing performance hit depending on how complex your setup is.

However what you started with is ok to achieve this functionality. Perhaps only do that code if the key typed is a letter or number too? You may want to look at the CSharpContext.Type property to get some more information about the general context of the caret. That could help in some of your scenarios.


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.