summaryrefslogtreecommitdiff
path: root/ale_linters/prolog/swipl.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ale_linters/prolog/swipl.vim')
-rw-r--r--ale_linters/prolog/swipl.vim34
1 files changed, 32 insertions, 2 deletions
diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim
index 5c601c40..0d8823d5 100644
--- a/ale_linters/prolog/swipl.vim
+++ b/ale_linters/prolog/swipl.vim
@@ -34,13 +34,14 @@ function! s:Subst(format, vars) abort
return substitute(a:format, '%\(.\)', '\=get(l:vars, submatch(1), "")', 'g')
endfunction
+let s:pattern = '\v^(ERROR|Warning)+%(:\s*[^:]+:(\d+)%(:(\d+))?)?:\s*(.*)$'
+
function! ale_linters#prolog#swipl#Handle(buffer, lines) abort
- let l:pattern = '\v^(ERROR|Warning)+%(:\s*[^:]+:(\d+)%(:(\d+))?)?:\s*(.*)$'
let l:output = []
let l:i = 0
while l:i < len(a:lines)
- let l:match = matchlist(a:lines[l:i], l:pattern)
+ let l:match = matchlist(a:lines[l:i], s:pattern)
if empty(l:match)
let l:i += 1
@@ -65,6 +66,13 @@ endfunction
" This returns [<next line number>, <error message string>]
function! s:GetErrMsg(i, lines, text) abort
+ let l:next_line = get(a:lines, a:i+1, '')
+ let l:matches = matchlist(l:next_line, s:pattern)
+
+ if !empty(l:matches) && empty(l:matches[2])
+ return s:GetContErrMsg(a:i+1, a:lines, a:text.matches[4])
+ endif
+
if a:text !~# '^\s*$'
return [a:i + 1, a:text]
endif
@@ -80,6 +88,28 @@ function! s:GetErrMsg(i, lines, text) abort
return [l:i, join(l:text, '. ')]
endfunction
+function! s:GetContErrMsg(i, lines, text) abort
+ if a:text !~# '^\s*$'
+ return [a:i + 1, a:text]
+ endif
+
+ let l:i = a:i + 1
+ let l:text = []
+
+ while l:i < len(a:lines) && a:lines[l:i] =~# s:pattern
+ let l:matches = matchlist(a:lines[l:i], s:pattern)
+
+ if !empty(l:matches[2])
+ break
+ endif
+ call add(l:text, s:Trim(l:matches[4]))
+
+ let l:i += 1
+ endwhile
+
+ return [l:i, join(l:text, '. ')]
+endfunction
+
function! s:Trim(str) abort
return substitute(a:str, '\v^\s+|\s+$', '', 'g')
endfunction