diff options
author | w0rp <w0rp@users.noreply.github.com> | 2018-11-19 19:36:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-19 19:36:32 +0000 |
commit | 4b4b09593b2b090282981d69a9647a3c91d1f8b9 (patch) | |
tree | 931d50082b2eef3affd7a5d9fafa7dbe02a5459a /ale_linters | |
parent | f538bb440a8d9e5f607fe7a8d54f7862537586d9 (diff) | |
parent | d90673ab5b40ec1ef79ab9e3eb0b1b7012425701 (diff) | |
download | ale-4b4b09593b2b090282981d69a9647a3c91d1f8b9.zip |
Merge pull request #2087 from m-pilia/ada
Add GCC linter for Ada
Diffstat (limited to 'ale_linters')
-rw-r--r-- | ale_linters/ada/gcc.vim | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ale_linters/ada/gcc.vim b/ale_linters/ada/gcc.vim new file mode 100644 index 00000000..d6f973ae --- /dev/null +++ b/ale_linters/ada/gcc.vim @@ -0,0 +1,54 @@ +" Author: Martino Pilia <martino.pilia@gmail.com> +" Description: Lint Ada files with GCC + +call ale#Set('ada_gcc_executable', 'gcc') + +" -gnatwa: activate most optional warnings +" -gnatq: try semantic analysis even if syntax errors have been found +call ale#Set('ada_gcc_options', '-gnatwa -gnatq') + +function! ale_linters#ada#gcc#GetCommand(buffer) abort + " Build a suitable output file name. The output file is specified because + " the .ali file may be created even if no code generation is attempted. + " The output file name must match the source file name (except for the + " extension), so here we cannot use the null file as output. + let l:tmp_dir = fnamemodify(ale#engine#CreateDirectory(a:buffer), ':p') + let l:out_file = l:tmp_dir . fnamemodify(bufname(a:buffer), ':t:r') . '.o' + + " -gnatc: Check syntax and semantics only (no code generation attempted) + return '%e -x ada -c -gnatc' + \ . ' -o ' . ale#Escape(l:out_file) + \ . ' -I ' . ale#Escape(fnamemodify(bufname(a:buffer), ':p:h')) + \ . ale#Pad(ale#Var(a:buffer, 'ada_gcc_options')) + \ . ' %t' +endfunction + +" For the message format please refer to: +" https://gcc.gnu.org/onlinedocs/gnat_ugn/Output-and-Error-Message-Control.html +" https://gcc.gnu.org/onlinedocs/gnat_ugn/Warning-Message-Control.html +function! ale_linters#ada#gcc#Handle(buffer, lines) abort + " Error format: <filename>:<lnum>:<col>: <text> + " Warning format: <filename>:<lnum>:<col>: warning: <text> + let l:re = '\v(.+):([0-9]+):([0-9]+):\s+(warning:)?\s*(.+)\s*' + let l:output = [] + + for l:match in ale#util#GetMatches(a:lines, l:re) + call add(l:output, { + \ 'bufnr': a:buffer, + \ 'lnum': str2nr(l:match[2]), + \ 'col': str2nr(l:match[3]), + \ 'type': l:match[4] is# 'warning:' ? 'W' : 'E', + \ 'text': l:match[5], + \}) + endfor + + return l:output +endfunction + +call ale#linter#Define('ada', { +\ 'name': 'gcc', +\ 'output_stream': 'stderr', +\ 'executable_callback': ale#VarFunc('ada_gcc_executable'), +\ 'command_callback': 'ale_linters#ada#gcc#GetCommand', +\ 'callback': 'ale_linters#ada#gcc#Handle', +\}) |