Created
November 12, 2019 13:38
-
-
Save kevinw/b178f5443e559ed14b838669fe747c9c to your computer and use it in GitHub Desktop.
ALE linter for odin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let g:ale_odin_compiler = "c:\\Users\\Lyra\\src\\odin\\odin.exe" | |
let g:ale_linters = { | |
\ 'odin': ['odin'] | |
\} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Author: Kevin Watters <[email protected]> | |
" 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' | |
\}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI the
odin.vim
file goes in.vim/plugged/ale/ale_linters/odin/odin.vim
, or wherever you have ALE installed.