Saturday, September 1, 2012

Syntastic Scala fix

Syntastic is an awesome vim plugin. I've been programming in scala recently and syntastic works with scala which is awesome, except one issue which has been annoying me. Since syntastic uses "scala" on the command line to find errors in the script it considers the package statement at the start of the script as an error. "scalac" is a better command to find the errors but when compiling a file in isolation it compains about imports from dependent libraries. A reasonable option seems to be stop scalac after the parsing step.

Here's the patch:

diff --git a/syntax_checkers/scala.vim b/syntax_checkers/scala.vim
index f6f05af..941054d 100644
--- a/syntax_checkers/scala.vim
+++ b/syntax_checkers/scala.vim
@@ -24,7 +24,7 @@ if !exists("g:syntastic_scala_options")
 endif

 function! SyntaxCheckers_scala_GetLocList()
-    let makeprg = 'scala '. g:syntastic_scala_options .' '.  shellescape(expand('%')) . ' /dev/null'
+    let makeprg = 'scalac -Ystop-after:parser '. g:syntastic_scala_options .' '.  shellescape(expand('%'))

     let errorformat = '%f\:%l: %trror: %m'


Basically just set makeprg to 'scalac -Ystop-after:parser '. g:syntastic_scala_options .' '.  shellescape(expand('%'))

3 comments:

  1. Can you open a pull request against the Syntastic repo with this fix?
    https://github.com/scrooloose/syntastic

    ReplyDelete
  2. + thanks! I just tried this out and it was so nice to not have that line marked as an error!

    ReplyDelete
  3. The problem with this fix is that basic problems like undefined variables aren't picked up.

    ReplyDelete