Posted 10 years ago by Daniel Bryars
Version: 13.1.0311
Avatar

I'm using an XmlSyntaxLanguage with an XSD to provide automatic intellisense support - this is working very well.

For some attributes on some elements I'd like to define the Member List myself - it will be a dynamic list which isn't available until runtime (and can't be defined in the xsd file). The specific attribute value I'm trying to auto-complete is a very simple script which takes the name of a class and a function seperated by a dot, like this:

Geo.A()
Geo.B()
Geo.C()
Raiden.A()
Raiden.SomeOtherFunction()

These do have parameters, which would be nice to show some help on like:

Raiden.A(String name, Int32 age) 

I'm not really sure if I'm on the right track, what I've done so far is pretty rudimentary.

I've made a new class which derives from XmlSyntaxLanguage, and overrides OnSyntaxEditorIntelliPromptMemberListPreFilter - I've then added some IntelliPromptMemberListItems like so:

protected override void OnSyntaxEditorIntelliPromptMemberListPreFilter(SyntaxEditor syntaxEditor, IntelliPromptMemberListPreFilterEventArgs e)
{
//TODO: Some filtering based on the TargetElement and TargetAttribute

IntelliPromptMemberListItem item = new IntelliPromptMemberListItem("Geo.A()", 0, "Geo runtime - The fantastic A method!");
e.Items.Add("Geo.A()",item);

item = new IntelliPromptMemberListItem("Geo.B()", 0, "Geo runtime - The awesome B method!");
e.Items.Add("Geo.B()", item);

item = new IntelliPromptMemberListItem("Geo.C()", 0, "Geo runtime - The amazing C method!");
e.Items.Add("Geo.C()", item);

item = new IntelliPromptMemberListItem("Raiden.A()", 0, "Raiden runtime - incredible A Method");
e.Items.Add("Raiden.A()", item);

item = new IntelliPromptMemberListItem("Raiden.B()", 0, "Raiden runtime - irresistable B Method");
e.Items.Add("Raiden.B()", item);

base.OnSyntaxEditorIntelliPromptMemberListPreFilter(syntaxEditor, e);
}

This code does show a list of members, and if I start typing then it highlights the item in the IntelliPrompt drop down, selecting the item populates the attribute value.

I'd like to do a few more things:

I'd like to just show the "class" names. Ie Geo, Raiden. Then when you press '.' the method names should be scoped to the class name I've put in.

I was thinking that I could filter the MemberList to just "Geo", and "Raiden" first, and then when '.' is pressed I'd somehow raise the IntelliPrompt again, but filter it with the method names, eg A(), B(), C(). But, I've found the following problems trying this approach -

  • I've noticed that if the caret is not at the start of the attribute when the IntelliPrompt is invoked then the TargetAttribute of the IntelliPromptMemberListPreFilterEventArgs Context property is null.
  • Also I don't know how to get the current contents of the current attribute value.
  • Pressing '.' currently selects the current thing in the IntelliPrompt.

So perhaps I'm using the wrong approach.

Please can you advise me on the best way to do this? Or at least improve what I have now.

Thanks,

Daniel

Comments (3)

Posted 10 years ago by Daniel Bryars
Avatar

I have also noticed that I'm on quite an old version, I haven't updated the code for a while - the version I'm using is 4.0.0281.

I don't mind buying an updated version if it helps.

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Daniel,

I would also recommend that you do as you said and only show Geo, Raiden in the first list. Then watch for a "." to be typed and if you are in an attribute value, show the member list again but with the appropriate method names.

1) When I opened our XML Reflection demo, went into an attribute and typed a "." in the middle of a word, then did Ctrl+Space, I put a breakpoint in the code that calls the filter method.  The context there did have the TargetAttribute filled in.  I didn't see it as null.

2) You can call something like this to get a text stream (syntaxEditor.Document.GetTextStream(syntaxEditor.Caret.Offset)) then look at the tokens around there.  Accumulate the text in any surrounding tokens that are Key = "StartTagAttributeValueDefaultToken".  That will give you the attribute value.

3) You can update the syntaxEditor.IntelliPrompt.MemberList.AllowedCharacters property to include '.' in the collection.  You'll have to do it in your filter method override since it gets reset.

I hope that helps.


Actipro Software Support

Posted 10 years ago by Daniel Bryars
Avatar

Thank you. I've changed the syntaxEditor.IntelliPrompt.MemberList.AllowedCharacters property to include '.' in the collection and this works well thankyou.

I haven't tried your other advice yet, but will give that a go over the next couple of days. Enjoy your thanksgiving turkey!

The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.