Tuesday, April 10, 2007

Ruby Screenshot of the Week #9: Parameter Completion

WARNING: This blog entry was imported from my old blog on blogs.sun.com (which used different blogging software), so formatting and links may not be correct.


Code completion now inserts the parameters for the method you select. They are inserted as a live code template such that you can jump from one parameter to the next using Tab or Return. More importantly, the parameters are also displayed as a tooltip over the method call. You can invoke this whenever you're typing in code - not just using code completion. Hit Alt-P (or on the Mac, Ctrl-P) and if the IDE can figure out the method signature of the method call surrounding the caret, it will display the parameter list, and show the current parameter in bold. As you move the caret around, the tooltip will be updated to show which parameter you're currently editing.






Messing with the user's editing workflow is always risky, so please let me know how you feel the new code completion behavior works. The parameter tooltip depends on being able to figure out the signature of the surrounding method call, which depends on type inference, so it may not always work - but it will also improve as I tweak and improve type analysis across code completion, goto declaration, etc.



Also, there is also a Go To Test action now for jumping quickly between a test class and its unit test. Should work in Rails, RSpec, ZenTest, and also between any classes named Foo, FooTest or TestFoo regardless of which files they're in. This action is in the editor context menu, and is bound to Ctrl-Shift-E. To get this stuff, get at least version 0.65 of the Ruby Feature module (see these installation instructions).



P.S. You can find some more information on the Ruby support in an interview I did with Geertjan Wielenga a couple of weeks ago. There are some other interviews in the same series talking about the new language support in NetBeans. The Rails support in NetBeans will soon have improved support for JavaScript, YAML, and RHTML - stay tuned!


