summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md5
-rw-r--r--ale_linters/haskell/ghc.vim59
-rwxr-xr-xdmd-wrapper6
-rw-r--r--plugin/ale/util.vim18
-rwxr-xr-xstdin-wrapper23
5 files changed, 107 insertions, 4 deletions
diff --git a/README.md b/README.md
index 446602b4..d53795aa 100644
--- a/README.md
+++ b/README.md
@@ -31,12 +31,15 @@ name. That seems to be the fairest way to arrange this table.
| Bash | [-n flag](https://www.gnu.org/software/bash/manual/bash.html#index-set) |
| Bourne Shell | [-n flag](http://linux.die.net/man/1/sh) |
| C | [gcc](https://gcc.gnu.org/) |
-| D | [dmd](https://dlang.org/dmd-linux.html) |
+| D | [dmd](https://dlang.org/dmd-linux.html)\* |
+| Haskell | [ghc](https://www.haskell.org/ghc/)\* |
| Fortran | [gcc](https://gcc.gnu.org/) |
| JavaScript | [eslint](http://eslint.org/), [jscs](http://jscs.info/), [jshint](http://jshint.com/) |
| Python | [flake8](http://flake8.pycqa.org/en/latest/) |
| Ruby | [rubocop](https://github.com/bbatsov/rubocop) |
+*\* Supported only on Unix machines via a wrapper script.*
+
If you would like to see support for more languages and tools, please
[create an issue](https://github.com/w0rp/ale/issues)
or [create a pull request](https://github.com/w0rp/ale/pulls).
diff --git a/ale_linters/haskell/ghc.vim b/ale_linters/haskell/ghc.vim
new file mode 100644
index 00000000..2fb5e52b
--- /dev/null
+++ b/ale_linters/haskell/ghc.vim
@@ -0,0 +1,59 @@
+if exists('g:loaded_ale_linters_haskell_ghc')
+ finish
+endif
+
+let g:loaded_ale_linters_haskell_ghc = 1
+
+function! ale_linters#haskell#ghc#Handle(buffer, lines)
+ " Look for lines like the following.
+ "
+ " /dev/stdin:28:26: Not in scope: `>>>>>'
+ let pattern = '^[^:]\+:\(\d\+\):\(\d\+\): \(.\+\)$'
+ let output = []
+
+ " For some reason the output coming out of the GHC through the wrapper
+ " script breaks the lines up in strange ways. So we have to join some
+ " lines back together again.
+ let corrected_lines = []
+
+ for line in a:lines
+ if len(matchlist(line, pattern)) > 0
+ call add(corrected_lines, line)
+ call add(corrected_lines, '')
+ elseif line == ''
+ call add(corrected_lines, line)
+ else
+ if len(corrected_lines) > 0
+ let corrected_lines[-1] .= line
+ endif
+ endif
+ endfor
+
+ for line in corrected_lines
+ let l:match = matchlist(line, pattern)
+
+ if len(l:match) == 0
+ continue
+ endif
+
+ call add(output, {
+ \ 'bufnr': a:buffer,
+ \ 'lnum': l:match[1] + 0,
+ \ 'vcol': 0,
+ \ 'col': l:match[2] + 0,
+ \ 'text': l:match[3],
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \})
+ endfor
+
+ return output
+endfunction
+
+call ALEAddLinter('haskell', {
+\ 'name': 'ghc',
+\ 'output_stream': 'stderr',
+\ 'executable': 'ghc',
+\ 'command': g:ale#util#stdin_wrapper . ' .hs ghc -fno-code -v0',
+\ 'callback': 'ale_linters#haskell#ghc#Handle',
+\})
diff --git a/dmd-wrapper b/dmd-wrapper
index dd2bb53a..678aeb99 100755
--- a/dmd-wrapper
+++ b/dmd-wrapper
@@ -9,8 +9,8 @@ temp_file="$temp_file".d
trap "rm $temp_file" EXIT
-while read line; do
- echo "$line" >> "$temp_file"
+while read; do
+ echo "$REPLY" >> "$temp_file"
done
# Read imports from DUB.
@@ -24,7 +24,7 @@ while [ "$path" != '/' ]; do
cd "$path"
- while read import_line; do
+ while read import_line; do
import_line_options="$import_line_options -I$import_line"
done <<< "$(dub describe --import-paths)"
diff --git a/plugin/ale/util.vim b/plugin/ale/util.vim
new file mode 100644
index 00000000..34cacca1
--- /dev/null
+++ b/plugin/ale/util.vim
@@ -0,0 +1,18 @@
+if exists('g:loaded_ale_util')
+ finish
+endif
+
+let g:loaded_ale_util = 1
+
+function! s:FindWrapperScript()
+ for parent in split(&runtimepath, ',')
+ " Expand the path to deal with ~ issues.
+ let path = expand(parent . '/' . 'stdin-wrapper')
+
+ if filereadable(path)
+ return path
+ endif
+ endfor
+endfunction
+
+let g:ale#util#stdin_wrapper = s:FindWrapperScript()
diff --git a/stdin-wrapper b/stdin-wrapper
new file mode 100755
index 00000000..b3f9a2f9
--- /dev/null
+++ b/stdin-wrapper
@@ -0,0 +1,23 @@
+#!/bin/bash -eu
+
+# This script implements a wrapper for any program which does not accept
+# stdin input on most Unix machines. The input to the script is read to a
+# temporary file, and the first argument sets a particular file extension
+# for the temporary file.
+#
+# All of the following arguments are read as command to run.
+
+file_extension="$1"
+shift
+
+temp_file=`mktemp`
+mv "$temp_file" "$temp_file$file_extension"
+temp_file="$temp_file$file_extension"
+
+trap "rm $temp_file" EXIT
+
+while read; do
+ echo "$REPLY" >> "$temp_file"
+done
+
+"$@" "$temp_file"