From abe1440268799fd9fba38c71b8423f988523678e Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 1 Oct 2020 12:49:53 -0400 Subject: [PATCH 1/8] prolog/swipl: update error format for new version A recent(?) update to swipl changed the error format from Warning: some.pl:2: Singleton variables: [Y] to Warning: some.pl:2: Warning: Singleton variables: [Y] The old error handler doesn't report the correct line numbers and messages on the old format. I've chosen to add a function that covers the second case and detect it, rather than rewrite the current function. This way, both versions should be able to live together. --- Example file that demonstrates the issue (some.pl above): ``` % vim: ft=prolog ii(X, Y) :- X. ``` --- --- ale_linters/prolog/swipl.vim | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim index 5c601c40..70d967f7 100644 --- a/ale_linters/prolog/swipl.vim +++ b/ale_linters/prolog/swipl.vim @@ -34,13 +34,13 @@ 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 +65,11 @@ endfunction " This returns [, ] function! s:GetErrMsg(i, lines, text) abort + let next_line = get(a:lines, a:i+1, '') + let matches = matchlist(next_line, s:pattern) + if !empty(matchlist) && empty(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 +85,26 @@ function! s:GetErrMsg(i, lines, text) abort return [l:i, join(l:text, '. ')] endfunction +function! s:GetErrMsg(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 matches = matchlist(a:lines[l:i], s:pattern) + if !empty(matches[2]) + break + end + call add(l:text, s:Trim(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 From e32d5fc03d159c659e8294bbe1656fafa77bfdda Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 1 Oct 2020 13:10:28 -0400 Subject: [PATCH 2/8] prolog/swipl: address linter feedback This actually caught a bug where I forgot to rename the function --- ale_linters/prolog/swipl.vim | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim index 70d967f7..5c5388d3 100644 --- a/ale_linters/prolog/swipl.vim +++ b/ale_linters/prolog/swipl.vim @@ -35,6 +35,7 @@ function! s:Subst(format, vars) abort endfunction let s:pattern = '\v^(ERROR|Warning)+%(:\s*[^:]+:(\d+)%(:(\d+))?)?:\s*(.*)$' + function! ale_linters#prolog#swipl#Handle(buffer, lines) abort let l:output = [] let l:i = 0 @@ -65,11 +66,13 @@ endfunction " This returns [, ] function! s:GetErrMsg(i, lines, text) abort - let next_line = get(a:lines, a:i+1, '') - let matches = matchlist(next_line, s:pattern) - if !empty(matchlist) && empty(matches[2]) + 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 @@ -85,7 +88,7 @@ function! s:GetErrMsg(i, lines, text) abort return [l:i, join(l:text, '. ')] endfunction -function! s:GetErrMsg(i, lines, text) abort +function! s:GetContErrMsg(i, lines, text) abort if a:text !~# '^\s*$' return [a:i + 1, a:text] endif @@ -94,11 +97,12 @@ function! s:GetErrMsg(i, lines, text) abort let l:text = [] while l:i < len(a:lines) && a:lines[l:i] =~# s:pattern - let matches = matchlist(a:lines[l:i], s:pattern) - if !empty(matches[2]) + let l:matches = matchlist(a:lines[l:i], s:pattern) + + if !empty(l:matches[2]) break - end - call add(l:text, s:Trim(matches[4])) + endif + call add(l:text, s:Trim(l:matches[4])) let l:i += 1 endwhile From 81b92bcbfa78074c550f46a83629645c6a1a4412 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 1 Oct 2020 13:11:56 -0400 Subject: [PATCH 3/8] prolog/swipl: add test for new format --- test/handler/test_swipl_handler.vader | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/handler/test_swipl_handler.vader b/test/handler/test_swipl_handler.vader index 9e425cf6..7986c6a1 100644 --- a/test/handler/test_swipl_handler.vader +++ b/test/handler/test_swipl_handler.vader @@ -35,6 +35,22 @@ Execute (The swipl handler should handle a warning / error of two lines): \ ' Singleton variables: [M]', \ ]) +Execute (The swipl handler should handle a warning / error of two lines in the new format): + call ale#test#SetFilename('test.pl') + AssertEqual + \ [ + \ { + \ 'lnum': 9, + \ 'col': 0, + \ 'text': 'Singleton variables: [M]', + \ 'type': 'W', + \ }, + \ ], + \ ale_linters#prolog#swipl#Handle(bufnr(''), [ + \ 'Warning: /path/to/test.pl:9:', + \ 'Warning: Singleton variables: [M]', + \ ]) + Execute (The swipl handler should join three or more lines with '. '): call ale#test#SetFilename('test.pl') AssertEqual From 3410c1b1e298b8dcde2e7657a587fbaf4a007fec Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Thu, 1 Oct 2020 13:18:31 -0400 Subject: [PATCH 4/8] prolog/swipl: add blank line after call Though I do not see this specified or followed anywhere else --- ale_linters/prolog/swipl.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim index 5c5388d3..0d8823d5 100644 --- a/ale_linters/prolog/swipl.vim +++ b/ale_linters/prolog/swipl.vim @@ -103,6 +103,7 @@ function! s:GetContErrMsg(i, lines, text) abort break endif call add(l:text, s:Trim(l:matches[4])) + let l:i += 1 endwhile From 730222bcd815acdb2b090afc81573a54f79395d2 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Mon, 30 Nov 2020 13:51:15 -0500 Subject: [PATCH 5/8] fix blank line issue (???) --- ale_linters/prolog/swipl.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim index 0d8823d5..878a2cbf 100644 --- a/ale_linters/prolog/swipl.vim +++ b/ale_linters/prolog/swipl.vim @@ -102,6 +102,7 @@ function! s:GetContErrMsg(i, lines, text) abort if !empty(l:matches[2]) break endif + call add(l:text, s:Trim(l:matches[4])) let l:i += 1 From 6a3d215571662bfc97d2d415dfbec4bc217eda62 Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Wed, 20 Jan 2021 11:59:24 -0500 Subject: [PATCH 6/8] prolog/swipl: simplify with @hsanson's suggestions https://github.com/dense-analysis/ale/pull/3377#issuecomment-763628447 --- ale_linters/prolog/swipl.vim | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim index 878a2cbf..e5a42e52 100644 --- a/ale_linters/prolog/swipl.vim +++ b/ale_linters/prolog/swipl.vim @@ -66,13 +66,6 @@ endfunction " This returns [, ] 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,31 +73,17 @@ function! s:GetErrMsg(i, lines, text) abort let l:i = a:i + 1 let l:text = [] - while l:i < len(a:lines) && a:lines[l:i] =~# '^\s' - call add(l:text, s:Trim(a:lines[l:i])) - let l:i += 1 - endwhile + let l:pattern = '\v^(ERROR|Warning)?:?(.*)$' - return [l:i, join(l:text, '. ')] -endfunction + while l:i < len(a:lines) + let l:match = matchlist(a:lines[l:i], l:pattern) -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]) + if empty(l:match) || empty(l:match[2]) + let l:i += 1 break endif - call add(l:text, s:Trim(l:matches[4])) - + call add(l:text, s:Trim(l:match[2])) let l:i += 1 endwhile From 80a0108fcfa93876c03e7e74110d11e398561cb0 Mon Sep 17 00:00:00 2001 From: Horacio Sanson Date: Wed, 20 Jan 2021 12:00:55 -0500 Subject: [PATCH 7/8] prolog/swipl: cover new format with complex tests https://github.com/dense-analysis/ale/pull/3377#issuecomment-763628447 --- test/handler/test_swipl_handler.vader | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/handler/test_swipl_handler.vader b/test/handler/test_swipl_handler.vader index 7986c6a1..81b8b9e5 100644 --- a/test/handler/test_swipl_handler.vader +++ b/test/handler/test_swipl_handler.vader @@ -95,6 +95,50 @@ Execute (The swipl handler should ignore warnings / errors 'No permission to cal \ ' vimscript: (multifile A)', \ ]) +Execute (The swipl handler should join three or more lines with '. ' on latest swipl): + call ale#test#SetFilename('test.pl') + AssertEqual + \ [ + \ { + \ 'lnum': 10, + \ 'col': 0, + \ 'text': 'Clauses of fib/2 are not together in the source-file. Earlier definition at /path/to/test.pl:7. Current predicate: f/0. Use :- discontiguous fib/2. to suppress this message', + \ 'type': 'W', + \ }, + \ ], + \ ale_linters#prolog#swipl#Handle(bufnr(''), [ + \ 'Warning: /path/to/test.pl:10:', + \ 'Warning: Clauses of fib/2 are not together in the source-file', + \ 'Warning: Earlier definition at /path/to/test.pl:7', + \ 'Warning: Current predicate: f/0', + \ 'Warning: Use :- discontiguous fib/2. to suppress this message', + \ ]) + +Execute (The swipl handler should ignore warnings / errors 'No permission to call sandboxed with latest swpl...'): + call ale#test#SetFilename('test.pl') + AssertEqual + \ [], + \ ale_linters#prolog#swipl#Handle(bufnr(''), [ + \ 'ERROR: /path/to/test.pl:11:', + \ 'ERROR: No permission to call sandboxed `''$set_predicate_attribute''(_G3416:_G3417,_G3413,_G3414)''', + \ 'ERROR: Reachable from:', + \ 'ERROR: system:''$set_pattr''(A,B,C,D)', + \ 'ERROR: system:''$set_pattr''(vimscript:A,B,C)', + \ 'ERROR: vimscript: (multifile A)', + \ 'ERROR: /path/to/test.pl:12:', + \ 'ERROR: No permission to call sandboxed `''$set_predicate_attribute''(_G205:_G206,_G202,_G203)''', + \ 'ERROR: Reachable from:', + \ 'ERROR: system:''$set_pattr''(A,B,C,D)', + \ 'ERROR: system:''$set_pattr''(vimscript:A,B,C)', + \ 'ERROR: vimscript: (multifile A)', + \ 'ERROR: /path/to/test.pl:13:', + \ 'ERROR: No permission to call sandboxed `''$set_predicate_attribute''(_G1808:_G1809,_G1805,_G1806)''', + \ 'ERROR: Reachable from:', + \ 'ERROR: system:''$set_pattr''(A,B,C,D)', + \ 'ERROR: system:''$set_pattr''(vimscript:A,B,C)', + \ 'ERROR: vimscript: (multifile A)', + \ ]) + Execute (The swipl handler should handle a warning / error with no line number): call ale#test#SetFilename('test.pl') AssertEqual From 10d2b8797c3d4336729f5f6f75edab53733d7642 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sat, 23 Jan 2021 12:27:55 -0500 Subject: [PATCH 8/8] swipl: style fix --- ale_linters/prolog/swipl.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ale_linters/prolog/swipl.vim b/ale_linters/prolog/swipl.vim index e5a42e52..82859eb0 100644 --- a/ale_linters/prolog/swipl.vim +++ b/ale_linters/prolog/swipl.vim @@ -34,14 +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:output = [] let l:i = 0 + let l:pattern = '\v^(ERROR|Warning)+%(:\s*[^:]+:(\d+)%(:(\d+))?)?:\s*(.*)$' + while l:i < len(a:lines) - let l:match = matchlist(a:lines[l:i], s:pattern) + let l:match = matchlist(a:lines[l:i], l:pattern) if empty(l:match) let l:i += 1