Refactor the "s:LoadArgCount()" function (#3025)

* Refactor the "s:LoadArgCount()" function

Previously, this function would always set "v:errmsg" on the first
call with a given function.  This is because autoloaded functions
are not defined on the first call.

A number of improvements have been made:
 - a useless local function ("l:Function") is removed
 - the "execute()" builtin captures the output, instead of ":redir"
 - a ":try" block handles the case where a function is not defined
 - a useless ":if" is removed since ":redir" always defines the var
 - confusing quoting is re-written (remove double "'" chars)

Fixes: #3021
This commit is contained in:
w0rp 2020-03-04 20:56:22 +00:00 committed by GitHub
parent 634c81fd46
commit 8f7ccdc5e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -336,15 +336,11 @@ function! ale#util#GetMatches(lines, patterns) abort
endfunction
function! s:LoadArgCount(function) abort
let l:Function = a:function
redir => l:output
silent! function Function
redir END
if !exists('l:output')
try
let l:output = execute('function a:function')
catch /E123/
return 0
endif
endtry
let l:match = matchstr(split(l:output, "\n")[0], '\v\([^)]+\)')[1:-2]
let l:arg_list = filter(split(l:match, ', '), 'v:val isnot# ''...''')