#591 Store buffer variables when fixing filess, and read them back in ale#Var
This commit is contained in:
parent
6ec965c8e4
commit
b9f4b0373a
@ -128,9 +128,18 @@ 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
|
||||||
|
|
||||||
return getbufvar(str2nr(a:buffer), l:full_name, g:[l:full_name])
|
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 = {}
|
||||||
|
endif
|
||||||
|
|
||||||
|
return get(l:vars, l:full_name, g:[l:full_name])
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Initialize a variable with a default value, if it isn't already set.
|
" Initialize a variable with a default value, if it isn't already set.
|
||||||
|
@ -305,6 +305,7 @@ function! ale#fix#InitBufferData(buffer, fixing_flag) abort
|
|||||||
" The 'done' flag tells the function for applying changes when fixing
|
" The 'done' flag tells the function for applying changes when fixing
|
||||||
" is complete.
|
" is complete.
|
||||||
let g:ale_fix_buffer_data[a:buffer] = {
|
let g:ale_fix_buffer_data[a:buffer] = {
|
||||||
|
\ 'vars': getbufvar(a:buffer, ''),
|
||||||
\ 'lines_before': getbufline(a:buffer, 1, '$'),
|
\ 'lines_before': getbufline(a:buffer, 1, '$'),
|
||||||
\ 'filename': expand('#' . a:buffer . ':p'),
|
\ 'filename': expand('#' . a:buffer . ':p'),
|
||||||
\ 'done': 0,
|
\ 'done': 0,
|
||||||
|
@ -11,6 +11,7 @@ Before:
|
|||||||
let g:ale_enabled = 0
|
let g:ale_enabled = 0
|
||||||
let g:ale_echo_cursor = 0
|
let g:ale_echo_cursor = 0
|
||||||
let g:ale_run_synchronously = 1
|
let g:ale_run_synchronously = 1
|
||||||
|
let g:ale_fix_buffer_data = {}
|
||||||
let g:ale_fixers = {
|
let g:ale_fixers = {
|
||||||
\ 'testft': [],
|
\ 'testft': [],
|
||||||
\}
|
\}
|
||||||
@ -75,6 +76,8 @@ After:
|
|||||||
call delete('fix_test_file')
|
call delete('fix_test_file')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let g:ale_fix_buffer_data = {}
|
||||||
|
|
||||||
Given testft (A file with three lines):
|
Given testft (A file with three lines):
|
||||||
a
|
a
|
||||||
b
|
b
|
||||||
@ -291,3 +294,24 @@ Expect(The buffer should be the same):
|
|||||||
a
|
a
|
||||||
b
|
b
|
||||||
c
|
c
|
||||||
|
|
||||||
|
Given testft (A file with three lines):
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
||||||
|
|
||||||
|
Execute(ale#fix#InitBufferData() should set up the correct data):
|
||||||
|
noautocmd silent file fix_test_file
|
||||||
|
|
||||||
|
call ale#fix#InitBufferData(bufnr(''), 'save_file')
|
||||||
|
|
||||||
|
AssertEqual {
|
||||||
|
\ bufnr(''): {
|
||||||
|
\ 'temporary_directory_list': [],
|
||||||
|
\ 'vars': b:,
|
||||||
|
\ 'filename': simplify(getcwd() . '/fix_test_file'),
|
||||||
|
\ 'done': 0,
|
||||||
|
\ 'lines_before': ['a', 'b', 'c'],
|
||||||
|
\ 'should_save': 1,
|
||||||
|
\ },
|
||||||
|
\}, g:ale_fix_buffer_data
|
||||||
|
@ -3,6 +3,9 @@ Before:
|
|||||||
|
|
||||||
After:
|
After:
|
||||||
unlet! g:ale_some_variable
|
unlet! g:ale_some_variable
|
||||||
|
unlet! b:undefined_variable_name
|
||||||
|
|
||||||
|
let g:ale_fix_buffer_data = {}
|
||||||
|
|
||||||
Execute(ale#Var should return global variables):
|
Execute(ale#Var should return global variables):
|
||||||
AssertEqual 'abc', ale#Var(bufnr(''), 'some_variable')
|
AssertEqual 'abc', ale#Var(bufnr(''), 'some_variable')
|
||||||
@ -18,4 +21,21 @@ Execute(ale#Var should return buffer overrides for buffer numbers as strings):
|
|||||||
AssertEqual 'def', ale#Var(string(bufnr('')), 'some_variable')
|
AssertEqual 'def', ale#Var(string(bufnr('')), 'some_variable')
|
||||||
|
|
||||||
Execute(ale#Var should throw exceptions for undefined variables):
|
Execute(ale#Var should throw exceptions for undefined variables):
|
||||||
|
let b:undefined_variable_name = 'def'
|
||||||
|
|
||||||
AssertThrows call ale#Var(bufnr(''), 'undefined_variable_name')
|
AssertThrows call ale#Var(bufnr(''), 'undefined_variable_name')
|
||||||
|
|
||||||
|
Execute(ale#Var return variables from deleted buffers, saved for fixing things):
|
||||||
|
let g:ale_fix_buffer_data[1347347] = {'vars': {'ale_some_variable': 'def'}}
|
||||||
|
|
||||||
|
AssertEqual 'def', ale#Var(1347347, 'some_variable')
|
||||||
|
|
||||||
|
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')
|
||||||
|
Loading…
Reference in New Issue
Block a user