a8915d885b
* 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
47 lines
1.5 KiB
VimL
47 lines
1.5 KiB
VimL
" Author: Luxed <devildead13@gmail.com>
|
|
" Description: A language server for Haskell
|
|
|
|
call ale#Set('haskell_hie_executable', 'hie')
|
|
|
|
function! ale_linters#haskell#hie#GetProjectRoot(buffer) abort
|
|
" Search for the stack file first
|
|
let l:project_file = ale#path#FindNearestFile(a:buffer, 'stack.yaml')
|
|
|
|
" If it's empty, search for the cabal file
|
|
if empty(l:project_file)
|
|
let l:cabal_file = fnamemodify(bufname(a:buffer), ':p:h')
|
|
let l:paths = ''
|
|
|
|
while empty(matchstr(l:cabal_file, '^\(\/\|\(\w:\\\)\)$'))
|
|
let l:cabal_file = fnamemodify(l:cabal_file, ':h')
|
|
let l:paths = l:paths . l:cabal_file . ','
|
|
endwhile
|
|
|
|
let l:project_file = globpath(l:paths, '*.cabal')
|
|
endif
|
|
|
|
" Either extract the project directory or take the current working
|
|
" directory
|
|
if !empty(l:project_file)
|
|
let l:project_file = fnamemodify(l:project_file, ':h')
|
|
else
|
|
let l:project_file = expand('#' . a:buffer . ':p:h')
|
|
endif
|
|
|
|
return l:project_file
|
|
endfunction
|
|
|
|
function! ale_linters#haskell#hie#GetCommand(buffer) abort
|
|
let l:executable = ale#Var(a:buffer, 'haskell_hie_executable')
|
|
|
|
return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'hie')
|
|
\ . ' --lsp'
|
|
endfunction
|
|
|
|
call ale#linter#Define('haskell', {
|
|
\ 'name': 'hie',
|
|
\ 'lsp': 'stdio',
|
|
\ 'command_callback': 'ale_linters#haskell#hie#GetCommand',
|
|
\ 'executable_callback': ale#VarFunc('haskell_hie_executable'),
|
|
\ 'project_root_callback': 'ale_linters#haskell#hie#GetProjectRoot',
|
|
\})
|