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.
SapphireSteel, makers of the Ruby In Steel plugin for Microsoft Visual Studio, has been touting their own code completion feature for a while. One thing which has irked me a bit is that they tend to dismiss "code completion" as inferior to "true IntelliSense" - as if code completion is the name for simple identifier matching. Just to be clear - IntelliSense is a trademark of Microsoft, so nobody else calls the same feature that. Borland has referred to it as CodeInsight, but most IDEs refer to this feature as code completion.
In this article, SapphireSteel is throwing down the gauntlet by encouraging their users to see if anyone else can produce results like theirs:
To the best of our knowledge, Ruby In Steel’s IntelliSense for Ruby is unrivalled by any other IDE. {...}
We’ve also supplied a few files from our IntelliSense test suite which we invite you to use with Ruby In Steel and any other editor or IDE of your choice.
So, I thought I would show what code completion in NetBeans is capable of. Let's start with test 1, which calls for code completion on an array literal in the source:
As you can see, we show the type of methods right in the code completion dialog. It doesn't matter much for an Array, but if you had invoked code completion on the numbers themselves, you'd see that some methods are coming from Integer, and some are coming from its parent class Numeric - and sometimes it's interesting to know that. Next, let's look at
test 2:
The above example shows the type analyzer tracking types of variables.
More interestingly, notice that while we show the methods on the class "above the line", there are other methods there too. Those are methods inherited into MyClass. In the SapphireSteel screenshots, these methods were turned off, presumably because in Visual Studio they would be interleaved with the regular methods. The evaluation document describes how you can turn Object inheritance on and off in the options. I think our solution is nicer because you get the best of both worlds: the methods you are likely most interested in appear first, but when you ned the "standard" methods (they are there for a reason, after all), they also appear. Thus, if you have a String object and you're completing on the letter "e", you see "empty?" (a String method), but also "eval" (an Object method).
Next,
test 3 which tests module mixins:
Looks fine - and so does test 4 which is a more complicated scope test:
Anyway, I don't want to imply that our code completion is perfect! I still have a lot of things I want to do in our type inference engine. In particular, I want to make sure that code completion works well where it really matters: In code you're writing. Here's a final screenshot from a Rails application where you're writing a controller. Code completion works on important methods like render
, or a method I found myself calling the other day - send_file:
Rails does a number of things that are very tricky to handle for the IDE, so I'll be spending more time in this area to improve code completion for Rails apps.
P.S. To try it yourself, get bits from nbextras.org. As of yesterday we're in Milestone 9 stabilization, so a promoted build should be available within the next couple of weeks.
Hey Tor,
ReplyDeleteGreat work on all this stuff. I am currently evaluating Ruby IDEs and the work you guys have done is impressive. However, a showstopper for me is the absence of a Go to type tool. I often navigate through my project by bouncing from class to class, is this something you guys plan on doing soon or is it a "last mile" feature? Is there a workaround? I know there is a "go to file" plugin for netbeans but it unfortunately doesn't support wildcards. I am currently using the IntelliJ plugin which supports wildcarded go to type and go to symbol navigation, which makes navigating our codebase easy. I wish I had the code completion you guys have built though :)
Thanks again, look forward to seeing your progress.
Ok, see http://blogs.sun.com/tor/entry/saturday_morning_hack for a temporary solution.
ReplyDeleteHi Tor, was curious about responses on the previous screenshot... Seems like a few of us were left floating at the end.
ReplyDeleteTor - when Milestone 9 comes out does that mean we should download this as a full new install, and then use update centre just for the ruby module updates? Also are the 'code template tools' module used for importing Textmate bundles going to be in the Ruby Feature from Update Centre in the next milestone release? Cheers Greg
ReplyDeleteTor - Personally as I don't have too much time for Netbeans testing I'm quite happy to stay on the current version I have until you recommend us changing (i.e. ignoring daily builds, but when there is a milestone or new set of Ruby modules that we should upgrade to do this when you advise us on your blog) - Cheers Greg
ReplyDeleteHello Tor,
ReplyDeletethanks for the great work. Small question: What about the integration of attributes defined by attr_reader? Is this going to be implemented?
I've also added this as a request in netbeans issuezilla but I'm not sure about the current status of the request.
Cheers Fabian
Noticed the support for method argument suggestion - is there any plan to add support for hash arguments? Some sort of comment annotation, perhaps?
ReplyDeleteMost of my methods take one argument: either a hash:
def a_method args = {}
end
a_method :foo => 7, :bar => 'x', :something => 13
It's much less common to do Java-style
def a_method foo, bar, something
end
a_method 7, 'x', 13
James, yes - I'd like to do something in this area. It will be very tricky to do anything automated in this area; most likely it will take the form of some kind of documentation convention.
ReplyDelete