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
This commit is contained in:
Luxed 2018-08-02 15:24:58 -04:00 committed by w0rp
parent cb8ad9fbd8
commit 6b3086237a
5 changed files with 85 additions and 2 deletions

View file

@ -128,7 +128,7 @@ formatting.
| GraphQL | [eslint](http://eslint.org/), [gqlint](https://github.com/happylinks/gqlint), [prettier](https://github.com/prettier/prettier) |
| Haml | [haml-lint](https://github.com/brigade/haml-lint) |
| Handlebars | [ember-template-lint](https://github.com/rwjblue/ember-template-lint) |
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt) |
| Haskell | [brittany](https://github.com/lspitzner/brittany), [ghc](https://www.haskell.org/ghc/), [cabal-ghc](https://www.haskell.org/cabal/), [stack-ghc](https://haskellstack.org/), [stack-build](https://haskellstack.org/) !!, [ghc-mod](https://github.com/DanielG/ghc-mod), [stack-ghc-mod](https://github.com/DanielG/ghc-mod), [hlint](https://hackage.haskell.org/package/hlint), [hdevtools](https://hackage.haskell.org/package/hdevtools), [hfmt](https://github.com/danstiner/hfmt), [hie](https://github.com/haskell/haskell-ide-engine) |
| HTML | [alex](https://github.com/wooorm/alex) !!, [HTMLHint](http://htmlhint.com/), [proselint](http://proselint.com/), [tidy](http://www.html-tidy.org/), [write-good](https://github.com/btford/write-good) |
| Idris | [idris](http://www.idris-lang.org/) |
| Java | [checkstyle](http://checkstyle.sourceforge.net), [javac](http://www.oracle.com/technetwork/java/javase/downloads/index.html), [google-java-format](https://github.com/google/google-java-format), [PMD](https://pmd.github.io/) |

View file

@ -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',
\})

View file

@ -79,5 +79,16 @@ g:ale_haskell_stack_build_options *g:ale_haskell_stack_build_options*
programs will be slower unless you separately rebuild them outside of ALE.
===============================================================================
hie *ale-haskell-hie*
g:ale_haskell_hie_executable *g:ale_haskell_hie_executable*
*b:ale_haskell_hie_executable*
Type: |String|
Default: `'hie'`
This variable can be changed to use a different executable for the haskell
ide engine. i.e. `'hie-wrapper'`
===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -105,6 +105,7 @@ CONTENTS *ale-contents*
hdevtools...........................|ale-haskell-hdevtools|
hfmt................................|ale-haskell-hfmt|
stack-build.........................|ale-haskell-stack-build|
hie.................................|ale-haskell-hie|
html..................................|ale-html-options|
htmlhint............................|ale-html-htmlhint|
tidy................................|ale-html-tidy|
@ -369,7 +370,7 @@ Notes:
* GraphQL: `eslint`, `gqlint`, `prettier`
* Haml: `haml-lint`
* Handlebars: `ember-template-lint`
* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`
* Haskell: `brittany`, `ghc`, `cabal-ghc`, `stack-ghc`, `stack-build`!!, `ghc-mod`, `stack-ghc-mod`, `hlint`, `hdevtools`, `hfmt`, `hie`
* HTML: `alex`!!, `HTMLHint`, `proselint`, `tidy`, `write-good`
* Idris: `idris`
* Java: `checkstyle`, `javac`, `google-java-format`, `PMD`

View file

@ -0,0 +1,27 @@
Before:
call ale#assert#SetUpLinterTest('haskell', 'hie')
Save &filetype
let &filetype = 'haskell'
After:
call ale#assert#TearDownLinterTest()
Execute(The language string should be correct):
AssertLSPLanguage 'haskell'
Execute(The default executable should be correct):
AssertLinter 'hie',
\ ale#Escape('hie') . ' --lsp'
Execute(The project root should be detected correctly):
AssertLSPProject g:dir
call ale#test#SetFilename('hie_paths/file.hs')
AssertLSPProject ale#path#Simplify(g:dir . '/hie_paths')
Execute(The executable should be configurable):
let g:ale_haskell_hie_executable = 'foobar'
AssertLinter 'foobar', ale#Escape('foobar') . ' --lsp'