Fix #690 - Filter out errors from other files for Haskell

This commit is contained in:
w0rp 2017-06-25 17:08:57 +01:00
parent 229a1c092a
commit 93473a4101
5 changed files with 44 additions and 12 deletions

View File

@ -6,10 +6,11 @@ function! ale#handlers#haskell#HandleGHCFormat(buffer, lines) abort
"
"Appoint/Lib.hs:8:1: warning:
"Appoint/Lib.hs:8:1:
let l:pattern = '^[^:]\+:\(\d\+\):\(\d\+\):\(.*\)\?$'
let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+):(.*)?$'
let l:output = []
let l:corrected_lines = []
for l:line in a:lines
if len(matchlist(l:line, l:pattern)) > 0
call add(l:corrected_lines, l:line)
@ -30,21 +31,25 @@ function! ale#handlers#haskell#HandleGHCFormat(buffer, lines) abort
continue
endif
let l:errors = matchlist(l:match[3], '\(warning:\|error:\)\(.*\)')
if !ale#path#IsBufferPath(a:buffer, l:match[1])
continue
endif
let l:errors = matchlist(l:match[4], '\(warning:\|error:\)\(.*\)')
if len(l:errors) > 0
let l:type = l:errors[1]
let l:text = l:errors[2]
else
let l:type = ''
let l:text = l:match[3]
let l:text = l:match[4]
endif
let l:type = l:type ==# '' ? 'E' : toupper(l:type[0])
call add(l:output, {
\ 'lnum': l:match[1] + 0,
\ 'col': l:match[2] + 0,
\ 'lnum': l:match[2] + 0,
\ 'col': l:match[3] + 0,
\ 'text': l:text,
\ 'type': l:type,
\})

View File

@ -62,6 +62,23 @@ function! ale#path#IsAbsolute(filename) abort
return a:filename[:0] ==# '/' || a:filename[1:2] ==# ':\'
endfunction
" Given a filename, return 1 if the file represents some temporary file
" created by Vim.
function! ale#path#IsTempName(filename) abort
let l:prefix_list = [
\ $TMPDIR,
\ '/run/user',
\]
for l:prefix in l:prefix_list
if a:filename[:len(l:prefix) - 1] ==# l:prefix
return 1
endif
endfor
return 0
endfunction
" Given a buffer number and a relative or absolute path, return 1 if the
" two paths represent the same file on disk.
function! ale#path#IsBufferPath(buffer, complex_filename) abort
@ -83,8 +100,8 @@ function! ale#path#IsBufferPath(buffer, complex_filename) abort
let l:test_filename = substitute(l:test_filename, '\v^(\.\.[/\\])+', '/', '')
endif
" Use the basename for files in /tmp, as they are likely our files.
if l:test_filename[:len($TMPDIR) - 1] ==# $TMPDIR
" Use the basename for temporary files, as they are likely our files.
if ale#path#IsTempName(l:test_filename)
let l:test_filename = fnamemodify(l:test_filename, ':t')
endif

View File

@ -1,4 +1,6 @@
Execute(The ghc handler should handle hdevtools output):
call ale#test#SetFilename('foo.hs')
AssertEqual
\ [
\ {
@ -8,13 +10,15 @@ Execute(The ghc handler should handle hdevtools output):
\ 'text': '• Couldnt match type a -> T.Text with T.Text Expected type: [T.Text]',
\ },
\ ],
\ ale#handlers#haskell#HandleGHCFormat(12, [
\ '/path/to/foo.hs:147:62: warning:',
\ ale#handlers#haskell#HandleGHCFormat(bufnr(''), [
\ 'foo.hs:147:62: warning:',
\ '• Couldnt match type a -> T.Text with T.Text',
\ ' Expected type: [T.Text]',
\ ])
Execute(The ghc handler should handle ghc 8 output):
call ale#test#SetFilename('src/Appoint/Lib.hs')
AssertEqual
\ [
\ {
@ -30,7 +34,7 @@ Execute(The ghc handler should handle ghc 8 output):
\ 'text': ' Failed to load interface for GitHub.Endpoints.PullRequests Use -v to see a list of the files searched for.',
\ },
\ ],
\ ale#handlers#haskell#HandleGHCFormat(47, [
\ ale#handlers#haskell#HandleGHCFormat(bufnr(''), [
\ '',
\ 'src/Appoint/Lib.hs:6:1: error:',
\ ' Failed to load interface for GitHub.Data',
@ -42,6 +46,8 @@ Execute(The ghc handler should handle ghc 8 output):
\ ])
Execute(The ghc handler should handle ghc 7 output):
call ale#test#SetFilename('src/Main.hs')
AssertEqual
\ [
\ {
@ -51,7 +57,7 @@ Execute(The ghc handler should handle ghc 7 output):
\ 'text': ' parse error (possibly incorrect indentation or mismatched brackets)',
\ },
\ ],
\ ale#handlers#haskell#HandleGHCFormat(47, [
\ ale#handlers#haskell#HandleGHCFormat(bufnr(''), [
\ 'src/Main.hs:168:1:',
\ ' parse error (possibly incorrect indentation or mismatched brackets)',
\ ])

View File

@ -1,4 +1,6 @@
Execute(HandleGhcFormat should handle ghc-mod problems):
call ale#test#SetFilename('check2.hs')
AssertEqual
\ [
\ {
@ -21,7 +23,8 @@ Execute(HandleGhcFormat should handle ghc-mod problems):
\ },
\ ],
\ ale#handlers#haskell#HandleGHCFormat(bufnr(''), [
\ 'check1.hs:2:1:Failed to load interface for MissingUse -v to see a list of the files searched for.',
\ 'check2.hs:2:1:Failed to load interface for MissingUse -v to see a list of the files searched for.',
\ 'check2.hs:2:1: Suggestion: Use camelCaseFound: my_variable = ...Why not: myVariable = ...',
\ 'check2.hs:6:1: Warning: Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ',
\ 'xxx.hs:6:1: Warning: Eta reduceFound: myFunc x = succ xWhy not: myFunc = succ',
\ ])

View File

@ -41,3 +41,4 @@ Execute(ale#path#IsBufferPath should match files in /tmp):
Assert ale#path#IsBufferPath(bufnr(''), '../../../../../../../../tmp/vG0hKyD/1/test.ts')
Assert ale#path#IsBufferPath(bufnr(''), '/tmp/vG0hKyD/1/test.ts')
Assert ale#path#IsBufferPath(bufnr(''), '/run/user/1000/vG0hKyD/1/test.ts')