Saturday, February 2, 2013

Quick bug fixing in Scala with SBT and Vim


UPDATE: Dave Cleaver created a SBT plugin do generate quickfix! https://github.com/dscleaver/sbt-quickfix

Until now if you wanted to have vim quickfix integration with SBT, you had two solution:
Unfortunately none of them are in my opinion usable for day to day development:
  • Launching SBT from Vim create a new instance of SBT at each call, and starting SBT takes time... lot of time.
  • VimSIDE is still very experimental (wasn't able to make it work outside of the demo project) and heavy, too heavy for me... one of the reason I love using Vim it's because it's light, fast and he don't try to change the code I write because he pretend to be smarter than me (like IntelliJ).
So, I like to use SBT in his own shell, running in interactive mode and enjoying the power of '~' for continuous compilation/testing.
The only thing is that each time I'm fixing compilation errors/warnings I have to navigate manually to the file and enter the line number to jump in the right place.

This time is over!
The solution is very simple (but very hacky!), just a single bash script which:
  • Append warn/error SBT messages into a temporary file
  • Monitor certain action done in the interactive session and delete the file when necessary
Let's see how the script looks like:
That's all! if you want to use it:
  • Download and make it executable
  • Add it to your path with a fancy name (hint: qsbt)
  • Edit your .vimrc to add the SBT error format pattern and a key-binding (check comments in the script for an example).
And now enjoy continuous quick-fixing by starting sbt with the qsbt script!

No comments:

Post a Comment