20 comments:

  1. Can we expect NetBeans 6.0 Java editor to be that good? :)

    ReplyDelete
  2. Tor, I love following your posts on the Ruby support in Netbeans 6. On another note is there a separate mailing list to discuss the ruby support in Netbeans or just use the standard Netbeans lists? I don't really see much of any discussion around the Ruby support so I was just curious.

    ReplyDelete
  3. Very nice! IDE's all too often requires you to enter dummy parentheses or hit Ctrl+Space to get this functionality.

    ReplyDelete
  4. What about ctrl-a for beginning of line, ctrl-e for eol, ctrl-k/y for kill buffer/yank buffer, etc.? Seems that cmd works for these, but we need both as in normal cocoa apps on mac os x for sanity sake.

    ReplyDelete
  5. Autocomplete does not seem to be working, do I need to hit ctrl-space or something to activate it? If I, for example, type in "@test = Test.f" I'm not getting completion directly after the "." operator. I should see things like, "find" and such available I would think.

    ReplyDelete
  6. Not to mention cmd-left/right to move to the beginning and end of line versus skipping words, which should be option-left/right... Seems like the keybindings really needs some work to feel right on the mac.

    ReplyDelete
  7. Btw, while ctrl-a etc. isn't working, Command-Left/Right -should- be working (going to the beginning/end of the line - although note that it goes to the first/last non-space character; a second press goes to the raw start/end of the line). Option left/right should be jumping by words.

    ReplyDelete
  8. Thanks for that update and information Tor; can you make auto-activated completion an easily accessible option so that it can quickly be toggled? For me it seems that it would be much better than ctr-space as I have that bound to another system wide function that I've used for years now.


    ReplyDelete
  9. Hi Tor,
    I am, above all, interested in having first-class autocomplete. I am just unable to remember the name of the methods of the class I created a minute ago.

    Big problem with Ruby, when you define a class, you don't specify the types of its arguments. I concede that is SO powerful but, in many cases, we would probably be better served by giving the IDE a hint of the class we are passing, using some kind of annotations.

    The Sapphire Steel guys, which are doing what I believe is a very nice work to get good Intellisense, let you use optional comments in a special format before the declaration and have the ide parse them to infer the types of arguments and return value.
    They refer this as "Type assertions" and this is a sample:



    Example:

    #:return:=>Array

    #:arg:names=>Array

    #:arg:aName=>String

    def addName( names, aName )

    return names << aName

    end



    So, when you later type addName(, the autocomplete shows this tooltip:

    addName( names:Array, aName:String):Array


    I don't want to start a religion war on typed vs. typeless languages. Truth is I may be wrong but, coming from a Java background, I miss so much a good autocomplete capability in the IDE.

    The keyword here is OPTIONAL; since you don't have to do it if you don't like it, it would be only for the rest of us who would really appreciate this feature.


    However, if in the end you decide to implement this feature, I think it would be nice to follow the syntax of Sapphire, so the code can be more easily transferred and we avoid creating Ruby dialects. Or, a "Save as Sapphire Comments" or similar can be also a good option.


    Anyway, thanks for your great work.


    Jose Femenias,
    (big fan of Java Posse)

    P.S.: Sample was taken from this page http://www.sapphiresteel.com/onlinehelp/Type%20Assertions.html

    ReplyDelete
  10. Thank you! The . auto-completion makes everything much more natural. (For me)
    How far away from 'finished' is all this? Is it somewhat dependent on JRuby reaching 1.0?

    ReplyDelete
  11. Hi Tor,



    Ruby1-985 complained today about not meeting the requirements for language support. Looks like it's relying on the next nightly build of Netbeans IDE (ver. 17-04-06 was mentioned in the error).



    So, instead of building Netbeans myself, I'm trying out the RubyIDE build. Are there any outstanding issues related to running on Mac? You mentioned there were some problems a while back wiuth keybindings, packaging etc.

    ReplyDelete
  12. I lost a year in that error message, it should be version "070417".



    Don't worry about previous question. Since I'm in a different timezone (Italy), I've plenty of time to find out how the IDE build fares. The Wiki info is up to date on current IDE build issues I think.



    Do you want rhtml bug reports yet, or would it be better to wait?

    ReplyDelete
  13. Tor,

    thanks a lot for the support for type assertions and the very quick answer. I understand the subject could be controversial because it seems restricting; that's why I insisted on the optional nature of the implementation. Hopefully, this will satisfy most of us...(But, you know, "You can SATISFY some of the people all of the time, and all of the people some of the time, but you can not SATISFY all of the people all of the time"; hope Mr. Lincoln forgives me for the paraphrasing )
    I'm willing to test the feature ASAP.
    Thanks AGAIN!

    ReplyDelete
  14. Thanks Tor. Hope to see some of the other key binding issues, etc. worked out soon.

    ReplyDelete
  15. Hey Tor, noticed a lot of things going on with RHTML - that's great. I've been looking forward to seeing things like paren and braces completion etc. as well as <%%>, etc.



    Is there a work-in-progress cheatsheet floating around for functions and features currenting being developed/WIP? I'd sure like to see things like how to actually USE the abbreviations that you've just added as well as standard other functions that we're not familiar with. NB is very new for most rubists and we need a little hand holding to get started, especially for whiz-bang features that really will sell us on it.

    ReplyDelete
  16. Is it possible to make the "." completion to come up quicker? or to look for completion after even having started on the word to complete? For example, "assert s.valid?", when typing this it should autocomplete even after typing "s.va" (it still should resolve down to valid, rather than not offering anything due to the "." being passed before given time to search for completion term.



    Also, when typing, for example: "assert_redirected_to :action => 'index'" it does not start autocompleting "asser"... as it seems that it should just by virtue of inspecting Rails. Seems that the autocomplete is not fully baked yet or am I missing something?

    ReplyDelete
  17. Is CSS autocompletion coming or is there a way to tie NB RHTML and CSS development into Firebug for Firefox for sticky editing?

    ReplyDelete
  18. Hey Tor,
    I sent you email with some questions, but I quite unsure if you got one. If not can you let me know here, I will resend that email again.

    ReplyDelete
  19. Tor, what's the chance of seeing a "good" dark theme for NetBeans? I'm really used to dark themes for normal development tools and IDEs since they are easier on my eyes... I doesn't seem that a very good method of putting this together currently exists for all windows in the app views.

    ReplyDelete