From 8e70dc14f2a51f0ef7acb64c3ef9850cb4f23e64 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 4 May 2017 23:19:58 +0100 Subject: [PATCH] Fix #502 - Report undefined symbol errors better for javac --- ale_linters/java/javac.vim | 22 ++++++++----- test/handler/test_javac_handler.vader | 45 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 test/handler/test_javac_handler.vader diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim index 4e91c4f..4dbc6cb 100644 --- a/ale_linters/java/javac.vim +++ b/ale_linters/java/javac.vim @@ -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:16: error: ';' expected - let l:pattern = '^.*\:\(\d\+\):\ \(.*\):\(.*\)$' + let l:pattern = '\v^.*:(\d+): (.+):(.+)$' + let l:symbol_pattern = '\v^ +symbol: *(class) +([^ ]+)' let l:output = [] - for l:match in ale#util#GetMatches(a:lines, l:pattern) - call add(l:output, { - \ 'lnum': l:match[1] + 0, - \ 'text': l:match[2] . ':' . l:match[3], - \ 'type': l:match[2] ==# 'error' ? 'E' : 'W', - \}) + 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, { + \ 'lnum': l:match[1] + 0, + \ 'text': l:match[2] . ':' . l:match[3], + \ 'type': l:match[2] ==# 'error' ? 'E' : 'W', + \}) + endif endfor return l:output diff --git a/test/handler/test_javac_handler.vader b/test/handler/test_javac_handler.vader new file mode 100644 index 0000000..2c0723b --- /dev/null +++ b/test/handler/test_javac_handler.vader @@ -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', + \ ])