Archive for the ‘RSTALanguageSupport’ Category

More helpful Java code completion – Feedback please!

Wednesday, January 12th, 2011

If you’re using the JavaLanguageSupport in the RSTALanguageSupport trunk, I’d appreciate it if you checked out the latest and tried it out.  It has a nice new feature in that, if source is attached to jars on the classpath, code completion suggestions for methods will include the methods’ parameter names (assuming they can be found in Javadoc for the method):

Method param names in choices window

Method param names in choices window

Method param names in parameter assistance

Method param names in parameter assistance

Previously, parameter names were grepped out of the source file being edited’s methods, but for any compiled classes on the “classpath,” method parameters were identified by their type only.  The only way to know what each parameter was (short of having the API you’re using memorized) was to read the information in the description window.

Now, Java support has taken the next step.  It’s already reading the Javadoc for each method to put it into the description window, so why not grep the parameter names out of it, and use them everywhere else, such as the main code completion choices window?

If you point your application to a JDK, it’ll automatically locate the source zip (actually, it already did this). and this feature will work out-of-the-box!

My only concern is performance.  This is an un-optimized feature, and it does result in significantly more I/O (reading from the source zip or directory) than was done previously.  Memory consumption should be about the same, though there may be a lot more smaller temporary objects created (i.e. more GC).  So I request that if you grab the latest, you report back to me if there are any performance issues.

Have fun!

Yet More Java Code Completion Improvements

Saturday, December 18th, 2010

The fun never stops!  A couple more enhancements have been added to JavaLanguageSupport in the past few days.  Both of these are actually possible thanks to enhancements to the AutoComplete library, so you’ll need to update that too, but currently the Java code completion is the only thing that takes advantage of them.

First off, Java completion choices are now sorted by relevance, instead of alphabetically:

Sort by Relevance

Sort by Relevance

Note how the local variables and members are displayed before methods, which are both displayed before class names.  Previously everything was sorted purely alphabetically, putting the things you’re most likely to type (variables, fields and methods) in the middle of a huge amount of classes you’re less likely to want.

The next enhancement is completion suggestions for method parameters.  Now, not only do you get the nifty Eclipse-like parameter tool tip, parameter highlighting, and tab-to-move-between-params, you’ll also get a small popup listing all local variables, members, and getters whose types match (or are subtypes of) the type required for the currently-focused parameter!

Parameter choices completion

Parameter choices completion

Although in the example above there are only a small number of suggestions, note that again, the completions are sorted by relevance.  Also note that you’ll get “null” as a standard suggestion for non-primitive types, and “0” as a standard suggestion for numeric primitive types.

Java Code Completion Improvements

Wednesday, December 8th, 2010

There have been some great improvements to the Java language support in RSTALanguageSupport.  If you haven’t looked at it lately, here’s what you’re missing out on:

1. Import statements are added when code completion inserts a class name that has not yet been imported.  Following in the footsteps of IDE’s such as Eclipse, this feature prevents you from having to manually enter all your import statements; just type away, and hit Ctrl+Space to have them added for you.  Thanks go out to users Guilherme and Jonatas for the initial implementation of this feature, and for making me get off my bum and start working again on the library!

Before...

Before…

... and after.

… and after.

2. Duplicate local variable names are squiggle-underlined and flagged as errors.  A small but useful check.

Duplicate local variables - syntax error

Duplicate local variables – syntax error

3. Fixed a bug, and now the code completion list correctly handles and shows multiple classes/interfaces with the same name, such as javax.swing.text.Document and org.w3c.dom.Document.  Previously only one such class would “win out” and be listed as a completion choice.  Now, they all have equal and fair representation!  Once again, the hard work was done by Guilherme and Jonatas.

Multiple classes/interfaces/enums with the same name

Multiple classes/interfaces/enums with the same name

If you haven’t done so yet, download the RSTALanguageSupport project from SVN and give it a try!

Big Source Browser improvements for Java

Sunday, November 14th, 2010

RText has almost always had a “Source Browser,” a panel docked on the left (by default) that gave an outline of the code in the currently active editor, similar to the “Outline” view in Eclipse.  This component is powered by ctags, either the standard one if you’re on *nix, or Exuberant Ctags on Windows (or again on *nix if configured that way).  Using the former buys you outlines for C source only, while using the latter gets you outlines for any programming language supported by both Exuberant Ctags and RText (really, what’s supported by RSyntaxTextArea).

