Merge everything into the one global map.
This commit is contained in:
parent
0dbf08f6d5
commit
c546f47cc0
13 changed files with 122 additions and 77 deletions
|
@ -2,10 +2,6 @@
|
||||||
" Description: Utility functions related to cleaning state.
|
" Description: Utility functions related to cleaning state.
|
||||||
|
|
||||||
function! ale#cleanup#Buffer(buffer) abort
|
function! ale#cleanup#Buffer(buffer) abort
|
||||||
if has_key(g:ale_buffer_loclist_map, a:buffer)
|
|
||||||
call remove(g:ale_buffer_loclist_map, a:buffer)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if has_key(g:ale_buffer_info, a:buffer)
|
if has_key(g:ale_buffer_info, a:buffer)
|
||||||
" When buffers are removed, clear all of the jobs.
|
" When buffers are removed, clear all of the jobs.
|
||||||
for l:job in get(g:ale_buffer_info[a:buffer], 'job_list', [])
|
for l:job in get(g:ale_buffer_info[a:buffer], 'job_list', [])
|
||||||
|
|
|
@ -46,12 +46,12 @@ function! ale#cursor#EchoCursorWarning(...) abort
|
||||||
|
|
||||||
let l:buffer = bufnr('%')
|
let l:buffer = bufnr('%')
|
||||||
|
|
||||||
if !has_key(g:ale_buffer_loclist_map, l:buffer)
|
if !has_key(g:ale_buffer_info, l:buffer)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:pos = getcurpos()
|
let l:pos = getcurpos()
|
||||||
let l:loclist = g:ale_buffer_loclist_map[l:buffer]
|
let l:loclist = g:ale_buffer_info[l:buffer].loclist
|
||||||
let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2])
|
let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2])
|
||||||
|
|
||||||
if l:index >= 0
|
if l:index >= 0
|
||||||
|
|
|
@ -26,6 +26,7 @@ function! ale#engine#InitBufferInfo(buffer) abort
|
||||||
\ 'job_list': [],
|
\ 'job_list': [],
|
||||||
\ 'should_reset': 1,
|
\ 'should_reset': 1,
|
||||||
\ 'dummy_sign_set': 0,
|
\ 'dummy_sign_set': 0,
|
||||||
|
\ 'loclist': [],
|
||||||
\}
|
\}
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -121,28 +122,28 @@ function! s:HandleExit(job) abort
|
||||||
" Set the flag for resetting the loclist to 0 again, so we won't
|
" Set the flag for resetting the loclist to 0 again, so we won't
|
||||||
" empty the list later.
|
" empty the list later.
|
||||||
let g:ale_buffer_info[l:buffer].should_reset = 0
|
let g:ale_buffer_info[l:buffer].should_reset = 0
|
||||||
let g:ale_buffer_loclist_map[l:buffer] = []
|
let g:ale_buffer_info[l:buffer].loclist = []
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Add the loclist items from the linter.
|
" Add the loclist items from the linter.
|
||||||
call extend(g:ale_buffer_loclist_map[l:buffer], l:linter_loclist)
|
call extend(g:ale_buffer_info[l:buffer].loclist, l:linter_loclist)
|
||||||
|
|
||||||
" Sort the loclist again.
|
" Sort the loclist again.
|
||||||
" We need a sorted list so we can run a binary search against it
|
" We need a sorted list so we can run a binary search against it
|
||||||
" for efficient lookup of the messages in the cursor handler.
|
" for efficient lookup of the messages in the cursor handler.
|
||||||
call sort(g:ale_buffer_loclist_map[l:buffer], 'ale#util#LocItemCompare')
|
call sort(g:ale_buffer_info[l:buffer].loclist, 'ale#util#LocItemCompare')
|
||||||
|
|
||||||
if g:ale_set_loclist
|
if g:ale_set_loclist
|
||||||
call setloclist(0, g:ale_buffer_loclist_map[l:buffer])
|
call setloclist(0, g:ale_buffer_info[l:buffer].loclist)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if g:ale_set_signs
|
if g:ale_set_signs
|
||||||
call ale#sign#SetSigns(l:buffer, g:ale_buffer_loclist_map[l:buffer])
|
call ale#sign#SetSigns(l:buffer, g:ale_buffer_info[l:buffer].loclist)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if exists('*ale#statusline#Update')
|
if exists('*ale#statusline#Update')
|
||||||
" Don't load/run if not already loaded.
|
" Don't load/run if not already loaded.
|
||||||
call ale#statusline#Update(l:buffer, g:ale_buffer_loclist_map[l:buffer])
|
call ale#statusline#Update(l:buffer, g:ale_buffer_info[l:buffer].loclist)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Call user autocommands. This allows users to hook into ALE's lint cycle.
|
" Call user autocommands. This allows users to hook into ALE's lint cycle.
|
||||||
|
@ -281,6 +282,15 @@ function! ale#engine#Invoke(buffer, linter) abort
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Given a buffer number, return the warnings and errors for a given buffer.
|
||||||
|
function! ale#engine#GetLoclist(buffer) abort
|
||||||
|
if !has_key(g:ale_buffer_info, a:buffer)
|
||||||
|
return []
|
||||||
|
endif
|
||||||
|
|
||||||
|
return g:ale_buffer_info[a:buffer].loclist
|
||||||
|
endfunction
|
||||||
|
|
||||||
" This function can be called with a timeout to wait for all jobs to finish.
|
" This function can be called with a timeout to wait for all jobs to finish.
|
||||||
" If the jobs to not finish in the given number of milliseconds,
|
" If the jobs to not finish in the given number of milliseconds,
|
||||||
" an exception will be thrown.
|
" an exception will be thrown.
|
||||||
|
|
|
@ -27,7 +27,7 @@ function! s:SetupCount(buffer) abort
|
||||||
|
|
||||||
" Cache is cold, so manually ask for an update.
|
" Cache is cold, so manually ask for an update.
|
||||||
if !has_key(g:ale_buffer_info[a:buffer], 'count')
|
if !has_key(g:ale_buffer_info[a:buffer], 'count')
|
||||||
call ale#statusline#Update(a:buffer, get(g:ale_buffer_loclist_map, a:buffer, []))
|
call ale#statusline#Update(a:buffer, g:ale_buffer_info[a:buffer].loclist)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
24
doc/ale.txt
24
doc/ale.txt
|
@ -145,23 +145,6 @@ g:ale_linter_aliases *g:ale_linter_aliases*
|
||||||
different set of linters from the type it is being mapped to.
|
different set of linters from the type it is being mapped to.
|
||||||
|
|
||||||
|
|
||||||
g:ale_buffer_loclist_map *g:ale_buffer_loclist_map*
|
|
||||||
|
|
||||||
Type: |Dictionary|
|
|
||||||
Default: `{}`
|
|
||||||
|
|
||||||
This variable is used internally by ALE for tracking the warnings and
|
|
||||||
errors for a particular buffer. The dictionary maps a buffer number to
|
|
||||||
a |List| of |Dictionary| items in the format accepted by |setqflist()|,
|
|
||||||
with a minor addition of a `linter_name` for each object which describes
|
|
||||||
the linter which reported the warnings and errors. (A buffer may run
|
|
||||||
multiple linters in combination on the same filetype.)
|
|
||||||
|
|
||||||
NOTE: This variable should not be modified outside of the plugin itself,
|
|
||||||
but can be read in other plugins whenever information about the current
|
|
||||||
errors and warnings ALE is reporting is needed.
|
|
||||||
|
|
||||||
|
|
||||||
g:ale_lint_on_text_changed *g:ale_lint_on_text_changed*
|
g:ale_lint_on_text_changed *g:ale_lint_on_text_changed*
|
||||||
|
|
||||||
Type: |Number|
|
Type: |Number|
|
||||||
|
@ -556,6 +539,13 @@ ale#Queue(delay) *ale#Queue()*
|
||||||
again from the same buffer
|
again from the same buffer
|
||||||
|
|
||||||
|
|
||||||
|
ale#engine#GetLoclist(buffer) *ale#engine#GetLoclist()*
|
||||||
|
|
||||||
|
Given a buffer number, this function will rerurn the list of warnings and
|
||||||
|
errors reported by ALE for a given buffer in the format accepted by
|
||||||
|
|setqflist()|.
|
||||||
|
|
||||||
|
|
||||||
ale#linter#Define(filetype, linter) *ale#linter#Define()*
|
ale#linter#Define(filetype, linter) *ale#linter#Define()*
|
||||||
Given a |String| for a filetype and a |Dictionary| Describing a linter
|
Given a |String| for a filetype and a |Dictionary| Describing a linter
|
||||||
configuration, add a linter for the given filetype. The dictionaries each
|
configuration, add a linter for the given filetype. The dictionaries each
|
||||||
|
|
|
@ -22,9 +22,8 @@ if !s:ale_has_required_features
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Globals
|
" This global variable is used internally by ALE for tracking information for
|
||||||
|
" each buffer which linters are being run against.
|
||||||
let g:ale_buffer_loclist_map = {}
|
|
||||||
let g:ale_buffer_info = {}
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
" User Configuration
|
" User Configuration
|
||||||
|
|
|
@ -7,11 +7,14 @@ Before:
|
||||||
|
|
||||||
After:
|
After:
|
||||||
augroup! VaderTest
|
augroup! VaderTest
|
||||||
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
Given vim (Some vimscript):
|
Given vim (Some vimscript):
|
||||||
set nocompatible
|
set nocompatible
|
||||||
|
|
||||||
Execute (Lint it):
|
Execute (Lint it):
|
||||||
call ale#Lint()
|
call ale#Lint()
|
||||||
call ale#engine#WaitForJobs(2000)
|
call ale#engine#WaitForJobs(2000)
|
||||||
|
|
||||||
Then (Autocommands should have run):
|
Then (Autocommands should have run):
|
||||||
AssertEqual g:success, 1
|
AssertEqual g:success, 1
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
Before:
|
Before:
|
||||||
let g:buffer = bufnr('%')
|
let g:buffer = bufnr('%')
|
||||||
let g:ale_buffer_loclist_map = {
|
|
||||||
\ g:buffer : [],
|
|
||||||
\ 10347: [],
|
|
||||||
\}
|
|
||||||
|
|
||||||
let g:ale_buffer_info = {
|
let g:ale_buffer_info = {
|
||||||
\ g:buffer : {},
|
\ g:buffer : {},
|
||||||
|
@ -12,10 +8,8 @@ Before:
|
||||||
|
|
||||||
After:
|
After:
|
||||||
unlet! g:buffer
|
unlet! g:buffer
|
||||||
let g:ale_buffer_loclist_map = {}
|
|
||||||
let g:ale_buffer_info = {}
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
Execute('ALE globals should be cleared when the buffer is closed.'):
|
Execute('ALE globals should be cleared when the buffer is closed.'):
|
||||||
:q!
|
:q!
|
||||||
AssertEqual {10347: []}, g:ale_buffer_loclist_map
|
|
||||||
AssertEqual {10347: {}}, g:ale_buffer_info
|
AssertEqual {10347: {}}, g:ale_buffer_info
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
Before:
|
Before:
|
||||||
let g:ale_buffer_loclist_map = {
|
let g:ale_buffer_info = {
|
||||||
\ bufnr('%'): [
|
\ bufnr('%'): {
|
||||||
\ {
|
\ 'loclist': [
|
||||||
\ 'lnum': 1,
|
\ {
|
||||||
\ 'bufnr': bufnr('%'),
|
\ 'lnum': 1,
|
||||||
\ 'vcol': 0,
|
\ 'bufnr': bufnr('%'),
|
||||||
\ 'linter_name': 'eslint',
|
\ 'vcol': 0,
|
||||||
\ 'nr': -1,
|
\ 'linter_name': 'eslint',
|
||||||
\ 'type': 'E',
|
\ 'nr': -1,
|
||||||
\ 'col': 10,
|
\ 'type': 'E',
|
||||||
\ 'text': 'Missing semicolon. (semi)'
|
\ 'col': 10,
|
||||||
\ },
|
\ 'text': 'Missing semicolon. (semi)'
|
||||||
\ {
|
\ },
|
||||||
|
\ {
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
\ 'bufnr': bufnr('%'),
|
\ 'bufnr': bufnr('%'),
|
||||||
\ 'vcol': 0,
|
\ 'vcol': 0,
|
||||||
|
@ -20,8 +21,8 @@ Before:
|
||||||
\ 'type': 'W',
|
\ 'type': 'W',
|
||||||
\ 'col': 10,
|
\ 'col': 10,
|
||||||
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
|
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
\ 'bufnr': bufnr('%'),
|
\ 'bufnr': bufnr('%'),
|
||||||
\ 'vcol': 0,
|
\ 'vcol': 0,
|
||||||
|
@ -30,14 +31,15 @@ Before:
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ 'col': 15,
|
\ 'col': 15,
|
||||||
\ 'text': 'Missing radix parameter (radix)'
|
\ 'text': 'Missing radix parameter (radix)'
|
||||||
\ }
|
\ }
|
||||||
\ ],
|
\ ],
|
||||||
|
\ },
|
||||||
\}
|
\}
|
||||||
|
|
||||||
After:
|
After:
|
||||||
unlet! g:output
|
unlet! g:output
|
||||||
unlet! g:lines
|
unlet! g:lines
|
||||||
let g:ale_buffer_loclist_map = {}
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
Given javascript(A Javscript file with warnings/errors):
|
Given javascript(A Javscript file with warnings/errors):
|
||||||
var x = 3
|
var x = 3
|
||||||
|
|
31
test/test_get_loclist.vader
Normal file
31
test/test_get_loclist.vader
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
Before:
|
||||||
|
let g:loclist = [
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'bufnr': bufnr('%'),
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'eslint',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'text': 'Missing semicolon. (semi)'
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 2,
|
||||||
|
\ 'bufnr': bufnr('%'),
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'eslint',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'text': 'Infix operators must be spaced. (space-infix-ops)'
|
||||||
|
\ },
|
||||||
|
\]
|
||||||
|
let g:ale_buffer_info = {'1': {'loclist': g:loclist}}
|
||||||
|
|
||||||
|
After:
|
||||||
|
unlet g:loclist
|
||||||
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
|
Execute(GetLoclist should return the loclist):
|
||||||
|
AssertEqual g:loclist, ale#engine#GetLoclist(1)
|
|
@ -26,7 +26,6 @@ Before:
|
||||||
|
|
||||||
After:
|
After:
|
||||||
sign unplace *
|
sign unplace *
|
||||||
let g:ale_buffer_loclist_map = {}
|
|
||||||
let g:ale_buffer_info = {}
|
let g:ale_buffer_info = {}
|
||||||
delfunction g:CollectSigns
|
delfunction g:CollectSigns
|
||||||
unlet g:actual_sign_list
|
unlet g:actual_sign_list
|
||||||
|
|
|
@ -3,15 +3,35 @@ Given javascript (Some JavaScript with problems):
|
||||||
var y = 3
|
var y = 3
|
||||||
|
|
||||||
Before:
|
Before:
|
||||||
let g:ale_buffer_loclist_map = {}
|
let g:expected_data = [
|
||||||
let g:expected_data = {bufnr('%'): [{'lnum': 1, 'bufnr': bufnr('%'), 'vcol': 0, 'linter_name': 'eslint', 'nr': -1, 'type': 'W', 'col': 10, 'text': 'Infix operators must be spaced. [Warning/space-infix-ops]'}, {'lnum': 2, 'bufnr': bufnr('%'), 'vcol': 0, 'linter_name': 'eslint', 'nr': -1, 'type': 'E', 'col': 10, 'text': 'Missing semicolon. [Error/semi]'}]}
|
\ {
|
||||||
|
\ 'lnum': 1,
|
||||||
|
\ 'bufnr': bufnr('%'),
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'eslint',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'W',
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'text': 'Infix operators must be spaced. [Warning/space-infix-ops]',
|
||||||
|
\ },
|
||||||
|
\ {
|
||||||
|
\ 'lnum': 2,
|
||||||
|
\ 'bufnr': bufnr('%'),
|
||||||
|
\ 'vcol': 0,
|
||||||
|
\ 'linter_name': 'eslint',
|
||||||
|
\ 'nr': -1,
|
||||||
|
\ 'type': 'E',
|
||||||
|
\ 'col': 10,
|
||||||
|
\ 'text': 'Missing semicolon. [Error/semi]',
|
||||||
|
\ }
|
||||||
|
\]
|
||||||
|
|
||||||
After:
|
After:
|
||||||
let g:ale_buffer_loclist_map = {}
|
|
||||||
unlet g:expected_data
|
unlet g:expected_data
|
||||||
|
|
||||||
Execute(The loclist should be updated after linting is done):
|
Execute(The loclist should be updated after linting is done):
|
||||||
call ale#Lint()
|
call ale#Lint()
|
||||||
call ale#engine#WaitForJobs(2000)
|
call ale#engine#WaitForJobs(2000)
|
||||||
|
|
||||||
AssertEqual g:expected_data, g:ale_buffer_loclist_map
|
AssertEqual ['' . bufnr('%')], keys(g:ale_buffer_info)
|
||||||
|
AssertEqual g:expected_data, g:ale_buffer_info[bufnr('%')].loclist
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
Before:
|
Before:
|
||||||
let g:ale_buffer_loclist_map = {}
|
|
||||||
let g:ale_statusline_format = ['%sE', '%sW', 'OKIE']
|
let g:ale_statusline_format = ['%sE', '%sW', 'OKIE']
|
||||||
|
|
||||||
After:
|
After:
|
||||||
let g:ale_buffer_loclist_map = {}
|
|
||||||
let g:ale_buffer_info = {}
|
let g:ale_buffer_info = {}
|
||||||
|
|
||||||
Execute (Count should be 0 when data is empty):
|
Execute (Count should be 0 when data is empty):
|
||||||
|
@ -20,19 +18,22 @@ Execute (The count should be correct after an update):
|
||||||
AssertEqual [0, 0], ale#statusline#Count(44)
|
AssertEqual [0, 0], ale#statusline#Count(44)
|
||||||
|
|
||||||
Execute (Count should be match the loclist):
|
Execute (Count should be match the loclist):
|
||||||
let g:ale_buffer_info = {bufnr('%'): {}}
|
let g:ale_buffer_info = {
|
||||||
let g:ale_buffer_loclist_map = {bufnr('%'): [
|
\ bufnr('%'): {
|
||||||
\ {
|
\ 'loclist': [
|
||||||
\ 'lnum': 1,
|
\ {
|
||||||
\ 'bufnr': 1,
|
\ 'lnum': 1,
|
||||||
\ 'vcol': 0,
|
\ 'bufnr': 1,
|
||||||
\ 'linter_name': 'testlinter',
|
\ 'vcol': 0,
|
||||||
\ 'nr': -1,
|
\ 'linter_name': 'testlinter',
|
||||||
\ 'type': 'E',
|
\ 'nr': -1,
|
||||||
\ 'col': 1,
|
\ 'type': 'E',
|
||||||
\ 'text': 'Test Error',
|
\ 'col': 1,
|
||||||
\ },
|
\ 'text': 'Test Error',
|
||||||
\]}
|
\ },
|
||||||
|
\ ],
|
||||||
|
\ },
|
||||||
|
\}
|
||||||
AssertEqual [1, 0], ale#statusline#Count(bufnr('%'))
|
AssertEqual [1, 0], ale#statusline#Count(bufnr('%'))
|
||||||
|
|
||||||
Execute (Output should be empty for non-existant buffer):
|
Execute (Output should be empty for non-existant buffer):
|
||||||
|
|
Reference in a new issue