Add support for checking Haskell code via a wrapper script which can be used for other tools, and fix a readline problem with the DMD wrapper script.

This commit is contained in:
w0rp 2016-09-18 23:58:04 +01:00
parent e0fc0c7bb6
commit 57ef2c9833
5 changed files with 107 additions and 4 deletions

View File

@ -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).

View File

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

View File

@ -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.

18
plugin/ale/util.vim Normal file
View File

@ -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()

23
stdin-wrapper Executable file
View File

@ -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"