the blog
Back to -Blog

Ruby On Rails IntelliSense #1

Bringing speed and accuracy to Rails code completion
by Dermot Hogan
Wednesday 19 September 2007.

We’re now getting very close to releasing the next version of Ruby In Steel – version 1.2. This has two main components: the first part is better Rails IntelliSense and the second is a set of integrated tools to assist in Rails programming – the Visual Rails Workbench. This is the culmination of about six months work and it’s a major release for us even though the version increment is a mere 0.1.

Because it’s so big, we’ve decided to release it in two stages. The first stage will be the Rails IntelliSense part. In fact this first component has everything – the entire 1.2 codebase but with the Visual Rails Workbench turned off. In Visual Studio terms the Visual Rails Workbench is an ‘editor’, and is basically a standalone item apart from a few menu commands which need to be displayed or hidden depending on whether the Visual Rails Workbench is activated or not. So it’s no big deal to do this from a packaging point of view. But it makes a lot of sense to try and get the Rails IntelliSense bedded down and working before activating a major new chunk of functionality.

The Rails IntelliSense is part of a major rewrite of the IntelliSense system. The first (version 1.0) IntelliSense was (to be honest) pretty clunky. It worked but it was slow. Our second attempt speeded things up a lot, but produced some inaccurate completion lists and didn’t do Rails at all well. This next version – IntelliSense 3 if you like – is a lot faster, slicker and much, much more accurate. It’s so good that we now produce true ‘analytical’ Rails IntelliSense. In other words, we don’t cheat by using lookup lists of Rails functions. Instead, we analyse the actual Rails files and generate the IntelliSense database from these original source files. In effect, we parse and analyse most of the Rails system to do this. And by ’parse and analyse’, I don’t mean pattern matching with a few regular expressions: we do the full nine yards, the whole enchilada. And you can configure it. I’ll explain more of this in my next blog entry and show some examples. All I’ll say right now is that I’ve looked at all the other ‘IntelliSense’ (or ’code completion’ or whatever they call it) systems around for Ruby and I can tell you that our latest iteration beats the pants off the competition.

But for now, I just want to cover one new bit of Visual Studio functionality that I can across only a week ago. One of the problems any Ruby IntelliSense system has is to organise the huge number of methods that are in Object – I think there’s about 100 or so. Since Object is the base class of everything, it means that it’s very easy to get your own methods lost in the Object noise. We’ve tried a couple of approaches to this – letting you selectively disable the display of Object methods, or having an option to turn on and off the display of ‘ancestor’ methods, for example. But what you really need is a quick and easy way of switching between displaying all methods of a variable or class and displaying just the interesting ones.

Last week, I was experimenting with doing just this – and found that Visual Studio has exactly the functionality needed already in place! I was fooling around with a COM interface, IVsCompletionSet, which handles the display that you get after a dot or CTRL-SPACE when I accidentally discovered a totally new interface, IVsCompletionSetEx, which does exactly the filtering required. It turns out that this is also used in Visual Basic, but not, for some reason, in C#. It essentially allows you to split completion lists into a ‘Common’ set and an ‘All’ set. You can in fact put whatever you want in these partitions, but for Ruby it makes sense to have one as a subset of the other.

Here’s a screen shot of a simple completion list (CTRL-SPACE) with all methods displayed:

And here’s the same completion list with just the non-Object methods displayed.

And lastly, here’s the completion list with ‘ancestor’ methods displayed.

The current system of filtering options still exists. You can turn off Object methods entirely, you can exclude global symbols, you can exclude constants and module/class names and you can exclude ancestor methods from a particular class. So at a global level you can control what goes into the completion list and then at a local level, toggle between a simple completion list and a fuller one.

Bookmark and Share   Keywords:  development  rails
  • Ruby On Rails IntelliSense #1
    21 September 2007, by Alex Le

    This is awesome! I’ll ask my company to purchase the license since we are a Microsoft .NET shop and it’s hard to break away from VS. In the end, VS is still THE best IDE out there and Ruby in steel just makes developing Rails more effective and efficient.

  • Keyboard shortcut?
    19 September 2007, by AlexK

    Will it be possible to switch between the tabs in the completion list via a keyboard shortcut?

    • Keyboard shortcut?
      20 September 2007, by Huw Collingbourne

      We hadn’t thought of doing this. I guess it would be possible but it isn’t the default behaviour - for example, as far as I am aware this isn’t done in VB which also uses this two-pane type of completion list. However, if you prefer working in one specific view (either Common or All) you can select this once and from then on that is the view that will be ’in front’ when you next see the completion list. Click the tab to go to the alternative view and that will then become the default unless changed again.

      best wishes


© SapphireSteel Software 2014