Until I get odin support in ALE's tree proper, here's how you register an odin check -vet linter with ALE so your edit->compile->fix loop is shorter!
Last active
September 18, 2019 02:06
-
-
Save kevinw/9cd4ac6830d5547a9dc8722b1a27cc7e to your computer and use it in GitHub Desktop.
run `odin check -vet` as a Vim ALE linter (async code checking as you write)
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
| " example .vimrc configuration using vim-plug as package manager https://github.com/junegunn/vim-plug | |
| call plug#begin('~/.vim/plugged') | |
| " Install ALE, the asynchronous linting plugin. | |
| Plug 'w0rp/ale' | |
| " Install odin syntax recognition | |
| Plug 'Tetralux/odin.vim' | |
| " Point odin.vim at your local odin compiler | |
| let g:ale_odin_compiler = "c:\\Users\\EXAMPLE_YOUR_USER\\PATH_TO_SRC\\odin\\odin.exe" | |
| " And register odin.vim as an odin "checker" | |
| let g:ale_linters = { | |
| \ 'odin': ['odin'] | |
| \} | |
| " ... any more plugins you have installed | |
| call plug#end() |
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
| " | |
| " THIS FILE MUST GO IN ALE's ale_linters directory, like this: | |
| " | |
| " ~/.vim/plugged/ale/ale_linters/odin/odin.vim | |
| " | |
| " If you're using a different plugin manager, the ale root folder may be somewhere else. | |
| " | |
| " Author: Kevin Watters <kevinwatters@gmail.com> | |
| " Description: This file adds support for checking odin code with the odin | |
| " compiler's "vet" command. | |
| function! ale_linters#odin#odin#GetExecutable(buffer) abort | |
| return g:ale_odin_compiler | |
| endfunction | |
| function! ale_linters#odin#odin#GetCommand(buffer) abort | |
| return fnameescape(ale_linters#odin#odin#GetExecutable(a:buffer)) | |
| \ . ' check %s -vet' | |
| 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) | |
| " because odin check complains about missing mains | |
| if l:match[3] == "Undefined entry point procedure 'main'" | |
| 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
