]> git.madduck.net Git - etc/vim.git/blobdiff - .vim/bundle/ale/ale_linters/ada/gcc.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Merge commit '76265755a1add77121c8f9dabb3e9bb70fe9a972' as '.vim/bundle/ale'
[etc/vim.git] / .vim / bundle / ale / ale_linters / ada / gcc.vim
diff --git a/.vim/bundle/ale/ale_linters/ada/gcc.vim b/.vim/bundle/ale/ale_linters/ada/gcc.vim
new file mode 100644 (file)
index 0000000..5afc9ae
--- /dev/null
@@ -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#command#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 %s: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': {b -> ale#Var(b, 'ada_gcc_executable')},
+\   'command': function('ale_linters#ada#gcc#GetCommand'),
+\   'callback': 'ale_linters#ada#gcc#Handle',
+\})