From 86297a7c65eadc5dc7668e129c92316aa0a89898 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 26 Jul 2017 10:29:46 +0100 Subject: [PATCH] Fix #804 - Do not run scalac for sbt files --- ale_linters/scala/scalac.vim | 28 ++++++++++++++++++++++---- test/handler/test_scalac_handler.vader | 18 +++++++++++++++++ 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 test/handler/test_scalac_handler.vader diff --git a/ale_linters/scala/scalac.vim b/ale_linters/scala/scalac.vim index 4bc0cb8..9262e62 100644 --- a/ale_linters/scala/scalac.vim +++ b/ale_linters/scala/scalac.vim @@ -1,6 +1,26 @@ -" Author: Zoltan Kalmar - https://github.com/kalmiz +" Author: Zoltan Kalmar - https://github.com/kalmiz, +" w0rp " Description: Basic scala support using scalac +function! ale_linters#scala#scalac#GetExecutable(buffer) abort + if index(split(getbufvar(a:buffer, '&filetype'), '\.'), 'sbt') >= 0 + " Don't check sbt files with scalac. + return '' + endif + + return 'scalac' +endfunction + +function! ale_linters#scala#scalac#GetCommand(buffer) abort + let l:executable = ale_linters#scala#scalac#GetExecutable(a:buffer) + + if empty(l:executable) + return '' + endif + + return ale#Escape(l:executable) . ' -Ystop-after:parser %t' +endfunction + function! ale_linters#scala#scalac#Handle(buffer, lines) abort " Matches patterns line the following: " @@ -38,8 +58,8 @@ endfunction call ale#linter#Define('scala', { \ 'name': 'scalac', -\ 'executable': 'scalac', -\ 'output_stream': 'stderr', -\ 'command': 'scalac -Ystop-after:parser %t', +\ 'executable_callback': 'ale_linters#scala#scalac#GetExecutable', +\ 'command_callback': 'ale_linters#scala#scalac#GetCommand', \ 'callback': 'ale_linters#scala#scalac#Handle', +\ 'output_stream': 'stderr', \}) diff --git a/test/handler/test_scalac_handler.vader b/test/handler/test_scalac_handler.vader new file mode 100644 index 0000000..a4c7363 --- /dev/null +++ b/test/handler/test_scalac_handler.vader @@ -0,0 +1,18 @@ +Before: + runtime ale_linters/scala/scalac.vim + +After: + call ale#linter#Reset() + +Given scala(An empty Scala file): + +Execute(The default executable and command should be correct): + AssertEqual 'scalac', ale_linters#scala#scalac#GetExecutable(bufnr('')) + AssertEqual + \ ale#Escape('scalac') . ' -Ystop-after:parser %t', + \ ale_linters#scala#scalac#GetCommand(bufnr('')) + +Given scala.sbt(An empty SBT file): +Execute(scalac should not be run for sbt files): + AssertEqual '', ale_linters#scala#scalac#GetExecutable(bufnr('')) + AssertEqual '', ale_linters#scala#scalac#GetCommand(bufnr(''))