2018-08-02 19:24:58 +00:00
|
|
|
" 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)
|
2019-02-07 16:24:41 +00:00
|
|
|
" Search all of the paths except for the root filesystem path.
|
|
|
|
let l:paths = join(
|
|
|
|
\ ale#path#Upwards(expand('#' . a:buffer . ':p:h'))[:-2],
|
|
|
|
\ ','
|
|
|
|
\)
|
2018-08-02 19:24:58 +00:00
|
|
|
let l:project_file = globpath(l:paths, '*.cabal')
|
|
|
|
endif
|
|
|
|
|
2019-02-07 16:24:41 +00:00
|
|
|
" If we still can't find one, use the current file.
|
|
|
|
if empty(l:project_file)
|
|
|
|
let l:project_file = expand('#' . a:buffer . ':p')
|
2018-08-02 19:24:58 +00:00
|
|
|
endif
|
|
|
|
|
2019-02-07 16:24:41 +00:00
|
|
|
return fnamemodify(l:project_file, ':h')
|
2018-08-02 19:24:58 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-09-28 08:05:01 +00:00
|
|
|
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')
|
2019-02-06 18:05:13 +00:00
|
|
|
\ . ' --lsp'
|
2018-09-28 08:05:01 +00:00
|
|
|
endfunction
|
|
|
|
|
2018-08-02 19:24:58 +00:00
|
|
|
call ale#linter#Define('haskell', {
|
|
|
|
\ 'name': 'hie',
|
|
|
|
\ 'lsp': 'stdio',
|
2019-02-22 18:05:04 +00:00
|
|
|
\ 'command': function('ale_linters#haskell#hie#GetCommand'),
|
|
|
|
\ 'executable': {b -> ale#Var(b, 'haskell_hie_executable')},
|
|
|
|
\ 'project_root': function('ale_linters#haskell#hie#GetProjectRoot'),
|
2018-08-02 19:24:58 +00:00
|
|
|
\})
|