mirror of https://github.com/dense-analysis/ale
Optimise ale#Var a little
This commit is contained in:
parent
9ddf1b6a05
commit
13a8f9c061
|
@ -191,15 +191,12 @@ endfunction
|
||||||
"
|
"
|
||||||
" Every variable name will be prefixed with 'ale_'.
|
" Every variable name will be prefixed with 'ale_'.
|
||||||
function! ale#Var(buffer, variable_name) abort
|
function! ale#Var(buffer, variable_name) abort
|
||||||
let l:nr = str2nr(a:buffer)
|
|
||||||
let l:full_name = 'ale_' . a:variable_name
|
let l:full_name = 'ale_' . a:variable_name
|
||||||
|
let l:vars = getbufvar(str2nr(a:buffer), '', 0)
|
||||||
|
|
||||||
if bufexists(l:nr)
|
if l:vars is 0
|
||||||
let l:vars = getbufvar(l:nr, '')
|
" Look for variables from deleted buffers, saved from :ALEFix
|
||||||
elseif has_key(g:, 'ale_fix_buffer_data')
|
let l:vars = get(get(g:ale_fix_buffer_data, a:buffer, {}), 'vars', {})
|
||||||
let l:vars = get(g:ale_fix_buffer_data, l:nr, {'vars': {}}).vars
|
|
||||||
else
|
|
||||||
let l:vars = {}
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return get(l:vars, l:full_name, g:[l:full_name])
|
return get(l:vars, l:full_name, g:[l:full_name])
|
||||||
|
|
|
@ -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')
|
if !has_key(s:, 'job_info_map')
|
||||||
let s:job_info_map = {}
|
let s:job_info_map = {}
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -44,6 +44,8 @@ endif
|
||||||
" This global variable is used internally by ALE for tracking information for
|
" This global variable is used internally by ALE for tracking information for
|
||||||
" each buffer which linters are being run against.
|
" each buffer which linters are being run against.
|
||||||
let g:ale_buffer_info = {}
|
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
|
" User Configuration
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,3 @@ Execute(ale#Var should return the global variable for unknown variables):
|
||||||
let g:ale_fix_buffer_data = {}
|
let g:ale_fix_buffer_data = {}
|
||||||
|
|
||||||
AssertEqual 'abc', ale#Var(1347347, 'some_variable')
|
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')
|
|
||||||
|
|
Loading…
Reference in New Issue