feat(erlang/erlc): add option for custom executable

This commit is contained in:
pinicarus 2020-10-28 11:48:57 +01:00
parent 557a1ed5da
commit 15f44933c2
No known key found for this signature in database
GPG key ID: BED1B8A689160C89
3 changed files with 60 additions and 4 deletions

View file

@ -1,14 +1,22 @@
" Author: Magnus Ottenklinger - https://github.com/evnu " Author: Magnus Ottenklinger - https://github.com/evnu
let g:ale_erlang_erlc_executable = get(g:, 'ale_erlang_erlc_executable', 'erlc')
let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '') let g:ale_erlang_erlc_options = get(g:, 'ale_erlang_erlc_options', '')
function! ale_linters#erlang#erlc#GetExecutable(buffer) abort
return ale#Var(a:buffer, 'erlang_erlc_executable')
endfunction
function! ale_linters#erlang#erlc#GetCommand(buffer) abort function! ale_linters#erlang#erlc#GetCommand(buffer) abort
let l:output_file = ale#util#Tempname() let l:output_file = ale#util#Tempname()
call ale#command#ManageFile(a:buffer, l:output_file) call ale#command#ManageFile(a:buffer, l:output_file)
return 'erlc -o ' . ale#Escape(l:output_file) let l:command = ale#Escape(ale_linters#erlang#erlc#GetExecutable(a:buffer))
\ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options') \ . ' -o ' . ale#Escape(l:output_file)
\ . ' %t' \ . ' ' . ale#Var(a:buffer, 'erlang_erlc_options')
\ . ' %t'
return l:command
endfunction endfunction
function! ale_linters#erlang#erlc#Handle(buffer, lines) abort function! ale_linters#erlang#erlc#Handle(buffer, lines) abort
@ -90,7 +98,7 @@ endfunction
call ale#linter#Define('erlang', { call ale#linter#Define('erlang', {
\ 'name': 'erlc', \ 'name': 'erlc',
\ 'executable': 'erlc', \ 'executable': function('ale_linters#erlang#erlc#GetExecutable'),
\ 'command': function('ale_linters#erlang#erlc#GetCommand'), \ 'command': function('ale_linters#erlang#erlc#GetCommand'),
\ 'callback': 'ale_linters#erlang#erlc#Handle', \ 'callback': 'ale_linters#erlang#erlc#Handle',
\}) \})

View file

@ -34,6 +34,14 @@ g:ale_erlang_dialyzer_rebar3_profile *g:ale_erlang_dialyzer_rebar3_profile*
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
erlc *ale-erlang-erlc* erlc *ale-erlang-erlc*
g:ale_erlang_erlc_executable *g:ale_erlang_erlc_executable*
*b:ale_erlang_erlc_executable*
Type: |String|
Default: `'erlc'`
This variable can be changed to specify the erlc executable.
g:ale_erlang_erlc_options *g:ale_erlang_erlc_options* g:ale_erlang_erlc_options *g:ale_erlang_erlc_options*
*b:ale_erlang_erlc_options* *b:ale_erlang_erlc_options*
Type: |String| Type: |String|

View file

@ -0,0 +1,40 @@
Before:
call ale#assert#SetUpLinterTest('erlang', 'erlc')
After:
call ale#assert#TearDownLinterTest()
Execute(The default command should be correct.):
let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
let g:regex = '^''erlc''\s\+-o\s\+[^\s]\+\s\+%t'
let g:matched = match(g:cmd, g:regex)
" match returns -1 if not found
AssertNotEqual
\ g:matched,
\ -1,
\ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'
Execute(The command should accept configured executable.):
let b:ale_erlang_erlc_executable = '/usr/bin/erlc'
let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
let g:regex = '^''/usr/bin/erlc''\s\+-o\s\+[^\s]\+\s\+%t'
let g:matched = match(g:cmd, g:regex)
" match returns -1 if not found
AssertNotEqual
\ g:matched,
\ -1,
\ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'
Execute(The command should accept configured options.):
let b:ale_erlang_erlc_options = '-I include'
let g:cmd = ale_linters#erlang#erlc#GetCommand(bufnr(''))
let g:regex = '^''erlc''\s\+-o\s\+[^\s]\+\s\+-I include\s\+%t'
let g:matched = match(g:cmd, g:regex)
" match returns -1 if not found
AssertNotEqual
\ g:matched,
\ -1,
\ 'Command error: expected [' . g:cmd . '] to match [' . g:regex . ']'