IntelliPrompt on KeyTyped forgot a first letter

SyntaxEditor for Windows Forms Forum

Posted 13 years ago by Mazlan
Version: 4.0.0285
Avatar
Hi, I am new to SyntaxEditor. I just make the lexical parser from dynamic language XML definition and syntax coloring work well. I still studying to make semantic parser to work.

I want to create a simple cut down C# IDE that is actually in a method body scope, no OOP, no inteliprompt member list and at last it will inserted into hard coded predefined class to be built into a dll file.

Now I try to show inteliPrompt list immediately after a first letter is pressed, so I can show any of data types, user defined variables and predefined methods. I found this thread http://www.actiprosoftware.com/support/forums/viewforumtopic.aspx?ForumTopicID=5872 shows an example to trigger it from SyntaxEditor.KeyTyped event:

// If the typed character was a letter...
if (Char.IsLetter(e.KeyChar)) {
    // See if a new token starts after the character that was typed
    var stream = editor.Document.GetTextStream(editor.Caret.Offset);
    if (stream.IsAtTokenStart) {
        // See if the character that was typed started a new token
        stream.ReadCharacterReverse();
        if (stream.IsAtTokenStart) {
            // Show member list here
            // I add "bool" and "string" to test.
        }
    }
}
Now when I press "s" (for string) it will show the inteliPrompt well with "bool" and "string" in the list. However it seems the first "s" is forgotten:
  • If I focus to "string" and press enter it will become "sstring" in the editor
  • If I press the second "s" to make it become "ss" then inteliPrompt will just focus on the "string" (seems that is my first typed "s")
So my question are:
  1. When the first letter typed, how to make the inteliPrompt immediately popup and it will focus on the related member by taking the first latter into account, in this case "string"?
  2. TextStream from Document.GetTextStream() is disposible, can I immediately dispose it or did the instance is reuseable inside Document?
  3. Did the inteliPrompt can automatically search for a keyword and minimize the list or I need to Clear() and polulate the MemberList again each time key pressed? e.g: when I type "day" it will show only "IsWeekDay" and "GetPublicHolidays", when I add "s" it will only has "GetPublicHolidays".
  4. Which one is the best time to populate the intelliPrompt, based on SyntaxEditor.KeyTyped event or after I implement semantic parsing and I have many AST nodes, how? I need to show MemberList differently whether it is in document line start, in method parameter, in if condition or anything else that is need to look around the TextStream in SyntaxEditor.KeyTyped and mixed with DynamicOutliningSyntaxLanguage.OnSyntaxEditorTriggerActivated event. Seems like I just mess around only for showing inteliprompt in different conditions.


[Modified at 08/01/2011 11:14 PM]

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Mazlan,

1) You are probably calling the member list's Show method that doesn't take an offset range. There is an overload where you'd specify the offset range to consider replacable, in your case, the offset range of the "s".

2) You can dispose it immediately.

3) At this time we don't have an auto-filter feature like that in the WinForms SyntaxEditor. We do have that in our WPF and Silverlight versions, which have newer object models and designs.

4) For our own add-on language implementations, we show IntelliPrompt on KeyTyped and generally use a combination of token-scanning and AST examination to figure out context. Since the AST nodes are likely going to be slightly out of date at all times (since they are parsed in a worker thread), you can't rely on them to know the tokens immediately around the caret, especially in larger documents.

What we do is use token scanning via TextStream to determine the expression around the caret and then use the AST more for figuring out if that expression range is in a type, method, etc.


Actipro Software Support

Posted 13 years ago by Mazlan
Avatar
Hi, Thank you I don't realize the Show() method overload. For the 3) I need to develop it my self and 4) I take your suggestion. So this is the working example for my problem 1):

// If the typed character was a letter...
if (Char.IsLetter(e.KeyChar))
{
    // See if a new token starts after the character that was typed
    using (TextStream stream = syntaxEditor.Document.GetTextStream(syntaxEditor.Caret.Offset))
    {
        if (stream.IsAtTokenStart)
        {
            // See if the character that was typed started a new token
            stream.ReadCharacterReverse();
            if (stream.IsAtTokenStart)
            {
                // Show member list here

                // Get the member list
                IntelliPromptMemberList memberList = syntaxEditor.IntelliPrompt.MemberList;
                memberList.ResetAllowedCharacters();

                // Set IntelliPrompt ImageList
                memberList.ImageList = SyntaxEditor.ReflectionImageList;

                // Add items to the list
                int imageIndex = (int)IconResource.Keyword;
                memberList.Clear();

                // add native types
                memberList.Add(new IntelliPromptMemberListItem("int", imageIndex, "Native 32 bit integer"));
                memberList.Add(new IntelliPromptMemberListItem("string", imageIndex, "Native string type"));
                memberList.Add(new IntelliPromptMemberListItem("bool", imageIndex, "Native boolean type to represent <b>true</b> or <b>false</b>."));

                // add variables within the scope

                // add predefined methods.

                // Show the list
                if (memberList.Count > 0)
                    memberList.Show(stream.Offset, 1);
            }
        }
    }
}
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.