But not too long ago, as part of my Language Support add-on library efforts, I also implemented an outline tree specifically for Java, almost perfectly mimicking Eclipse’s Outline view.  I’ve been wanting to use it in RText for awhile now, but figured since it was currently Java-specific (won’t display an outline for any other language), it couldn’t be used.  Well, I finally bit the bullet and made RText’s SourceBrowser “pluggable.”  Languages can register a specific tree view for themselves, but if they don’t, it falls back on the standard ctags-based tree.  This allows me to register and use the JavaOutlineTree class only when editing Java code.  Here’s a screenshot:

Java Outline Tree

Java Outline Tree

As you can see, the Source Browser now provides much more detailed, and much nicer looking, information for Java classes.

Perl Language Support Enhancement

Friday, October 22nd, 2010

Newly added to the Perl Language Support in RSTALanguageSupport is the ability to modify the value of the PERL5LIB environment variable used when syntax-checking source code.  This feature has already been integrated into the RText Subversion trunk:

Missing a Perl library

Missing a Perl library

Adding it via PERL5LIB

Adding it via PERL5LIB

Problem solved!

Problem solved!

As the source code in the screenshots say, you can also solve this (a more proper solution in many cases, as well) with “use lib”, but I’m trying to give as much freedom with the language support library as possible.

Auto-Activation added to AutoComplete

Sunday, June 6th, 2010

Sorry for the overloading of the “auto” prefix here… The “AutoComplete” library should probably have been named “CodeComplete”, but the point was to emphasize that it was usable for more scenarios than just code completion…

Anyway, after a few requests, I’m adding what Eclipse refers to as Auto-Activation.  This means that you can have the completion popup appear automatically after certain characters are typed.  For example, typing a ‘.’ character in Java could cause the completion popup to appear after a small delay, removing the need to keep pressing Ctrl+Space.

The new methods are added to the AutoCompletion class, and look like this:

public void setAutoActivationEnabled(boolean enabled)
public boolean isAutoActivationEnabled()
public void setAutoActivationDelay(int millis)
public int getAutoActivationDelay()


These methods allow you to toggle not only whether auto-activation is enabled, but also how long the delay should be between when they stop typing and when the popup appears.  It can be set to 0, meaning to always appear when possible, but often users want a small delay (maybe 200 milliseconds), so that it only shows up if they genuinely need it and stop typing.

Note that auto-activation depends on auto-completion itself being enabled.  If you’ve called setAutoCompleteEnabled(false) on an AutoCompletion, it will not honor the auto-activation property.

As to what characters trigger auto-activation, that is done on a per-CompletionProvider basis, since this can (and should) vary depending on what programming language is being edited.  The CompletionProvider interface now has a method:

public boolean isAutoActivateOkay(JTextComponent)

that should return true or false, depending on whether the text at the current caret position is something that auto-activation should occur at.  The concrete base class, CompletionProviderBase (what all CompletionProviders actually extend from, allow you to set exactly what characters this method checks for:

public void setAutoActivationRules(boolean letters, String others)

The first parameter allows you to have auto-activation occur after any standard letter (e.g. Ascii).  I personally think this is annoying, but I have seen editors do it in the past (Visual Studio?).  The second parameter is a string, each char of which is treated as a char to auto-activate after.  So for example, with Java you could call “setAutoActivationRules(false, “.”)” to auto-activate after the user types a period.  For markup languages you could pass “<” as the “others” String to auto-activate for tag names after ‘<” is typed.

The RSTALanguageSupport library is already taking advantage of this new feature.  The Java, HTML, and PHP supports all now auto-activate after appropriate characters by default.  They’re extra smart, and won’t auto-activate when not appropriate (e.g. typing “foo.” while in Javadoc won’t start auto-completion in Java, or typing ‘<‘ while in a comment or attribute in HTML – while invalid in and of itself – will not cause code completion either).  If you’re an early adopter, be sure to check out out!  It was first added in revision 209.

Integrating Language Support into RText

Saturday, May 22nd, 2010

I’ve spent the last week or so doing tedious, but important, stuff – making sure the RSTALangaugeSupport API is robust enough to be used in other applications.  The hard work is starting to pay off: Perl support is almost completely integrated already!

Perl options in RText

Perl options in RText

Here’s RText’s Options dialog, showing all the features related to Perl support that you can currently toggle.  As you can see, you can currently fiddle with both the code completion as well as the on-the-fly syntax checking I recently blogged about.  For the latter, you have to have a Perl install somewhere on your machine.  RText will scan your PATH for a Perl install, and default to using that, but you can change it to another installation if you want.  Still pending is the ability to add modules to the @INC path.

Language support will be fully integrated into all aspects of RText.  For example, compile errors and warnings will show up in the Error Strip component:

Compiler errors in Error Strip

Compiler errors in Error Strip

Also, function descriptions are displayed simply by hovering the mouse over them.  For example, below, my mouse is over the “print” function (sorry screen captures in Windows don’t capture the mouse pointer):

Function descriptions on mouse hover

Function descriptions on mouse hover

Perl is one of the harder languages to integrate, simply because its language support has so many features (runtime compilation, etc.) that others don’t have.  Hopefully other language supports will be integrated into RText shortly.  Stay tuned!

Perl Syntax Checking

Wednesday, May 12th, 2010

Perl syntax checking has been added to RSTALanguageSupport.  You can configure it with the location of a Perl install on your system (by default it scans your PATH for a Perl binary), and then PerlLanguageSupport will automatically begin scanning your code for errors as you type:

Perl Syntax Checking

Perl Syntax Checking

Next will be the ability to muck with the @INC path to add other libraries.  Currently it only uses the default @INC of your Perl install.

RSTALanguageSupport Progress

Sunday, May 2nd, 2010

The RSTALangaugeSupport library I’ve blogged about for so long has finally been added to the Subversion repository, but do note that it isn’t ready for prime time yet.  Use it at your own risk!  And send feedback when you do!  :)

