summaryrefslogtreecommitdiff
path: root/ale_linters/haskell
diff options
context:
space:
mode:
authorLuxed <cocodu13820@hotmail.fr>2018-08-02 15:24:58 -0400
committerw0rp <w0rp@users.noreply.github.com>2018-08-02 20:24:58 +0100
commit6b3086237ab32a4045a0ff70752714f9c16cdbfd (patch)
tree173a44ad8399631cd3c79519df987165a0d010bc /ale_linters/haskell
parentcb8ad9fbd82df92993e526a8e48d4400ba08936b (diff)
downloadale-6b3086237ab32a4045a0ff70752714f9c16cdbfd.zip
Add Haskell IDE Engine (hie) support (#1735)
* Adding support for haskell-ide-engine * Work with the current directory if no stack.yaml file is found * Added Cabal file detection, updated documentation and added tests * Updated help
Diffstat (limited to 'ale_linters/haskell')
-rw-r--r--ale_linters/haskell/hie.vim44
1 files changed, 44 insertions, 0 deletions
diff --git a/ale_linters/haskell/hie.vim b/ale_linters/haskell/hie.vim
new file mode 100644
index 00000000..558d36a3
--- /dev/null
+++ b/ale_linters/haskell/hie.vim
@@ -0,0 +1,44 @@
+" Author: Luxed <devildead13@gmail.com>
+" Description: A language server for Haskell
+
+call ale#Set('haskell_hie_executable', 'hie')
+
+function! ale_linters#haskell#hie#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'haskell_hie_executable')
+endfunction
+
+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
+
+call ale#linter#Define('haskell', {
+\ 'name': 'hie',
+\ 'lsp': 'stdio',
+\ 'command': '%e --lsp',
+\ 'executable_callback': 'ale_linters#haskell#hie#GetExecutable',
+\ 'project_root_callback': 'ale_linters#haskell#hie#GetProjectRoot',
+\})