mirror of
https://github.com/dense-analysis/ale.git
synced 2026-02-07 02:11:05 +08:00
Experimental code for showing results as soon as each linter completes
This commit is contained in:
@@ -33,17 +33,12 @@ function! ale#engine#InitBufferInfo(buffer) abort
|
||||
if !has_key(g:ale_buffer_info, a:buffer)
|
||||
" job_list will hold the list of jobs
|
||||
" loclist holds the loclist items after all jobs have completed.
|
||||
" lint_file_loclist holds items from the last run including linters
|
||||
" which use the lint_file option.
|
||||
" new_loclist holds loclist items while jobs are being run.
|
||||
" temporary_file_list holds temporary files to be cleaned up
|
||||
" temporary_directory_list holds temporary directories to be cleaned up
|
||||
" history holds a list of previously run commands for this buffer
|
||||
let g:ale_buffer_info[a:buffer] = {
|
||||
\ 'job_list': [],
|
||||
\ 'loclist': [],
|
||||
\ 'lint_file_loclist': [],
|
||||
\ 'new_loclist': [],
|
||||
\ 'temporary_file_list': [],
|
||||
\ 'temporary_directory_list': [],
|
||||
\ 'history': [],
|
||||
@@ -154,53 +149,66 @@ function! s:HandleExit(job_id, exit_code) abort
|
||||
" to set default values for loclist items.
|
||||
let l:linter_loclist = ale#engine#FixLocList(l:buffer, l:linter, l:linter_loclist)
|
||||
|
||||
" Add the loclist items from the linter.
|
||||
" loclist items for files which are checked go into a different list,
|
||||
" and are kept between runs.
|
||||
if l:linter.lint_file
|
||||
call extend(g:ale_buffer_info[l:buffer].lint_file_loclist, l:linter_loclist)
|
||||
else
|
||||
call extend(g:ale_buffer_info[l:buffer].new_loclist, l:linter_loclist)
|
||||
endif
|
||||
|
||||
if !empty(g:ale_buffer_info[l:buffer].job_list)
|
||||
" Wait for all jobs to complete before doing anything else.
|
||||
return
|
||||
endif
|
||||
|
||||
" Automatically remove all managed temporary files and directories
|
||||
" now that all jobs have completed.
|
||||
call ale#engine#RemoveManagedFiles(l:buffer)
|
||||
|
||||
" Combine the lint_file List and the List for everything else.
|
||||
let l:combined_list = g:ale_buffer_info[l:buffer].lint_file_loclist
|
||||
\ + g:ale_buffer_info[l:buffer].new_loclist
|
||||
" Remove previous items for this linter.
|
||||
call filter(g:ale_buffer_info[l:buffer].loclist, 'v:val.linter_name !=# l:linter.name')
|
||||
" Add the new items.
|
||||
call extend(g:ale_buffer_info[l:buffer].loclist, l:linter_loclist)
|
||||
|
||||
" Sort the loclist again.
|
||||
" We need a sorted list so we can run a binary search against it
|
||||
" for efficient lookup of the messages in the cursor handler.
|
||||
call sort(l:combined_list, 'ale#util#LocItemCompare')
|
||||
call sort(g:ale_buffer_info[l:buffer].loclist, 'ale#util#LocItemCompare')
|
||||
|
||||
" Now swap the old and new loclists, after we have collected everything
|
||||
" and sorted the list again.
|
||||
let g:ale_buffer_info[l:buffer].loclist = l:combined_list
|
||||
let g:ale_buffer_info[l:buffer].new_loclist = []
|
||||
let l:linting_is_done = empty(g:ale_buffer_info[l:buffer].job_list)
|
||||
|
||||
if l:linting_is_done
|
||||
" Automatically remove all managed temporary files and directories
|
||||
" now that all jobs have completed.
|
||||
call ale#engine#RemoveManagedFiles(l:buffer)
|
||||
|
||||
" Figure out which linters are still enabled, and remove
|
||||
" problems for linters which are no longer enabled.
|
||||
let l:name_map = {}
|
||||
|
||||
for l:linter in ale#linter#Get(getbufvar(l:buffer, '&filetype'))
|
||||
let l:name_map[l:linter.name] = 1
|
||||
endfor
|
||||
|
||||
call filter(
|
||||
\ g:ale_buffer_info[l:buffer].loclist,
|
||||
\ 'get(l:name_map, v:val.linter_name)',
|
||||
\)
|
||||
endif
|
||||
|
||||
call ale#engine#SetResults(l:buffer, g:ale_buffer_info[l:buffer].loclist)
|
||||
|
||||
" Call user autocommands. This allows users to hook into ALE's lint cycle.
|
||||
silent doautocmd User ALELint
|
||||
if l:linting_is_done
|
||||
" Call user autocommands. This allows users to hook into ALE's lint cycle.
|
||||
silent doautocmd User ALELint
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#engine#SetResults(buffer, loclist) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
let l:job_list = get(l:info, 'job_list', [])
|
||||
let l:linting_is_done = empty(l:job_list)
|
||||
|
||||
" Set signs first. This could potentially fix some line numbers.
|
||||
" The List could be sorted again here by SetSigns.
|
||||
if g:ale_set_signs
|
||||
call ale#sign#SetSigns(a:buffer, a:loclist)
|
||||
|
||||
if l:linting_is_done
|
||||
call ale#sign#RemoveDummySignIfNeeded(a:buffer)
|
||||
endif
|
||||
endif
|
||||
|
||||
if g:ale_set_quickfix || g:ale_set_loclist
|
||||
call ale#list#SetLists(a:buffer, a:loclist)
|
||||
|
||||
if l:linting_is_done
|
||||
call ale#list#CloseWindowIfNeeded(a:buffer)
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('*ale#statusline#Update')
|
||||
|
||||
@@ -35,13 +35,8 @@ function! ale#list#SetLists(buffer, loclist) abort
|
||||
endif
|
||||
endif
|
||||
|
||||
" If we don't auto-open lists, bail out here.
|
||||
if !g:ale_open_list && !g:ale_keep_list_window_open
|
||||
return
|
||||
endif
|
||||
|
||||
" If we have errors in our list, open the list. Only if it isn't already open
|
||||
if len(a:loclist) > 0 || g:ale_keep_list_window_open
|
||||
if (g:ale_open_list && !empty(a:loclist)) || g:ale_keep_list_window_open
|
||||
let l:winnr = winnr()
|
||||
|
||||
if g:ale_set_quickfix
|
||||
@@ -56,13 +51,21 @@ function! ale#list#SetLists(buffer, loclist) abort
|
||||
if l:winnr !=# winnr()
|
||||
wincmd p
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Only close if the list is totally empty (relying on Vim's state, not our
|
||||
" own). This keeps us from closing the window when other plugins have
|
||||
" populated it.
|
||||
elseif !g:ale_keep_list_window_open && g:ale_set_quickfix && len(getqflist()) == 0
|
||||
cclose
|
||||
elseif !g:ale_keep_list_window_open && len(getloclist(0)) == 0
|
||||
function! ale#list#CloseWindowIfNeeded(buffer) abort
|
||||
if g:ale_keep_list_window_open || !g:ale_open_list
|
||||
return
|
||||
endif
|
||||
|
||||
" Only close windows if the quickfix list or loclist is completely empty,
|
||||
" including errors set through other means.
|
||||
if g:ale_set_quickfix
|
||||
if empty(getqflist())
|
||||
cclose
|
||||
endif
|
||||
elseif g:ale_set_loclist && empty(getloclist(0))
|
||||
lclose
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -118,7 +118,20 @@ function! s:GroupLoclistItems(loclist) abort
|
||||
let l:last_lnum = l:obj.lnum
|
||||
endfor
|
||||
|
||||
return l:grouped_items
|
||||
" Now we've gathered the items in groups, filter the groups down to
|
||||
" the groups containing at least one new item.
|
||||
let l:new_grouped_items = []
|
||||
|
||||
for l:group in l:grouped_items
|
||||
for l:obj in l:group
|
||||
if !has_key(l:obj, 'sign_id')
|
||||
call add(l:new_grouped_items, l:group)
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
|
||||
return l:new_grouped_items
|
||||
endfunction
|
||||
|
||||
function! s:IsDummySignSet(current_id_list) abort
|
||||
@@ -189,14 +202,18 @@ function! ale#sign#SetSignColumnHighlight(has_problems) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:PlaceNewSigns(buffer, grouped_items) abort
|
||||
function! s:PlaceNewSigns(buffer, grouped_items, current_sign_offset) abort
|
||||
if g:ale_change_sign_column_color
|
||||
call ale#sign#SetSignColumnHighlight(!empty(a:grouped_items))
|
||||
endif
|
||||
|
||||
let l:offset = a:current_sign_offset > 0
|
||||
\ ? a:current_sign_offset
|
||||
\ : g:ale_sign_offset
|
||||
|
||||
" Add the new signs,
|
||||
for l:index in range(0, len(a:grouped_items) - 1)
|
||||
let l:sign_id = l:index + g:ale_sign_offset + 1
|
||||
let l:sign_id = l:offset + l:index + 1
|
||||
let l:sublist = a:grouped_items[l:index]
|
||||
let l:type = ale#sign#GetSignType(a:grouped_items[l:index])
|
||||
|
||||
@@ -232,22 +249,17 @@ endfunction
|
||||
|
||||
" Given some current signs and a loclist, look for items with sign IDs,
|
||||
" and change the line numbers for loclist items to match the signs.
|
||||
function! s:UpdateLineNumbers(current_sign_list, loclist) abort
|
||||
let l:items_by_sign_id = s:GetItemsWithSignIDs(a:loclist)
|
||||
|
||||
function! s:UpdateLineNumbers(current_sign_list, items_by_sign_id) abort
|
||||
" Do nothing if there's nothing to work with.
|
||||
if empty(l:items_by_sign_id)
|
||||
if empty(a:items_by_sign_id)
|
||||
return
|
||||
endif
|
||||
|
||||
for [l:line, l:sign_id, l:name] in a:current_sign_list
|
||||
for l:obj in get(l:items_by_sign_id, l:sign_id, [])
|
||||
for l:obj in get(a:items_by_sign_id, l:sign_id, [])
|
||||
let l:obj.lnum = l:line
|
||||
endfor
|
||||
endfor
|
||||
|
||||
" Sort items again.
|
||||
call sort(a:loclist, 'ale#util#LocItemCompare')
|
||||
endfunction
|
||||
|
||||
" This function will set the signs which show up on the left.
|
||||
@@ -260,8 +272,13 @@ function! ale#sign#SetSigns(buffer, loclist) abort
|
||||
|
||||
" Find the current markers
|
||||
let l:current_sign_list = ale#sign#FindCurrentSigns(a:buffer)
|
||||
" Get a mapping from sign IDs to current loclist items which have them.
|
||||
let l:items_by_sign_id = s:GetItemsWithSignIDs(a:loclist)
|
||||
|
||||
call s:UpdateLineNumbers(l:current_sign_list, a:loclist)
|
||||
" Use sign information to update the line numbers for the loclist items.
|
||||
call s:UpdateLineNumbers(l:current_sign_list, l:items_by_sign_id)
|
||||
" Sort items again, as the line numbers could have changed.
|
||||
call sort(a:loclist, 'ale#util#LocItemCompare')
|
||||
|
||||
let l:grouped_items = s:GroupLoclistItems(a:loclist)
|
||||
|
||||
@@ -277,16 +294,19 @@ function! ale#sign#SetSigns(buffer, loclist) abort
|
||||
" while we add the new signs, if we had signs before.
|
||||
for [l:line, l:sign_id, l:name] in l:current_sign_list
|
||||
if l:sign_id != g:ale_sign_offset
|
||||
\&& !has_key(l:items_by_sign_id, l:sign_id)
|
||||
exec 'sign unplace ' . l:sign_id . ' buffer=' . a:buffer
|
||||
endif
|
||||
endfor
|
||||
|
||||
call s:PlaceNewSigns(a:buffer, l:grouped_items)
|
||||
" Compute a sign ID offset so we don't hit the same sign IDs again.
|
||||
let l:current_sign_offset = max(map(keys(l:items_by_sign_id), 'str2nr(v:val)'))
|
||||
|
||||
" Remove the dummy sign now we've updated the signs, unless we want
|
||||
" to keep it, which will keep the sign column open even when there are
|
||||
" no warnings or errors.
|
||||
if l:is_dummy_sign_set && !g:ale_sign_column_always
|
||||
call s:PlaceNewSigns(a:buffer, l:grouped_items, l:current_sign_offset)
|
||||
endfunction
|
||||
|
||||
function! ale#sign#RemoveDummySignIfNeeded(buffer) abort
|
||||
if !g:ale_sign_column_always
|
||||
execute 'sign unplace ' . g:ale_sign_offset . ' buffer=' . a:buffer
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user