Fix #795 - Handle GCC errors without column numbers

This commit is contained in:
w0rp 2017-07-23 00:39:59 +01:00
parent 12217480f9
commit a0059cfe03
2 changed files with 50 additions and 5 deletions

View File

@ -23,6 +23,7 @@ endfunction
function! s:RemoveUnicodeQuotes(text) abort function! s:RemoveUnicodeQuotes(text) abort
let l:text = a:text let l:text = a:text
let l:text = substitute(l:text, '[`´]', '''', 'g') let l:text = substitute(l:text, '[`´]', '''', 'g')
let l:text = substitute(l:text, '\v\\u2018([^\\]+)\\u2019', '''\1''', 'g')
let l:text = substitute(l:text, '[“”]', '"', 'g') let l:text = substitute(l:text, '[“”]', '"', 'g')
return l:text return l:text
@ -50,7 +51,7 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort
" <stdin>:8:5: warning: conversion lacks type at end of format [-Wformat=] " <stdin>:8:5: warning: conversion lacks type at end of format [-Wformat=]
" <stdin>:10:27: error: invalid operands to binary - (have int and char *) " <stdin>:10:27: error: invalid operands to binary - (have int and char *)
" -:189:7: note: $/${} is unnecessary on arithmetic variables. [SC2004] " -:189:7: note: $/${} is unnecessary on arithmetic variables. [SC2004]
let l:pattern = '^\(.\+\):\(\d\+\):\(\d\+\): \([^:]\+\): \(.\+\)$' let l:pattern = '\v^([a-zA-Z]?:?[^:]+):(\d+):(\d+)?:? ([^:]+): (.+)$'
let l:output = [] let l:output = []
for l:line in a:lines for l:line in a:lines
@ -99,12 +100,17 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort
continue continue
endif endif
call add(l:output, { let l:item = {
\ 'lnum': l:match[2] + 0, \ 'lnum': str2nr(l:match[2]),
\ 'col': l:match[3] + 0,
\ 'type': l:match[4] =~# 'error' ? 'E' : 'W', \ 'type': l:match[4] =~# 'error' ? 'E' : 'W',
\ 'text': s:RemoveUnicodeQuotes(l:match[5]), \ 'text': s:RemoveUnicodeQuotes(l:match[5]),
\}) \}
if !empty(l:match[3])
let l:item.col = str2nr(l:match[3])
endif
call add(l:output, l:item)
endif endif
endfor endfor

View File

@ -94,3 +94,42 @@ Execute(The GCC handler shouldn't complain about #pragma once for headers):
\ ale#handlers#gcc#HandleGCCFormat(347, [ \ ale#handlers#gcc#HandleGCCFormat(347, [
\ '<stdin>:1:1: warning: #pragma once in main file [enabled by default]', \ '<stdin>:1:1: warning: #pragma once in main file [enabled by default]',
\ ]) \ ])
Execute(The GCC handler should handle syntax errors):
AssertEqual
\ [
\ {
\ 'lnum': 6,
\ 'col': 12,
\ 'type': 'E',
\ 'text': 'invalid suffix "p" on integer constant'
\ },
\ {
\ 'lnum': 17,
\ 'col': 5,
\ 'type': 'E',
\ 'text': 'invalid suffix "n" on integer constant'
\ },
\ {
\ 'lnum': 4,
\ 'type': 'E',
\ 'text': 'variable or field ''foo'' declared void'
\ },
\ {
\ 'lnum': 4,
\ 'type': 'E',
\ 'text': '''cat'' was not declared in this scope'
\ },
\ {
\ 'lnum': 12,
\ 'type': 'E',
\ 'text': 'expected '';'' before ''o'''
\ },
\ ],
\ ale#handlers#gcc#HandleGCCFormat(347, [
\ '<stdin>:6:12: error: invalid suffix "p" on integer constant',
\ '<stdin>:17:5: error: invalid suffix "n" on integer constant',
\ '<stdin>:4: error: variable or field ''foo'' declared void',
\ '<stdin>:4: error: ''cat'' was not declared in this scope',
\ '<stdin>:12: error: expected `;'' before ''o''',
\ ])