1
0
Fork 0
mirror of synced 2024-11-17 14:35:34 -05:00
ultimate-vim/sources_non_forked/ale/ale_linters/solidity/solc.vim

54 lines
1.7 KiB
VimL
Raw Normal View History

2019-11-16 10:28:42 -05:00
" Author: Karl Bartel <karl42@gmail.com> - http://karl.berlin/
" Description: Report solc compiler errors in Solidity code
2021-07-04 16:47:44 -04:00
call ale#Set('solidity_solc_executable', 'solc')
2019-11-16 10:28:42 -05:00
call ale#Set('solidity_solc_options', '')
function! ale_linters#solidity#solc#Handle(buffer, lines) abort
" Matches patterns like the following:
2021-07-04 16:47:44 -04:00
" Error: Expected ';' but got '('
" --> /path/to/file/file.sol:1:10:)
let l:pattern = '\v(Error|Warning): (.*)$'
let l:line_and_column_pattern = '\v\.sol:(\d+):(\d+):'
2019-11-16 10:28:42 -05:00
let l:output = []
2021-07-04 16:47:44 -04:00
for l:line in a:lines
let l:match = matchlist(l:line, l:pattern)
if len(l:match) == 0
let l:match = matchlist(l:line, l:line_and_column_pattern)
if len(l:match) > 0
let l:index = len(l:output) - 1
let l:output[l:index]['lnum'] = l:match[1] + 0
let l:output[l:index]['col'] = l:match[2] + 0
endif
else
let l:isError = l:match[1] is? 'Error'
call add(l:output, {
\ 'lnum': 0,
\ 'col': 0,
\ 'text': l:match[2],
\ 'type': l:isError ? 'E' : 'W',
\})
endif
2019-11-16 10:28:42 -05:00
endfor
return l:output
endfunction
function! ale_linters#solidity#solc#GetCommand(buffer) abort
2021-07-04 16:47:44 -04:00
let l:executable = ale#Var(a:buffer, 'solidity_solc_executable')
return l:executable . ale#Pad(ale#Var(a:buffer, 'solidity_solc_options')) . ' %s'
2019-11-16 10:28:42 -05:00
endfunction
call ale#linter#Define('solidity', {
\ 'name': 'solc',
2021-07-04 16:47:44 -04:00
\ 'executable': {b -> ale#Var(b, 'solidity_solc_executable')},
2019-11-16 10:28:42 -05:00
\ 'command': function('ale_linters#solidity#solc#GetCommand'),
\ 'callback': 'ale_linters#solidity#solc#Handle',
\ 'output_stream': 'stderr',
\})