Optimise ale#Var a little

This commit is contained in:
w0rp 2018-07-04 23:54:14 +01:00
parent 9ddf1b6a05
commit 13a8f9c061
No known key found for this signature in database
GPG key ID: 0FC1ECAA8C81CD83
4 changed files with 6 additions and 19 deletions

View file

@ -191,15 +191,12 @@ endfunction
"
" Every variable name will be prefixed with 'ale_'.
function! ale#Var(buffer, variable_name) abort
let l:nr = str2nr(a:buffer)
let l:full_name = 'ale_' . a:variable_name
let l:vars = getbufvar(str2nr(a:buffer), '', 0)
if bufexists(l:nr)
let l:vars = getbufvar(l:nr, '')
elseif has_key(g:, 'ale_fix_buffer_data')
let l:vars = get(g:ale_fix_buffer_data, l:nr, {'vars': {}}).vars
else
let l:vars = {}
if l:vars is 0
" Look for variables from deleted buffers, saved from :ALEFix
let l:vars = get(get(g:ale_fix_buffer_data, a:buffer, {}), 'vars', {})
endif
return get(l:vars, l:full_name, g:[l:full_name])

View file

@ -1,10 +1,3 @@
" This global Dictionary tracks the ALE fix data for jobs, etc.
" This Dictionary should not be accessed outside of the plugin. It is only
" global so it can be modified in Vader tests.
if !has_key(g:, 'ale_fix_buffer_data')
let g:ale_fix_buffer_data = {}
endif
if !has_key(s:, 'job_info_map')
let s:job_info_map = {}
endif

View file

@ -44,6 +44,8 @@ endif
" This global variable is used internally by ALE for tracking information for
" each buffer which linters are being run against.
let g:ale_buffer_info = {}
" This global Dictionary tracks data for fixing code. Don't mess with it.
let g:ale_fix_buffer_data = {}
" User Configuration

View file

@ -34,8 +34,3 @@ Execute(ale#Var should return the global variable for unknown variables):
let g:ale_fix_buffer_data = {}
AssertEqual 'abc', ale#Var(1347347, 'some_variable')
Execute(ale#Var should return the global variables when the ALE fix variable is undefined):
unlet! g:ale_fix_buffer_data
AssertEqual 'abc', ale#Var(1347347, 'some_variable')