The Ruby Librarian
One of the annoying things about analysing source code for IntelliSense is that (currently) Ruby In Steel re-analyses code that clearly hasn’t been changed.
Consider this code:
c = Complex.new(1, 1)
In the current version of Ruby In Steel, the ‘require’ is examined first and the code file specified is loaded and parsed. Then the following code statements are parsed. This sequence is repeated over and over as you type in order to generate the IntelliSense. However, it’s pretty clear that in most, if not all, circumstances, the text in ‘complex.rb’ has not changed. Yet, it is still re-analysed along with the two or three lines of text that we’re really interested in.
This isn’t normally too much of a problem. Parsing a file is pretty quick and, for simple files which don’t do too many requires themselves, it works out ok. Where it doesn’t work well is if the file is complicated or hauls in most of the Ruby libraries (either by design or accident). The library file ‘date.rb’ is one of my favourite test cases. It’s big (3200 lines) and seems to take a fair amount of time to parse yet it’s actually doing something pretty simple – providing dates and times to Ruby programs.
The other problem area is Rails. Rails is complicated and, in addition, it isn’t obvious sometimes which files to include or require for a particular project, since Rails does all this dynamically. A similar situation exists if you have a large Ruby project. You really want some sort of ‘library’ to specify what types and classes are used in the programs and to include that ‘type library’ to assist with the IntelliSense.
This is where our new Librarian comes in. The Librarian allows you to create compiled IntelliSense libraries for use in your projects. So for example, if you have this source code:
There are no requires - I’ve commented the date require out - and yet if I hover over the Vector class, I get this (showing that Vector has indeed been resolved:
If you look in the Solution Explorer, you’ll see this:
Under the References node, there are three Reference nodes complex, date and matrix, corresponding to the standard Ruby library files, complex.rb, date.rb and matrix.rb. These have been added to the References folder using the standard Add References tool:
But there’s more! You can also create and edit your own IntelliSense ‘stub’ file customised to your exact needs. Even better, you can also create a library for Rails that knows about the database structure of your tables: Rails Database IntelliSense.
I’ll explain how all this works and how to do it next week.
The Librarian will be part of Ruby In Steel Deeveloper 1.3. We hope to get a beta of this out to registered users within the next week or so. The final release should be available a few weeks after that.