Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created November 12, 2019 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinw/b178f5443e559ed14b838669fe747c9c to your computer and use it in GitHub Desktop.
Save kevinw/b178f5443e559ed14b838669fe747c9c to your computer and use it in GitHub Desktop.
ALE linter for odin
let g:ale_odin_compiler = "c:\\Users\\Lyra\\src\\odin\\odin.exe"
let g:ale_linters = {
\ 'odin': ['odin']
\}
" Author: Kevin Watters <kevinwatters@gmail.com>
" Description: This file adds support for checking odin code with the odin
" compiler.
function! ale_linters#odin#odin#GetExecutable(buffer) abort
return g:ale_odin_compiler
endfunction
function! ale_linters#odin#odin#GetCommand(buffer) abort
let l:buf_direc = expand('%:h')
return fnameescape(ale_linters#odin#odin#GetExecutable(a:buffer))
\ . ' check ' . l:buf_direc . ' -vet -ignore-unknown-attributes'
endfunction
function! ale_linters#odin#odin#HandleOdinCompilerCheck(buffer, lines) abort
" Regular expression to match messages:
" They look like:
"C:\path\to\file.odin(80:5) 'foo' declared but not used
let l:pattern = '\v(.*)\((\d+):(\d+)\)\s+(.*)$'
" For each match, update the l:output list:
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:message = l:match[4]
" Hack for now because odin check complains about missing mains, or
" too many mains.
if l:message == "Undefined entry point procedure 'main'"
continue
endif
if l:message == "Redeclaration of the entry pointer procedure 'main'"
continue
endif
if l:message == "Redeclaration of 'main' in this scope"
continue
endif
call add(l:output, {
\ 'filename': expand(l:match[1]),
\ 'lnum': l:match[2],
\ 'col': l:match[3],
\ 'text': l:match[4],
\ 'type': 'E'
\})
endfor
return l:output
endfunction
call ale#linter#Define('odin', {
\ 'name': 'odin',
\ 'executable_callback': 'ale_linters#odin#odin#GetExecutable',
\ 'command_callback': 'ale_linters#odin#odin#GetCommand',
\ 'callback': 'ale_linters#odin#odin#HandleOdinCompilerCheck',
\ 'output_stream': 'both'
\})
@kevinw
Copy link
Author

kevinw commented Nov 12, 2019

FYI the odin.vim file goes in .vim/plugged/ale/ale_linters/odin/odin.vim, or wherever you have ALE installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment