Join  |  Sign in
Custom code completion items

29-Oct-2017 11:11 AM

Gary Yates

Gary Yates

Posts: 2

I am using the SyntaxEdit control with the Advanced VB .Net Parser in my program to allow editing scripts.  The scripts mostly consist of calling methods where the first parameter is the name of an item to operate on.  The name is a string.  I would like to have a list of valid names appear as soon as the user types the '(' after a method name.  The default behavior is to show the method signature, which is fine, but I would also like a pick list like the member list to appear, only populated with the name strings.

I have looked at NeedCodeCompletion event which is triggered by the '(', but it is not obvious to me if there is a way to do this.  Is this something that can be done using the SyntaxEdit framework?

Thanks,

  Reply

30-Oct-2017 05:35 PM

Andrew Medvedev

Andrew Medvedev

Posts: 49

Hi Gary,

You can show code completion hint and listbox with pre-populated members at the same time by handling NeedCodeCompletion like this:

   private void SyntaxEdit1_NeedCodeCompletion(object sender, Alternet.Syntax.CodeCompletionArgs e)
        {
            if (e.KeyChar == '(' && e.Provider != null && e.CompletionType == Alternet.Syntax.CodeCompletionType.ParameterInfo)
            {
syntaxEdit1.ShowCodeCompletionHint(e.Provider, e.Lexer); // display default hint

                var members = new Alternet.Syntax.CodeCompletion.ListMembers(); 
                members.ShowDescriptions = true;
                members.ShowResults = false;
                members.ShowQualifiers = false;

                var member = members.InsertListMember(0);
                member.Name = "name1";
                member.DisplayText = "<b>name1</b>";
                member.DataType = "void";
                member.Qualifier = "public";
                member.Description = "string name1";

                member = members.InsertListMember(0);
                member.Name = "name2";
                member.DisplayText = "<b>name2</b>";
                member.DataType = "void";
                member.Qualifier = "public";
                member.Description = "string name2";

                member = members.InsertListMember(0);
                member.Name = "name3";
                member.DisplayText = "<b>name3</b>";
                member.DataType = "void";
                member.Qualifier = "public";
                member.Description = "string name3";
                e.Init(Alternet.Syntax.CodeCompletionType.ListMembers, syntaxEdit1.Position);
                syntaxEdit1.ShowCodeCompletionBox(members, Alternet.Syntax.CodeCompletionType.ListMembers); // display listbox under the hint.

                e.Handled = true; // no further processing
            }
        }

regards,
Andrew
  Reply

02-Nov-2017 10:08 AM

Gary Yates

Gary Yates

Posts: 2

Thanks.  That works, but I need a slight variation.  What the user of the script is selecting is a string and needs to be quoted.  It also needs a prefix added.  For example, the finished code would be:

SetFlag("Flag:Audio On")

I would like the user to be able to select Audio On in the list, but then have the value inserted to be "Flag:Audio On".

Is there a way to intercept what is being completed and change it first, perhaps during the Tab is pressed.  Or a way to specify one thing to be shown in the list but something else completed.  I thought I might be able to do it with DisplayText vs Name, but that didn't work.

BTW, I tried to put "Flag:Audio On" in the list, but when I type the " it does match and code compete, the member listbox just disappears.

Everything else about the editor is working really well.

Thanks again,

  Reply

03-Nov-2017 06:50 PM

Andrew Medvedev

Andrew Medvedev

Posts: 49

Hi Gary,

you can specify string to be inserted in the editor in the same event with code like this:
member.InsertText = "string to insert";

We've found a small bug though in the editor that ignores this text, I will send you hot-fixed Alternet.Editor.dll via email.

regards,
Andrew
  Reply

02-Dec-2017 01:29 AM

Glitch

Glitch

Posts: 3

Hi, I registered an assembly in the editor component using RegisterAssembly.  I can get intellisense on instances of the class that I create in the editor, but I cannot seem to get intellisense on the constructor when I use code like this:

MyType p = new MyType(

Is there something more I need to configure to get intellisense on the constructor?

  Reply

02-Dec-2017 01:30 AM

Glitch

Glitch

Posts: 3

Hi, I registered an assembly in the editor component using RegisterAssembly.  I can get intellisense on instances of the class that I create in the editor, but I cannot seem to get intellisense on the constructor when I use code like this:

MyType p = new MyType(

Is there something more I need to configure to get intellisense on the constructor?

  Reply

04-Dec-2017 08:04 PM

Andrew Medvedev

Andrew Medvedev

Posts: 49

Hi,

the bug with intellisense not being displayed in constructors has been fixed in version 2. 
I'm uploading slightly modified RoslynSyntaxParser demo which references MyTypeLibrary dll where MyType is declared - you can see that parameter tooltip is displayed when you type code like MyType p = new MyType(
http://www.alternetsoft.com/projects/RoslynSyntaxParsing.zip
 
Kind regards,
Andrew Medvedev
  Reply

05-Dec-2017 12:26 AM

Glitch

Glitch

Posts: 3

This is great news, thank you!  Quick question, what is the recommended way to upgrade from 1.1 to 2.0?  I just ran the download and repair installation, and I still seem to be at 1.1?

  Reply

05-Dec-2017 09:08 PM

Andrew Medvedev

Andrew Medvedev

Posts: 49

Hi,
 
right now you need to uninstall previous version before installing a new one. We're working on supporting side-by-side installation for major releases, but for now the only way is to reinstall the software.

Kind regards,
Andrew Medvedev
  Reply