Archive for the ‘AutoComplete’ Category

RSyntaxTextArea 1.4.2 Released!

Monday, August 2nd, 2010

Last night, RSyntaxTextArea 1.4.2 was released on SourceForge!  That includes new releases of RSyntaxTextArea as well as AutoComplete and SpellChecker.  This release was mostly about bug fixes and improvements in code completion behavior.  Here’s a quick list of all of the changes in this release.

  • Groovy syntax highlighting updates (GDK Object methods, Java 5/6 java.lang classes, URL’s in comments)
  • A fix to prevent security exception when setting AA hint in an applet (thanks to Frederic in the forums)
  • Fixing positioning of FocusableTips and code completion windows on multi-monitor setups (thanks to grzlbrmft in the forums for the bug report and testing).  I’m personally jealous of everybody out there with a dual monitor setup, who got to experience this bug.  :)

    AutoComplete Windows

    AutoComplete Windows

  • AutoComplete’s description window now updates itself in response to a selection change after a small delay (120ms) instead of immediately, to help performance for language supports with slower descriptions (e.g. file IO).  This mimics Eclipse’s behavior.
  • Added ActionScript syntax highlighting.  Perhaps now I have no excuse to play with this language.

    ActionScript

    ActionScript

  • Improved performance of auto-completion list cell renderer for huge completion lists.  Helps with languages with huge amounts of functions, such as PHP.
  • When using SearchEngine, if the next match isn’t currently visible, center the found/replaced text after the search operation.  This is a seemingly small change but is a nice usability improvement, and is seen in better editors like Eclipse.  For example, if your cursor is here:
    Starting to Search

    Starting to Search

    And you used SearchEngine#find() in RSTA 1.4.1 to find the next instance of “clip”, the next instance would be selected and brought into the visible area like so:

    SearchEngine#find() result before 1.4.2

    SearchEngine#find() result before 1.4.2

    Note that the next instance is selected, but is barely scrolled into the view.  Starting with 1.4.2, the next match is scrolled to the center of the text area, vertically:

    SearchEngine#find(), after 1.4.2

    SearchEngine#find(), after 1.4.2

    If the next instance of the text you’re searching for is already visible, the editor is not scrolled, the text is merely selected.  If the next match is not currently visible, however, that’s when it will be scrolled to the center of the view.

  • Fix for SourceForge bug 2998448: regex “replace all” is always case-sensitive.
  • SearchEngine’s concept of “whole word” is more accurate now (allows for punctuation, such as ‘,’, at the end of words, for example).  Previously, a “whole word” had to be completely surrounded by whitespace.
  • Added start of JUnit tests for SearchEngine.java.
  • SearchEngine bug fixes for replaceAll() with regex and match case/whole word enabled.
  • Fixed auto-complete bug with overloaded functions.
  • Fixed auto-complete bug – capitalization should be corrected when completing a parameterized completion.
  • Improved properties file syntax highlighting: ‘:’ can divide name/value pairs.
  • Added “our” keyword to Perl syntax highlighting.

Grab it on the SourceForge page today!

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.

Smarter Auto-Indentation

Sunday, January 25th, 2009

The next release of RSyntaxTextArea will feature smarter auto-indentation for languages that use curly braces to denote code blocks, such as C, Java and Perl.  Instead of just remembering the previous line’s indentation, now, lines in a new code block are indented, and typing the closing ‘}’ character of a code block out-dents that character.  This is a rather small feature but most editors these days offer it, and once you get it used to it, it’s hard to go back to an editor that doesn’t have it!

Check out revision 70 in Subversion if you want to check it out early.

AutoCompletion site now up

Saturday, January 17th, 2009

AutoCompletion has enough features now where I’d really like other people to start trying out.  So I’ve added a little space for it on fifesoft.com describing what it is and (soon) how to use it. There’s a nice WebStart example there of an editor for C with code completion for the C standard library.  The Javadoc is up as well. All that is needed now is a couple of examples to get people started.

I also can’t decide if AutoComplete warrants its own SourceForge project, or if it can just be a subproject of RSyntaxTextArea. While the library can be used on any JTextComponent, auto-completion is usually used in IDE’s and programmer’s editors, and AutoComplete does come with special hooks to work better with RSTA. On the other hand, being a separate project may allow it to be discovered and used by a larger audience. Decisions, decisions…

Function Parameter Assistance

Monday, January 12th, 2009

Newly added to the AutoComplete library is parameter assistance… I’m not sure what you should actually call this feature, but it’s the one where typing a ( character causes a little tooltip to pop up describing the parameters for the function you’re entering:

param_complete1

Parameters are entered with default values. You can use tab and shift+tab to navigate through the parameters (ala Eclipse or NetBeans). The parameter you’re entering (separated by commas, for example) is highlighted in bold in the tooltip, and (if available), a short description of the currently active parameter is displayed.

This feature is configurable, just like the other autocomplete options, and can be turned off if you don’t have time to enter descriptive information about everything available to auto-complete.

I plan on making a very early release available on SourceForge this week. I’m interested in getting as much feedback as possible! As far as I know, RSTA and the AutoComplete library is the simplest way to get easy and powerful IDE-style features into Swing applications.

A minor update to RSyntaxTextArea will also be released, fixing a couple of minor bugs that have been reported by users.

AutoComplete added to Subversion

Wednesday, December 24th, 2008

I’ve gone ahead and added the AutoComplete project and its demo project to the RSyntaxTextArea Subversion repository.  Consider this to be a very early preview release.  Feedback is more than welcome, but please keep in mind that this is very much a work in progress!

AutoComplete can work on any JTextComponent.  It does not require RSyntaxTextArea.  But moving forward, it will come with built-in support for RSyntaxTextArea (it will be able to key off of its document parsing to deliver more intelligent completion choices, for example).  But feel free to use it in JTextFields or whatever else you want to use it in.

Javadoc for this early preview is here.  Check out the AutoCompleteDemo application for example usage.  The current simplest usage (just completion of simple words) is:


String[] words = new String[] { "aardvark", "angela", "apparel", "apple", "axe" };
WordCompletionProvider provider = new WordCompletionProvider(words);
AutoCompletion ac = new AutoCompletion(provider);
ac.setShowDescWindow(false);
ac.install(myTextComponent);

This will add autocompletion support for the words in the words array to myTextComponent. Simple as that. AutoCompleteDemo is a more complex example, providing autocompletion for the standard C library, complete with summaries of each method (see the screenshots below).

The code only requires Java 1.4 or greater to run, so practically everyone should be able to use it.  The license is LGPL, just like RSyntaxTextArea.

More Autocompletion progress

Tuesday, December 23rd, 2008

There’s been more autocompletion progress. It’s been mostly dirty work (making the API flexible, etc.), but there have been some cool new features added as well. First off, the rendering of autocompletion choices is now completely configurable, using standard ListCellRenderers. There will be a standard renderer that will try to nice things up a little for standard procedural and OO languages. Also, the completion and description windows are now resizable! This is a big usability improvement.

Here’s an updated screenshot of how things are looking now:

Autocompletion preview 2

Autocompletion preview 2

Autocompletion – Coming Soon!

Friday, December 19th, 2008

Here’s a little teaser…

Autocompletion Preview

Autocompletion Preview

Pretty nice huh?  It was easier to get basic autocomplete up and running in RSyntaxTextArea than I thought.  This will be an add-on library for RSTA, as not everybody will want or need this feature, and I’m trying to keep the core editor’s size down to a minimum.

It’s definitely still got some bugs and quirks, but it’s already in a usable state.  The project will get added to the RSTA Subversion repository once it’s a little more fully cooked.