Ruby & code-completion [with Vim]

These days I was looking for an environment for ruby, which provides advanced development helper stuff (like code completion for example).  Because of the issue, that ruby is an out-and-out dynamic language, such help provider turn out to become a very complex topic.

However, after all I discovered a quite nice editor-independend tool-collection, called rcodetools. Information is available at RubyForge and here.

rcodetools is a collection of Ruby code manipulation tools for automagic Test::Unit(RSpec) assertion generation, code annotation, 100% accurate code completion, code and documentation browsing, precise method information (rcodetools is meta-programming aware)…

rcodetools 0.7.0 introduces “test-driven completion” (TDC) which allows 100%-accurate completion while alternating between implementation and tests. Several new mechanisms allow faster development in large projects, and xmpfilter supports RSpec’s latest syntax.

rcodetools can be used with any editor, but it ships with emacs and vim support.

Since I’m a Vim-user, it’s perfect to me … and the deployment is rather easy, if you know what to do. ;-)

Assuming Ruby and RubyGems are installed and working, you can simply install it via RubyGems:

gem install rcodetools
gem install fastri

The last one you’ll just need, if you want documentation browsing support. Though I thought, RubyGems does it automatically,  I additionally had to execute the particular setup.rb (e.g. /usr/lib/ruby/gems/1.8/gems/rcodetools-0.8.5.0/setup.rb [path may vary]) as root to set it up properly.

As next step, you have to copy the rcodetools.vim from the mentioned gem-directory into the Vim‘s plugin-directory: in my case: ~/.vim/plugin/).

If you want documentation browsing support, you’ll have to add following line to your Vim-config (~/.vimrc):

let g:rct_completion_use_fri = 1

. Again, this will only work, if you install fastri first. Every time you wanna use it, fastri-server (shipped with the gem) must run.

Now everything should be set up proberly and working. Here is a nice screen-view, how it should look like:

Vim with Ruby code-completion.

At last, one important thing is to say about it: Be aware of the side effects of such technologies! As mentioned above, Ruby is a dynamic language. This means, the plugin has to execute your ruby code to obtain the information it needs. For instance this sideeffect takes place, if your code is deleting a file or sending an email. While you are using the code-completion feature, your code is executed before you really want to. So your file is already deleted or the email is already sent, before you start your program.

One Response to “Ruby & code-completion [with Vim]”

  1. Ruby & code-completion [with Vim] (via vootey’s blog) « Carbon Five News Network Says:

    [...] Ruby & code-completion [with Vim] (via vootey’s blog) Posted on December 17, 2010 by christianbradley These days I was looking for an environment for ruby, which provides advanced development helper stuff (like code completion for example).  Because of the issue, that ruby is an out-and-out dynamic language, such help provider turn out to become a very complex topic. However, after all I discovered a quite nice editor-independend tool-collection, called rcodetools. Information is available at RubyForge and here. rcodetools is a collection of Ruby … Read More [...]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.