If you check out the project, please read the readme file first.  It’s fairly up to date and explains how to compile and use the library.

The library currently includes code completion for the standard C library, and despite a couple of rough edges, should be mostly complete:

C code completion

C code completion

C support takes advantage of the parameter assistance feature of the AutoComplete library as well:

Parameter assistance for C functions

Parameter assistance for C functions

There’s also the start of decent support for Java, which is much more robust and dynamic than the support for other languages such as C.  It actually evaluates your code when you hit ctrl+space, and gives you accurate completion choices based on your current location in the code, based on classes you’ve imported (referencing jars on your “classpath”), local variables if you’re in a method, etc.  This has been discussed in several previous blog posts.

Java code completion

Java code completion

Yes, that tree widget on the left is actually included in RSTALanguageSupport as well!  However, it is currently Java-specific, and will not display an outline of source code in any other language.  It’s not high priority at the moment to generalize it, but it should probably happen sooner or later.  Java also supports parameter assistance when completing methods, like C does with its standard library.

There’s also code completion for Perl, supporting all built-in functions in Perl 5.10.x.  Rudimentary support for completions of variable names will appear for Perl in the next couple of days.

Perl code completion

Perl code completion

There’s also excellent support for HTML 5 – completion for all valid tag names, and attributes are suggested as well (only those attributes valid for the tag they are describing).  The description information displayed in the tool tip-style side window is rather lacking, however (as you can tell from the screenshot), so help improving this documentation is more than welcome!

HTML Completion

HTML Completion

PHP code completion is also included.  It uses the built-in HTML support when editing HTML, but when the caret is within PHP tags, PHP functions are suggested instead.  There is no documentation for PHP functions in the description window like there is for other languages just yet.

PHP code completion

PHP code completion

Similar to the C and Java support, parameter assistance is included for PHP functions:

Parameter assistance for PHP

Parameter assistance for PHP

Hopefully that is enough to whet some appetites!  Please discuss and ask questions over in the forums.

Javadoc assistance for Java Code Completion

Sunday, April 11th, 2010

I’ve added the ability to add “source attachments” to jars on the “class path” or “build path” (not sure what to call that, Eclipse uses “build path,” but RSTA isn’t compiling anything, since it’s just an editor…).  You can now get Javadoc in the description window alongside code completion choices.  In the example below, I’m editing java/lang/String.java, and I’ve attached the src.zip that comes with the JDK.  You’ll see that the Javadoc for the relevant String method is shown:

Source Attachments working

Source Attachments working

Beyond that, I’ve been working on the API, using RText as the test application.

Also, not the source outline tree on the left.  I’m working on getting this component simple and usable as well.  I’m tempted to shove it into the RSTALanguageSupport library, since it would only be used with RSTA instances using the library, but since it isn’t specifically related to the editor, it may just end up in RText itself.  It’s really nice – it displays the outline of the source as parsed by the code completion parser, and clicking on an item in the tree jumps to that item in the source code.  However, it is Java-specific and is not currently meant to be used for outlining just any language.