This repository has been archived on 2024-07-19. You can view files and clone it, but cannot push or open issues or pull requests.
ale/ale_linters/elixir/mix.vim

63 lines
1.9 KiB
VimL
Raw Normal View History

2017-08-23 07:03:13 +00:00
" Author: evnu - https://github.com/evnu
" Author: colbydehart - https://github.com/colbydehart
" Description: Mix compile checking for Elixir files
2017-08-23 07:03:13 +00:00
function! ale_linters#elixir#mix#Handle(buffer, lines) abort
" Matches patterns like the following:
"
" Error format
" ** (CompileError) apps/sim/lib/sim/server.ex:87: undefined function update_in/4
"
" TODO: Warning format
" warning: variable "foobar" does not exist and is being expanded to "foobar()", please use parentheses to remove the ambiguity or change the variable name
let l:pattern = '\v\(([^\)]+Error)\) ([^:]+):([^:]+): (.+)$'
let l:output = []
for l:match in ale#util#GetMatches(a:lines, l:pattern)
let l:type = 'E'
let l:text = l:match[4]
call add(l:output, {
\ 'bufnr': a:buffer,
\ 'lnum': l:match[3] + 0,
\ 'col': 0,
\ 'type': l:type,
\ 'text': l:text,
\})
endfor
return l:output
endfunction
2018-06-07 03:58:32 +00:00
function! ale_linters#elixir#mix#FindProjectRoot(buffer) abort
2018-06-07 16:47:57 +00:00
let l:mix_file = ale#path#FindNearestFile(a:buffer, 'mix.exs')
2018-06-07 16:47:57 +00:00
if !empty(l:mix_file)
return fnamemodify(l:mix_file, ':p:h')
2018-06-07 03:58:32 +00:00
endif
2018-06-07 16:47:57 +00:00
return '.'
2018-06-07 03:58:32 +00:00
endfunction
function! ale_linters#elixir#mix#GetCommand(buffer) abort
2018-06-07 03:58:32 +00:00
let l:project_root = ale_linters#elixir#mix#FindProjectRoot(a:buffer)
let l:temp_dir = ale#engine#CreateDirectory(a:buffer)
let l:mix_build_path = has('win32')
2018-06-20 21:44:56 +00:00
\ ? 'set MIX_BUILD_PATH=' . ale#Escape(l:temp_dir) . ' &&'
\ : 'MIX_BUILD_PATH=' . ale#Escape(l:temp_dir)
2018-06-07 16:47:57 +00:00
return ale#path#CdString(l:project_root)
\ . l:mix_build_path
\ . ' mix compile %s'
2017-08-23 07:03:13 +00:00
endfunction
call ale#linter#Define('elixir', {
\ 'name': 'mix',
\ 'executable': 'mix',
\ 'command_callback': 'ale_linters#elixir#mix#GetCommand',
2017-08-23 07:03:13 +00:00
\ 'callback': 'ale_linters#elixir#mix#Handle',
2018-06-07 03:58:32 +00:00
\ 'lint_file': 1,
2017-08-23 07:03:13 +00:00
\})