X

Geertjan's Blog

  • August 8, 2008

Tutorial for Editor Code Completion API

Geertjan Wielenga
Product Manager
When you press Ctrl-Space in the IDE, a code completion box pops up with words that you can use to complete the word under the curser. Here's a new tutorial that explains how you can create code completion functionality for your own MIME types or for one of the existing ones:

NetBeans Code Completion Tutorial

The tutorial replaces an older one. It's much better because it focuses specifically on code completion, not on extraneous stuff like web service clients and Options window integrations. In the end, you'll have a simple code completion box in HTML files, listing countries that can be selected and inserted into the editor:

The tutorial applies to NetBeans IDE 6.0 and upwards. It also contains a link to a plugin that provides the sources of the sample, in case you get stuck.

Join the discussion

Comments ( 19 )
  • Casper Bang Friday, August 8, 2008

    Very interesting. We have a desire in our team to get code completion for JPA queries. However, JPA is an embedded DSL inside string annotations. Does the approach described in the tutorial also apply if one wanted to "sub-tokenize" and provide completion inside a String token of a x-java MIME type?


  • Vincent Cantin Saturday, August 9, 2008

    In the tutorial, there should be "at " in:

    public CompletionTask createTask(int i,at JTextComponent jTextComponent) {

    }


  • Casper Bang Sunday, August 10, 2008

    After trying the cool tutorial, a few observations newbies like myself might choke on:

    In "Implementing the Completion Item Class" item 5 you instruct the user to return the text member instance from the getInsertPrefix, and in the line under, you say to return null from

    getInsertPrefix. The former appears to be correct.

    Also, you should probably have the user add the "Utilities API" module library such as to later be able to resolve Uilities.loadImage(...).

    In "Implementing the Action" item 1, you forgot to wrap doc.insertString with a try...catch (though visible later in "Implementing the Filter" item 3).

    The download includes the compiled and packaged .nbm, not the actual source code.


  • Geertjan Sunday, August 10, 2008

    "The download includes the compiled and packaged .nbm, not the actual source code."

    Rubbish. Install it and you have a sample in the New Project wizard, as shown on the plugin's page. Go back there and look at the screenshots.

    Thanks for the other comments, I'll look into them.


  • Casper Bang Sunday, August 10, 2008

    Ohh, the .nbm is a sample extension to NetBeans. In that case, all is well and fine. :)


  • Geertjan Sunday, August 10, 2008

    Exactly! Have fun with it (and read the next blog entry too if you haven't yet).


  • Karl Nickels Tuesday, August 12, 2008

    Thanks for the tutorial information. It is very easy to follow.

    Following the example, I've begun adding code completion to my plug-in for the NWScript scripting language. I've managed to extend the example to display one piece of text (full function declaration or constant with datatype) and insert the useable code (the constant name, or function name with datatypes or default values for parameters).

    My question is - how does Netbeans display the datatype for Java functions on the right side of the completion window all nice and neat? Is there a class I can look at as an example?


  • Karl Nickels Tuesday, August 12, 2008

    I continued on without worrying about the "neatness" of my completion window and ran into another issue.

    The implementation I chose for storing my lists is apparently an unwise choice. Needless to say, I made a static class with two static string arrays, which worked fine for the initial testing with a few entries, but Java apparently does not like a string array with over 8,000 entries, much less two.

    Should I be reading the entries from a data file instead? Should I choose something more dynamic like ArrayList? Or, if you could point me to the source of the relevent section of the Netbeans Java editor, I can try to follow that. I have been unsuccessful in locating it so far.


  • msn avatarları Tuesday, August 26, 2008

    great codes


  • Johannes Wednesday, December 17, 2008

    The link to the tutorial is broken, use this one instead: http://platform.netbeans.org/tutorials/nbm-code-completion.html


  • Dedicated Monday, February 2, 2009

    I am newbie using of Java. I tried getInsertPrefix too. But it doesnt work for me...


  • kolbastı Wednesday, February 4, 2009

    we say this kind of infos as kolbasti


  • Tabela Monday, February 23, 2009

    your labor health


  • Jobs Tuesday, April 7, 2009

    Thanks


  • Web Hosting Wednesday, May 6, 2009

    Thanks for your article..


  • joomla hosting Wednesday, May 13, 2009

    thank you blogs.sun!


  • sunucu Wednesday, May 13, 2009

    Thanks for your article..


  • beylikdüzü halı yıkama Friday, July 3, 2009

    thank you bro!...


  • porno Tuesday, July 14, 2009

    hello.. thank you for this article.


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha