This repository has been archived on 2024-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
ale/ale_linters/perl6/perl6.vim

167 lines
5.1 KiB
VimL
Raw Normal View History

2018-09-28 23:18:40 +00:00
" Author:Travis Gibson <https://github.com/Garland-g>
" Description: This file adds support for checking perl6 syntax
let g:ale_perl6_perl6_executable =
\ get(g:, 'ale_perl6_perl6_executable', 'perl6')
let g:ale_perl6_perl6_options =
\ get(g:, 'ale_perl6_perl6_options', '-c -Ilib')
let $PERL6_EXCEPTIONS_HANDLER = 'JSON'
let $RAKUDO_ERROR_COLOR = 0
function! ale_linters#perl6#perl6#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'perl6_perl6_executable')
endfunction
function! ale_linters#perl6#perl6#GetCommand(buffer) abort
return ale_linters#perl6#perl6#GetExecutable(a:buffer)
\ . ' ' . ale#Var(a:buffer, 'perl6_perl6_options')
\ . ' %t'
endfunction
2018-10-03 21:13:34 +00:00
function! ale_linters#perl6#perl6#ExtractError(dict, item, type, buffer) abort
2018-09-28 23:18:40 +00:00
let l:file = ''
2018-10-03 21:13:34 +00:00
let l:line = 1
2018-09-28 23:18:40 +00:00
let l:column = ''
let l:text = ''
let l:pre = ''
let l:counter = 2
let l:end_line = ''
let l:linepatternmessage = 'at\s\+line\s\+\(\d\+\)'
if has_key(a:dict[a:item], 'filename') && !empty(a:dict[a:item]['filename'])
2018-10-03 21:13:34 +00:00
let l:file = a:dict[a:item]['filename']
2018-09-28 23:18:40 +00:00
endif
if has_key(a:dict[a:item], 'line') && !empty(a:dict[a:item]['line'])
let l:line = a:dict[a:item]['line']
let l:counter -= 1
2018-09-28 23:18:40 +00:00
endif
if has_key(a:dict[a:item], 'column') && !empty(a:dict[a:item]['column'])
2018-10-03 21:13:34 +00:00
let l:column = a:dict[a:item]['column']
2018-09-28 23:18:40 +00:00
endif
if has_key(a:dict[a:item], 'message') && !empty(a:dict[a:item]['message'])
2018-10-03 21:13:34 +00:00
let l:text = substitute(a:dict[a:item]['message'], '\s*\n\s*', ' ', 'g')
2018-09-28 23:18:40 +00:00
let l:counter -= 1
endif
if has_key(a:dict[a:item], 'line-real') && !empty(a:dict[a:item]['line-real'])
let l:end_line = l:line
2018-10-03 21:13:34 +00:00
let l:line = a:dict[a:item]['line-real']
2018-09-28 23:18:40 +00:00
endif
for l:match in ale#util#GetMatches(l:text, l:linepatternmessage)
let l:line = l:match[1]
let l:counter -= 1
endfor
2018-10-03 21:13:34 +00:00
" Currently, filenames and line numbers are not always given in the error output
if l:counter < 2
\&& ( ale#path#IsBufferPath(a:buffer, l:file) || l:file is# '' )
2018-09-28 23:18:40 +00:00
return {
2018-10-03 21:13:34 +00:00
\ 'lnum': '' . l:line,
2018-09-28 23:18:40 +00:00
\ 'text': l:text,
\ 'type': a:type,
\ 'col': l:column,
\ 'end_lnum': l:end_line,
\ 'code': a:item,
\}
endif
2018-10-03 21:13:34 +00:00
return ''
2018-09-28 23:18:40 +00:00
endfunction
function! ale_linters#perl6#perl6#Handle(buffer, lines) abort
let l:output = []
if empty(a:lines)
return l:output
endif
if a:lines[0] is# 'Syntax OK'
return l:output
2018-09-28 23:18:40 +00:00
endif
try
let l:json = json_decode(join(a:lines, ''))
3560 add vim 8.2 and nvim 0.4 to ci tests (#3561) * Add vim82 and neovim04 to CI tests. * Fix test_sign_column_hightlighting test. In vim82 with verbose=1 the output of highlight command changes breaking the ale#sign#SetUpDefaultColumnWithoutErrorsHighlight(). This commit forces verbose=0 when the method starts and restores the previous value before exiting. * No return values in vim82 returns a numeric value instead of a empty string. * Fix test_reek_handler test The FuzzyJSONDecode() method catches E474 when it fails to parse the input as JSON but Vim8.2 throws E491 instead. This commit modifies the function to catch both E474 or E491. * Fix perl6 handler test. Perl6 handler catches json parse errors using the E474 error but in Vim82 it changed to E491. This commit modifies the handler so both errors are considered. * Fix list opening tests. In Vim 8.2 the call `range(1, bufnr('$'))` always returns quickfix buffers no matter if they are closed or not. Using `ls` does not show them but the above range will always include them. This new behavior breaks the ale#list#IsQuickfixOpen() method that in turn breaks many other things. This commit fixes this by using the getqflist() and getloclist() methods instead. * Fix test updates loclist test. For some reason in Vim 8.2 the sign offset seems to not reset between tests causing the sign_id to not match in the Assert. When the test is run individually it passes but when run as part of the whole suite the sign_id is off by one. Forcing the offset in the test setup seems to fix the issue. * Fix omnifunc completion test. For unknown reasons the SetCompletionResponse tests fail in Neovim 0.2 and 0.4. Unfortunatelly the only solution I found is to disable them for neovim. * Fix linter warnings * Fix smoker test. Add vim 8.2 to the list of versions that need some retires due to randomly failing tests. * Add docker image build job. Trying some clever trick to build the docker image if not available locally or in Docker hub. It uses the Dockerfile md5 checksum as tag so only when changes on that file occur will the image be downloaded or build. * Add labels to Docker image * Remove tests for middle versions 8.1 and 0.3.5 * Use same vader commit as appveyor * Implement image push to Docker Hub Co-authored-by: Horacio Sanson <horacio@allm.inc>
2021-01-27 19:52:24 +00:00
catch /E474\|E491/
2018-09-28 23:18:40 +00:00
call add(l:output, {
\ 'lnum': '1',
\ 'text': 'Received output in the default Perl6 error format. See :ALEDetail for details',
\ 'detail': join(a:lines, "\n"),
\ 'type': 'W',
\ })
return l:output
endtry
if type(l:json) is v:t_dict
for l:key in keys(l:json)
if has_key(l:json[l:key], 'sorrows')
\&& has_key(l:json[l:key], 'worries')
2018-09-28 23:18:40 +00:00
if !empty(l:json[l:key]['sorrows'])
for l:dictionary in get(l:json[l:key], 'sorrows')
for l:item in keys(l:dictionary)
2018-10-03 21:13:34 +00:00
let l:result =
2018-09-28 23:18:40 +00:00
\ ale_linters#perl6#perl6#ExtractError(
\ l:dictionary,
\ l:item,
2018-10-03 21:13:34 +00:00
\ 'E',
\ a:buffer,
2018-09-28 23:18:40 +00:00
\ )
2018-10-03 21:13:34 +00:00
if l:result isnot# ''
call add(l:output, l:result)
2018-10-03 21:13:34 +00:00
endif
2018-09-28 23:18:40 +00:00
endfor
endfor
endif
if !empty(l:json[l:key]['worries'])
for l:dictionary in get(l:json[l:key], 'worries')
for l:item in keys(l:dictionary)
2018-10-03 21:13:34 +00:00
let l:result =
2018-09-28 23:18:40 +00:00
\ ale_linters#perl6#perl6#ExtractError(
\ l:dictionary,
\ l:item,
2018-10-03 21:13:34 +00:00
\ 'W',
\ a:buffer,
2018-09-28 23:18:40 +00:00
\ )
2018-10-03 21:13:34 +00:00
if l:result isnot# ''
call add(l:output, l:result)
2018-10-03 21:13:34 +00:00
endif
2018-09-28 23:18:40 +00:00
endfor
endfor
endif
else
2018-10-03 21:13:34 +00:00
let l:result = ale_linters#perl6#perl6#ExtractError(
\ l:json,
\ l:key,
\ 'E',
\ a:buffer,
\ )
if l:result isnot# ''
call add(l:output, l:result)
2018-10-03 21:13:34 +00:00
endif
2018-09-28 23:18:40 +00:00
endif
endfor
endif
return l:output
endfunction
call ale#linter#Define('perl6', {
\ 'name': 'perl6',
\ 'executable': function('ale_linters#perl6#perl6#GetExecutable'),
2018-09-28 23:18:40 +00:00
\ 'output_stream': 'both',
\ 'command': function('ale_linters#perl6#perl6#GetCommand'),
2018-09-28 23:18:40 +00:00
\ 'callback': 'ale_linters#perl6#perl6#Handle',
\})