summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--ale_linters/haskell/hie.vim44
-rw-r--r--doc/ale-haskell.txt11
-rw-r--r--doc/ale.txt3
-rw-r--r--test/command_callback/test_haskell_hie_callbacks.vader27
5 files changed, 85 insertions, 2 deletions
diff --git a/README.md b/README.md
index bc7b1ee6..209370f0 100644
--- a/README.md
+++ b/README.md
@@ -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/) |
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',
+\})
diff --git a/doc/ale-haskell.txt b/doc/ale-haskell.txt
index 15d3ce48..379cd987 100644
--- a/doc/ale-haskell.txt
+++ b/doc/ale-haskell.txt
@@ -80,4 +80,15 @@ g:ale_haskell_stack_build_options *g:ale_haskell_stack_build_options*
===============================================================================
+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:
diff --git a/doc/ale.txt b/doc/ale.txt
index d4b51850..5006e472 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -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`
diff --git a/test/command_callback/test_haskell_hie_callbacks.vader b/test/command_callback/test_haskell_hie_callbacks.vader
new file mode 100644
index 00000000..5bd2794c
--- /dev/null
+++ b/test/command_callback/test_haskell_hie_callbacks.vader
@@ -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'