AutoCompletion for XML / HTML

Questions on using RSyntaxTextArea should go here.

Moderator: robert

AutoCompletion for XML / HTML

Postby Christian » Fri Apr 16, 2010 11:55 am

Hello,

first I thank you for this very nice component!

My Problem is, I wrote the data for autocompletion in a xml-file, one keyword is like this:

<autocomplete command="<html>" shortdesc="..." />

How can I make the RSTA to understand this? If I press CTRL+Space the entry isn't there, it only works if I escape this entry like (command="&lt;html&gt;"). Then the problem is, if I type <h and press ctrl + space nothing appears .. I hope you understand what I mean.
I use the BasicCompletion and I don't know if this is the best way for XML-Completion.


I hope you can help me and I would be very pleased to receive a helpful answer. Thanks!!
Christian
 

Re: AutoCompletion for XML / HTML

Postby robert » Mon Apr 19, 2010 8:19 pm

Hi Christian,

The problem is that you are using a DefaultCompletionProvider. It is designed to be simple, and usable for completion of mostly keywords and fields in languages with relatively simple syntax such as C.

DefaultCompletionProvider only scans the chars just before the caret; any contiguous block of letters, '_' chars and '.' chars is treated as the token to complete. This is done in its isValidChar(char) method. If you'd like to include other characters, such as '<', you can subclass DefaultCompletionProvider and override isValidChar(char) to also accept that character. For example:

Code: Select all
@Override
protected boolean isValidChar(char ch) {
   return super.isValidChar(ch) || ch=='>';
}


Also, you might want to check out this entry in my blog to see where I'm implementing very smart code completion for HTML, PHP and JSP. You might consider using this instead of rolling your own, as it is very feature-rich and should prove useful with editing markup. If you're so inclined, you could even contribute, especially in the form of descriptions of the tags, attribute, etc., where they are currently lacking!
User avatar
robert
 
Posts: 801
Joined: Sat May 10, 2008 5:16 pm

Re: AutoCompletion for XML / HTML

Postby Christian » Tue Apr 20, 2010 9:15 am

Thanks for your help!

For short distance I just preferr the first thing. To override this method, because it is not important to have the complete HTML-Tags and their valid attributes.
Because the user of my software are just able to use a few of the html-tags.

But for future it would be nice to have this feature you're implementing. Does the 168 RSTA just have this feature? Sorry, I'm not able to find it out by my own. And if you want, I could help you filling the gaps, if there are still any of them.
Christian
 

Re: AutoCompletion for XML / HTML

Postby robert » Tue Apr 27, 2010 8:42 pm

Christian wrote:But for future it would be nice to have this feature you're implementing. Does the 168 RSTA just have this feature? Sorry, I'm not able to find it out by my own. And if you want, I could help you filling the gaps, if there are still any of them.


The HTML auto-completion was added very recently. You can grab it in the standard SVN repository. You'll need to check out the trunk of "RSTALanguageSupport". Feel free to try it out and provide feedback, but note that this code is very volatile and will change frequently! There might not be an "official" release for awhile, you'll have to grab from SVN if you want to try it out and use it.

You'll see that the HTML completions are all stored in an XML file. If your language uses markup just like XML/HTML, you should be able create a similar XML file specific to your language, and the HtmlCompletionProvider would then auto-complete for your language. The "HtmlCompletionProvider" is actually just a generic "MarkupCompletionProvider" hard-coded to load completions for HTML 5 from an XML file.

In the future there could be changes to allow the user to specify an XML file to load for markup-based languages, changing HtmlCompletionProvider to MarkupCompletionProvider. But I don't see this happening for awhile. Feel free to hack into the code yourself to add this though! Feedback on the API is welcome, and I'll be glad to help you out if you have issues.
User avatar
robert
 
Posts: 801
Joined: Sat May 10, 2008 5:16 pm

Re: AutoCompletion for XML / HTML

Postby Christian » Fri Apr 30, 2010 12:31 pm

Thanks!
Christian
 


Return to Help

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests