Fix #502 - Report undefined symbol errors better for javac

This commit is contained in:
w0rp 2017-05-04 23:19:58 +01:00
parent 528355e2c6
commit 8e70dc14f2
2 changed files with 60 additions and 7 deletions

View File

@ -85,15 +85,23 @@ function! ale_linters#java#javac#Handle(buffer, lines) abort
" Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated " Main.java:13: warning: [deprecation] donaught() in Testclass has been deprecated
" Main.java:16: error: ';' expected " Main.java:16: error: ';' expected
let l:pattern = '^.*\:\(\d\+\):\ \(.*\):\(.*\)$' let l:pattern = '\v^.*:(\d+): (.+):(.+)$'
let l:symbol_pattern = '\v^ +symbol: *(class) +([^ ]+)'
let l:output = [] let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern) for l:match in ale#util#GetMatches(a:lines, [l:pattern, l:symbol_pattern])
if empty(l:match[3])
" Add symbols to 'cannot find symbol' errors.
if l:output[-1].text ==# 'error: cannot find symbol'
let l:output[-1].text .= ': ' . l:match[2]
endif
else
call add(l:output, { call add(l:output, {
\ 'lnum': l:match[1] + 0, \ 'lnum': l:match[1] + 0,
\ 'text': l:match[2] . ':' . l:match[3], \ 'text': l:match[2] . ':' . l:match[3],
\ 'type': l:match[2] ==# 'error' ? 'E' : 'W', \ 'type': l:match[2] ==# 'error' ? 'E' : 'W',
\}) \})
endif
endfor endfor
return l:output return l:output

View File

@ -0,0 +1,45 @@
Before:
runtime ale_linters/java/javac.vim
After:
call ale#linter#Reset()
Execute(The javac handler should handle cannot find symbol errors):
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'text': 'error: some error',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 2,
\ 'text': 'error: cannot find symbol: BadName',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 34,
\ 'text': 'error: cannot find symbol: BadName2',
\ 'type': 'E',
\ },
\ {
\ 'lnum': 37,
\ 'text': 'warning: some warning',
\ 'type': 'W',
\ },
\ ],
\ ale_linters#java#javac#Handle(347, [
\ '/tmp/vLPr4Q5/33/foo.java:1: error: some error',
\ '/tmp/vLPr4Q5/33/foo.java:2: error: cannot find symbol',
\ ' BadName foo() {',
\ ' ^',
\ ' symbol: class BadName',
\ ' location: class Bar',
\ '/tmp/vLPr4Q5/33/foo.java:34: error: cannot find symbol',
\ ' BadName2 foo() {',
\ ' ^',
\ ' symbol: class BadName2',
\ ' location: class Bar',
\ '/tmp/vLPr4Q5/33/foo.java:37: warning: some warning',
\ '4 errors',
\ ])