summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-04 23:54:14 +0100
committerw0rp <devw0rp@gmail.com>2018-07-04 23:54:14 +0100
commit13a8f9c06110c065086ce7e569bab68d0e222398 (patch)
treea20f312df929d82d81a96adc4061772602ae7b80
parent9ddf1b6a050bea6706bd51f2fd5f252c735bc1cc (diff)
downloadale-13a8f9c06110c065086ce7e569bab68d0e222398.zip
Optimise ale#Var a little
-rw-r--r--autoload/ale.vim11
-rw-r--r--autoload/ale/fix.vim7
-rw-r--r--plugin/ale.vim2
-rw-r--r--test/test_ale_var.vader5
4 files changed, 6 insertions, 19 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim
index dcc12150..8aa8bbd9 100644
--- a/autoload/ale.vim
+++ b/autoload/ale.vim
@@ -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])
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 1e056200..6e5875f6 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -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
diff --git a/plugin/ale.vim b/plugin/ale.vim
index 3bd12015..16a40268 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -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
diff --git a/test/test_ale_var.vader b/test/test_ale_var.vader
index fb674d93..5f42fe95 100644
--- a/test/test_ale_var.vader
+++ b/test/test_ale_var.vader
@@ -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')