diff options
author | w0rp <w0rp@users.noreply.github.com> | 2020-03-04 20:56:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-04 20:56:22 +0000 |
commit | 8f7ccdc5e95302223c516a0113f5af7e075dc041 (patch) | |
tree | 58c960285486a80745264ab94e72725d30b762ea | |
parent | 634c81fd465269f59e3db878fe8405828e6d2da9 (diff) | |
download | ale-8f7ccdc5e95302223c516a0113f5af7e075dc041.zip |
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
-rw-r--r-- | autoload/ale/util.vim | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 99cd856a..8d166625 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -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# ''...''') |