Ruby Screenshot of the Week #9: Parameter Completion

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!

Comments:

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

Posted by Romain Guy on April 10, 2007 at 05:11 PM PDT #

Hi Romain!

Yes, the Java editor also has this functionality!

Posted by Tor Norbye on April 10, 2007 at 05:27 PM PDT #

Wooohooo \\o/

Posted by Romain Guy on April 10, 2007 at 06:53 PM PDT #

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.

Posted by Scott Walter on April 10, 2007 at 11:14 PM PDT #

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

Posted by Casper on April 11, 2007 at 12:30 AM PDT #

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.

Posted by Ralph on April 11, 2007 at 06:57 AM PDT #

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.

Posted by Ralph on April 11, 2007 at 06:59 AM PDT #

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.

Posted by Ralph on April 11, 2007 at 07:31 AM PDT #

Hi Ralph -
the Mac keybindings recently got broken; up until Milestone 7 this worked. I've been involed in some e-mails on the subject; I'll make sure there's a high priority bug filed on this.

Yes, you need to use Ctrl-Space to invoke code completion. I used to have it auto-activated on "." but got some complaints that it was getting in the way. (It -does- auto activate on ::, e.g. Test::Unit:: will show TestCase and friends).

Hi Scott, we do have an alias named dev@scripting.netbeans.org dedicated to this but there isn't a lot of traffic yet; it's mostly being done through the issue tracker - and a lot of the feedback is coming in through the blog right now :)

Posted by Tor Norbye on April 11, 2007 at 07:38 AM PDT #

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.

Posted by Tor Norbye on April 11, 2007 at 07:51 AM PDT #

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.

Posted by Ralph on April 12, 2007 at 01:15 AM PDT #

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

Posted by Jose Femenias on April 12, 2007 at 04:12 AM PDT #

Hi Ralph, I've added a property you can set to get auto completion on typing ".": Run with -J-Druby.dotcomplete=true . The problem with the behavior right now is that if you're typing, let's say pi = 3.14, the dot will initiate code completion and you get an empty completion dialog saying "no suggestions". For these scenarios I need to suppress completion (when you're just typing right through), before making this the default property.

Hi Jose, as of the latest version type assertions are supported. I have looked into this before (and it's part of my JavaOne talk on Ruby tooling), and type assertions are definitely controversial - especially if it's used by code completion to tell you the expected type of methods (since that seems to restrict Ruby's duck typing). On the other hand, it can help your productivity in your own methods if you annotate them with these in that code completion can be more direct. So that's the part I have implemented - type assertions will help the type inference engine when you're using code completion inside that method. They are not propagated to clients elsewhere (yet - something to discuss).

To get these features you need the very latest builds - deadlock build #913 or later (but the Ruby build is not running now; it's waiting for the upstream trunk build to build successfully - so give it a little while.)

Posted by Tor Norbye on April 13, 2007 at 04:56 AM PDT #

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?

Posted by Steven Herod on April 13, 2007 at 09:45 PM PDT #

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.

Posted by Si on April 16, 2007 at 06:08 PM PDT #

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?

Posted by Si on April 16, 2007 at 07:40 PM PDT #

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!

Posted by Jose Femenias on April 17, 2007 at 02:35 AM PDT #

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

Posted by Ralph on April 17, 2007 at 03:48 AM PDT #

Hi Steven, "How far from finished is this?" - It's still beta quality - and unfortunately, we don't have a stable build to point to - so even though it's usually two steps forward from build to build, sometimes it's one step backwards when something breaks. There's been a couple of serious bugs in the last day or two which affected the Ruby support. Tomorrow is the feature freeze for Milestone 9, and at that point we go into stabilization mode for a week. Milestone 9 should be a reasonable build to stay with for a while.

Hi Si, it's still a bit early for RHTML bug reports - a bunch of new stuff landed yesterday (code completion in the HTML part, a navigator) but unfortunately it's affected regular Ruby editing a bit. We'll get this ironed out in the next couple of days. Again, Milestone 9 should be a good build to use and report bugs on.

Jose, yep - we can't satisfy everybody :) But hopefully this is a good start.

Posted by Tor Norbye on April 17, 2007 at 10:49 AM PDT #

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.

Posted by Ralph on April 18, 2007 at 01:13 PM PDT #

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?

Posted by Ralph on April 18, 2007 at 01:18 PM PDT #

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

Posted by Ralph on April 18, 2007 at 01:21 PM PDT #

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.

Posted by Sergey Kuznetsov on April 19, 2007 at 01:47 AM PDT #

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.

Posted by ylon on April 19, 2007 at 09:16 AM PDT #

Ralph, I'll try to improve the automatic . completion soon. However, I was only thinking auto complete would happen on typing "." or "::". Were you thinking it should start even when typing the prefix to a method call? That sounds like it could get a bit too aggressive. I think it's possible to rebind the auto-complete key from ctrl-space to something else - that might help for right now.

Regarding CSS auto completion - the CSS and JavaScript support is being revamped right now - as is RHTML and embedding of these other languages, but I'm not sure exactly how far along it is yet.

Sergey, yep - I got your e-mail - it got buried in my inbox (33,286 messages right now and counting) but I just fired off a reply (and filed an enhancement request on your behalf in Issuezilla.)

Ylon - yes, I have a dark theme I'm using - inspired by the BlueTheme for TextMate. It works okay for Ruby - but I haven't at all tweaked it for other files, such as RHTML. If you want to try it, e-mail me - and maybe we can work together to polish it such that we can spread it more widely.

Posted by Tor Norbye's Weblog on April 25, 2007 at 04:46 AM PDT #

By the way, here's what it looks like: http://blogs.sun.com/tor/resource/bluetheme1.png.

Note however that the rest of the IDE - including code completion popups and such - uses the look and feel of the application, which at least in my case stays white and Mac-like. The one area which is problematic is editor highlights like breakpoints, which don't seem to be configurable by theme - and the breakpoint colors don't work well with a dark theme. I'm going to ping somebody to see what can be done about this.

Posted by Tor Norbye's Weblog on April 25, 2007 at 04:55 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

Tor Norbye

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today