summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-25 17:08:57 +0100
committerw0rp <devw0rp@gmail.com>2017-06-25 17:08:57 +0100
commit93473a410139f4c094ae491e690bb22b40648214 (patch)
tree946fdc5ecb87dcd5e351ccc5b454121797ee63f1
parent229a1c092a6f7d5116590bed2cf0e97ad63bbc7c (diff)
downloadale-93473a410139f4c094ae491e690bb22b40648214.zip
Fix #690 - Filter out errors from other files for Haskell
-rw-r--r--autoload/ale/handlers/haskell.vim15
-rw-r--r--autoload/ale/path.vim21
-rw-r--r--test/handler/test_ghc_handler.vader14
-rw-r--r--test/handler/test_ghc_mod_handler.vader5
-rw-r--r--test/test_path_equality.vader1
5 files changed, 44 insertions, 12 deletions
diff --git a/autoload/ale/handlers/haskell.vim b/autoload/ale/handlers/haskell.vim
index cfddbdbf..17d9d242 100644
--- a/autoload/ale/handlers/haskell.vim
+++ b/autoload/ale/handlers/haskell.vim
@@ -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,
\})
diff --git a/autoload/ale/path.vim b/autoload/ale/path.vim
index 2c1d5133..2a38d740 100644
--- a/autoload/ale/path.vim
+++ b/autoload/ale/path.vim
@@ -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
diff --git a/test/handler/test_ghc_handler.vader b/test/handler/test_ghc_handler.vader
index e8d622bb..524f08b7 100644
--- a/test/handler/test_ghc_handler.vader
+++ b/test/handler/test_ghc_handler.vader
@@ -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)',
\ ])
diff --git a/test/handler/test_ghc_mod_handler.vader b/test/handler/test_ghc_mod_handler.vader
index f9b44b33..53991bb6 100644
--- a/test/handler/test_ghc_mod_handler.vader
+++ b/test/handler/test_ghc_mod_handler.vader
@@ -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 ‘Missing’Use -v to see a list of the files searched for.',
+ \ 'check2.hs:2:1:Failed to load interface for ‘Missing’Use -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',
\ ])
diff --git a/test/test_path_equality.vader b/test/test_path_equality.vader
index 78af5627..54d9bf9a 100644
--- a/test/test_path_equality.vader
+++ b/test/test_path_equality.vader
@@ -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')