Beginning help with Intelliprompt

SyntaxEditor for Windows Forms Forum

Posted 17 years ago by Bob Puckett
Version: 4.0.0256
Avatar
I need some beginning help with Intelliprompt. I am creating a non-mergeable language. I have highlighting working. I have basic outlining working (though I have not yet implemented the AST).

In my SyntaxLanguage I have overridden IntelliPromptCompleteWord, ShowIntelliPromptMemberList, and IntelliPromptMemberListSupported. I return true from IntelliPromptMemberListSupported.

I have copied code from the Simple example as a base.

My question is, when do these methods get called? Or when do I need to call them myself? Obviously, right now, I am not getting any memberlist pop-ups when I type in the editor.

Thanks for any help.

Comments (7)

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

When you say IntelliPromptMemberListSupported = true, that means that the Ctrl+Space hotkey will call your language's CompleteWord method. So all your member list code should be organized under that method.

But as you guessed, additionally you need to trap key presses (like ".") and call ShowIntelliPromptMemberList at the appropriate times. You can do that in an OnKeyTyped override.


Actipro Software Support

Posted 17 years ago by Bob Puckett
Avatar
OK, great, that was the hint I needed. Got that basic part part working. Now what I want is for a valid word completion list to come up whenever a character is typed just like in Visual Studio and for the list to be filtered on each successive character. Check my thinking here if you would -

I override the OnSyntaxEditorKeyTyped.

I check to see if it is an Alpha char with Char.IsLettere.KeyChar)

If so, I look at the Current Token (assuming that my LexicalParser was called on the previous modification). I add the new character to the end and then build up a member list of matching keywords.

I select the first item in the list.

I return from OnSyntaxEditorKeyTyped.

Does that sound like the way to go? Is there an easier way using facilities in the SyntaxEditor that i am not aware of yet?

Thanks for the GREAT fast tech support every time I ask a question.

Bob
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes that is a good way of doing it. I believe KeyTyped happens after the modification takes place. There is a KeyTyping that occurs before. But by using KeyTyped, you should be able to pass in the range of the "word" to the member list Show method. Then it will automatically handle selecting the proper item for you.


Actipro Software Support

Posted 17 years ago by Bob Puckett
Avatar
OK, everything is working except selecting the first item in the list. On the first character, the item in the member list is selected. Example: I type 'i' and get a list with "if", "in", "integer", "interrupt" and "if" is selected. When I type the second character, 'n', the list is filtered and only "in", "integer", "interrupt" are displayed, but there is no selected item.

Here is my code:
        public override bool ShowIntelliPromptMemberList(SyntaxEditor syntaxEditor)
        {
            return ShowIntellipromtMemberList(syntaxEditor, false);
        }

        private bool ShowIntellipromtMemberList(SyntaxEditor syntaxEditor, Boolean completeWord)
        {
            SemanticParserService.WaitForParse(SemanticParserServiceRequest.GetParseHashKey(syntaxEditor.Document, syntaxEditor.Document));

            // Initialize the member list
            IntelliPromptMemberList memberList = syntaxEditor.IntelliPrompt.MemberList;
            memberList.ResetAllowedCharacters();
            memberList.Clear();
            memberList.ImageList = SyntaxEditor.ReflectionImageList;

            // Get the target text range
            TextRange targetTextRange = TextRange.Deleted;
            TextStream stream = syntaxEditor.Document.GetTextStream(syntaxEditor.Caret.Offset);
            if (stream.IsAtTokenStart)
            {
                if (stream.Offset > 0)
                {
                    stream.GoToPreviousToken();
                    targetTextRange = stream.Token.TextRange;
                }
            }
            else
            {
                stream.GoToCurrentTokenStart();
                targetTextRange = stream.Token.TextRange;
            }

            // Get the member list items and add keywords
            IconResource icon = IconResource.Keyword;
            foreach (String s in this.myReservedWords.Keys)
            {
                if (s.StartsWith(syntaxEditor.Document.GetTokenText(stream.Token)))
                {
                    IntelliPromptMemberListItem item = new IntelliPromptMemberListItem(s, (int)icon);
                    memberList.Add(item);
                }
            }

            // Show the list
            if (memberList.Count > 0)
            {
                if (completeWord)
                    memberList.CompleteWord(targetTextRange.StartOffset, targetTextRange.Length);
                else
                    memberList.Show(targetTextRange.StartOffset, targetTextRange.Length);
                return true;
            }
            return false;
        }

        protected override void OnSyntaxEditorKeyTyped(SyntaxEditor syntaxEditor, KeyTypedEventArgs e)
        {
            if (Char.IsLetter(e.KeyChar))
                ShowIntelliPromptMemberList(syntaxEditor);
        }
It appears that the targetTextRange is correct.

This behavior occurs on the second character TYPED. If the 'i' was already in the text and I place my insertion point behind it and type 'n', then the "in" element in the list is selected - but when I type 't', there is no selected item. I must be missing some step of telling the editor something.

Thanks.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
There might be a minor bug at work here. If you'd like, make a simple sample project that shows this and email it over. Then we can debug it and see if it is a problem with our code that can be addressed in a maintenance release. Thanks.


Actipro Software Support

Posted 17 years ago by Bob Puckett
Avatar
Great. This is very simple to reproduce in your Simple Language sample application. Add the following lines to make your OnSyntaxEditorKeyTyped in the SimpleSyntaxLanguage look like this:
        protected override void OnSyntaxEditorKeyTyped(SyntaxEditor syntaxEditor, KeyTypedEventArgs e) {
            switch (e.KeyChar) {
                case '(':
                    if (syntaxEditor.Caret.Offset > 1) {
                        // Show the parameter info for code
                        this.ShowParameterInfoCore(syntaxEditor, syntaxEditor.Caret.Offset);
                    }
                    break;
                case ')':
                    if (syntaxEditor.Caret.Offset > 1) {
                        // Show the parameter info for the parent context level if there is one
                        this.ShowIntelliPromptParameterInfo(syntaxEditor);
                    }
                    break;
                case ',':
                    if ((!syntaxEditor.IntelliPrompt.ParameterInfo.Visible) && (syntaxEditor.Caret.Offset > 1) && (syntaxEditor.SelectedView.GetCurrentToken().LexicalState == this.LexicalStates["DefaultState"])) {
                        // Show the parameter info for the context level if parameter info is not already displayed
                        this.ShowIntelliPromptParameterInfo(syntaxEditor);
                    }
                    break;

                default: if (Char.IsLetter(e.KeyChar)) this.ShowIntelliPromptMemberList(syntaxEditor);
                    break;
            }
        }
The lines added are:
                default: if (Char.IsLetter(e.KeyChar)) this.ShowIntelliPromptMemberList(syntaxEditor);
                    break;
Recompile and run your sample app. Select Simple Language add on. Put the insertion point in one of the function blocks. Type 'i'. This will bring up a member list with a few elements and "Increment" will be highlighted as selected. Type 'n'. The list will no longer have a selected item.

Let me know if you find anything. Thanks.
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks this is now fixed for the next maintenance release.


Actipro Software Support

The latest build of this product (v24.1.0) 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.