From a8915d885b79ba8e243c228c9f38dddbcb1c479a Mon Sep 17 00:00:00 2001 From: Evan Borden Date: Fri, 28 Sep 2018 04:05:01 -0400 Subject: Add better support for Haskell stack compiler tools (#1851) * Add better support for Haskell stack compiler tools This commit adds support for `stack` as the executable of a tool. This follows a pattern that has been implemented for `bundler`'s tool chain. * Move hlint command to linter file * Add vader test for stack exec handling * Update ghc-mod to support stack execution `ghc-mod` was previously broken into 2 linters. 1. ghc_mod 2. stack_ghc_mod This additional linter is not necessary with proper support for executable variables and `stack exec` handling. * Support stack exec in hfmt * Support stack in hdevtools --- autoload/ale/fixers/brittany.vim | 10 ++++++++-- autoload/ale/fixers/hfmt.vim | 2 +- autoload/ale/fixers/hlint.vim | 5 +---- autoload/ale/fixers/stylish_haskell.vim | 10 ++++++++-- autoload/ale/handlers/haskell_stack.vim | 7 +++++++ autoload/ale/handlers/hlint.vim | 8 ++++++++ 6 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 autoload/ale/handlers/haskell_stack.vim create mode 100644 autoload/ale/handlers/hlint.vim (limited to 'autoload') diff --git a/autoload/ale/fixers/brittany.vim b/autoload/ale/fixers/brittany.vim index 57c77325..c2448348 100644 --- a/autoload/ale/fixers/brittany.vim +++ b/autoload/ale/fixers/brittany.vim @@ -3,11 +3,17 @@ call ale#Set('haskell_brittany_executable', 'brittany') -function! ale#fixers#brittany#Fix(buffer) abort +function! ale#fixers#brittany#GetExecutable(buffer) abort let l:executable = ale#Var(a:buffer, 'haskell_brittany_executable') + return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'brittany') +endfunction + +function! ale#fixers#brittany#Fix(buffer) abort + let l:executable = ale#fixers#brittany#GetExecutable(a:buffer) + return { - \ 'command': ale#Escape(l:executable) + \ 'command': l:executable \ . ' --write-mode inplace' \ . ' %t', \ 'read_temporary_file': 1, diff --git a/autoload/ale/fixers/hfmt.vim b/autoload/ale/fixers/hfmt.vim index ea061da4..0407b713 100644 --- a/autoload/ale/fixers/hfmt.vim +++ b/autoload/ale/fixers/hfmt.vim @@ -7,7 +7,7 @@ function! ale#fixers#hfmt#Fix(buffer) abort let l:executable = ale#Var(a:buffer, 'haskell_hfmt_executable') return { - \ 'command': ale#Escape(l:executable) + \ 'command': ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'hfmt') \ . ' -w' \ . ' %t', \ 'read_temporary_file': 1, diff --git a/autoload/ale/fixers/hlint.vim b/autoload/ale/fixers/hlint.vim index 94dd736e..88779a55 100644 --- a/autoload/ale/fixers/hlint.vim +++ b/autoload/ale/fixers/hlint.vim @@ -1,13 +1,10 @@ " Author: eborden " Description: Integration of hlint refactor with ALE. " -call ale#Set('haskell_hlint_executable', 'hlint') function! ale#fixers#hlint#Fix(buffer) abort - let l:executable = ale#Var(a:buffer, 'haskell_hlint_executable') - return { - \ 'command': ale#Escape(l:executable) + \ 'command': ale#handlers#hlint#GetExecutable(a:buffer) \ . ' --refactor' \ . ' --refactor-options="--inplace"' \ . ' %t', diff --git a/autoload/ale/fixers/stylish_haskell.vim b/autoload/ale/fixers/stylish_haskell.vim index a352312f..ce71c1ce 100644 --- a/autoload/ale/fixers/stylish_haskell.vim +++ b/autoload/ale/fixers/stylish_haskell.vim @@ -3,11 +3,17 @@ " call ale#Set('haskell_stylish_haskell_executable', 'stylish-haskell') -function! ale#fixers#stylish_haskell#Fix(buffer) abort +function! ale#fixers#stylish_haskell#GetExecutable(buffer) abort let l:executable = ale#Var(a:buffer, 'haskell_stylish_haskell_executable') + return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'stylish-haskell') +endfunction + +function! ale#fixers#stylish_haskell#Fix(buffer) abort + let l:executable = ale#fixers#stylish_haskell#GetExecutable(a:buffer) + return { - \ 'command': ale#Escape(l:executable) + \ 'command': l:executable \ . ' --inplace' \ . ' %t', \ 'read_temporary_file': 1, diff --git a/autoload/ale/handlers/haskell_stack.vim b/autoload/ale/handlers/haskell_stack.vim new file mode 100644 index 00000000..108301a9 --- /dev/null +++ b/autoload/ale/handlers/haskell_stack.vim @@ -0,0 +1,7 @@ +function! ale#handlers#haskell_stack#EscapeExecutable(executable, stack_exec) abort + let l:exec_args = a:executable =~? 'stack$' + \ ? ' exec ' . ale#Escape(a:stack_exec) . ' --' + \ : '' + + return ale#Escape(a:executable) . l:exec_args +endfunction diff --git a/autoload/ale/handlers/hlint.vim b/autoload/ale/handlers/hlint.vim new file mode 100644 index 00000000..b9a8c322 --- /dev/null +++ b/autoload/ale/handlers/hlint.vim @@ -0,0 +1,8 @@ +call ale#Set('haskell_hlint_executable', 'hlint') +call ale#Set('haskell_hlint_options', get(g:, 'hlint_options', '')) + +function! ale#handlers#hlint#GetExecutable(buffer) abort + let l:executable = ale#Var(a:buffer, 'haskell_hlint_executable') + + return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'hlint') +endfunction -- cgit v1.2.3