Fix #795 - Handle GCC errors without column numbers
This commit is contained in:
parent
12217480f9
commit
a0059cfe03
@ -23,6 +23,7 @@ endfunction
|
||||
function! s:RemoveUnicodeQuotes(text) abort
|
||||
let l:text = a:text
|
||||
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')
|
||||
|
||||
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>:10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’)
|
||||
" -: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 = []
|
||||
|
||||
for l:line in a:lines
|
||||
@ -99,12 +100,17 @@ function! ale#handlers#gcc#HandleGCCFormat(buffer, lines) abort
|
||||
continue
|
||||
endif
|
||||
|
||||
call add(l:output, {
|
||||
\ 'lnum': l:match[2] + 0,
|
||||
\ 'col': l:match[3] + 0,
|
||||
let l:item = {
|
||||
\ 'lnum': str2nr(l:match[2]),
|
||||
\ 'type': l:match[4] =~# 'error' ? 'E' : 'W',
|
||||
\ '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
|
||||
endfor
|
||||
|
||||
|
@ -94,3 +94,42 @@ Execute(The GCC handler shouldn't complain about #pragma once for headers):
|
||||
\ ale#handlers#gcc#HandleGCCFormat(347, [
|
||||
\ '<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''',
|
||||
\ ])
|
||||
|
Loading…
Reference in New Issue
Block a user