Jython code Completion

General Discussion goes here.

Moderator: robert

Jython code Completion

Postby GroG » Thu Jun 07, 2012 4:54 am

Hello !
Thank you for an fantastic project. It's clean, well managed, and a delight to use - (if only IBM took lessons from you, I would be a happier person)
Now the Question,
I was wondering if you could nudge me in a good direction. I am using RSyntaxTextArea in a swing application. The editor is for Jython. The text area is working great, and I would like to implement code completion in Jython. Besides the Jython keywords I would (at least) like to support a local Java package (through Jython) in the code completion.

Initially I saw a CompletionXML.dtd and was thinking I'd need to write a doclet for my package to have javadoc write it to match the DTD. Then I saw RSTALanguageSupport project.

So to summarize, the "users" of the editor will be writing in Jython, and I'm interested in code completion for (Python keywords + (at least) a couple of local Java packages)

I've downloaded and built all the projects under RSyntaxTextArea (trunk version) (kudos for the clean build process) - Now I was hoping for some sagely advice, before I start hacking and slashing and stepping on things I shouldn't :D

Kind Regards,
Posts: 2
Joined: Thu Jun 07, 2012 4:39 am

Re: Jython code Completion

Postby robert » Sat Jun 09, 2012 1:39 am

Hi Greg,

I'm glad you find the project useful! To get started with Jython code completion, the first thing to do would be to decide whether to "override" the standard Python highlighting (I assume Jython's syntax is a superset of Python's) and use it for Jython, or add your own Jython support. The former is simpler than the latter, and you can change this easily enough later.

Assuming the former, you'll want to examine RSTALanguageSupport project to see how things work. Maybe start with the C support in the org.fife.rsta.ac.c package. That does pretty much nothing but static code completions based off the CompletionXML.dtd you've already discovered, so it's fairly straightforward. You could copy that package as a starting point, for example, and rename the classes accordingly:

Code: Select all

You need to register your new LanguageSupport with the org.fife.rsta.ac.LanguageSupportFactory so it can be used:

Code: Select all
LanguageSupportFactory lsf = LanguageSupportFactory.get();
lsf.addLanguageSupport(SyntaxConstants.SYNTAX_STYLE_PYTHON, "com.grog.rsta.jython.JythonLanguageSupport");

Now any RSyntaxTextArea editing SYNTAX_STYLE_PYTHON code should get code completion for whatever you put into your "jython.xml" (or whatever your equivalent of c.xml is named). This should get you any static code completions, for example, keywords or default-package functions (if there are any). You can even add parameter support as seen in the C example.

Once that's working, you could take a step back and look at using classes in the Java language support (org.fife.rsta.ac.java.*) to get code completion for simple Java packages, etc. Be forewarned though - I tried to comment the code well, but it's far from documented. It's also certainly far from perfect, but I consider it "good enough", since even just code completions for members one level deep adds a "wow factor" to an application. In any case, the JavaScript support (org.fife.rsta.ac.js) is probably a shining example of how to grab and use stuff from the Java language support. Another user is graciously implementing JavaScript code completion (using Rhino, though I believe it's pluggable for any JSR223-compliant JS implementation), and his work allows users to point to classes in Java files and get code completion from them. So that would be a good resource.

Feel free to post any specific questions, and good luck!
User avatar
Posts: 852
Joined: Sat May 10, 2008 5:16 pm

Return to General

Who is online

Users browsing this forum: dixiegn16 and 0 guests