summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-07 23:12:45 +0100
committerw0rp <devw0rp@gmail.com>2017-06-08 17:30:21 +0100
commit62862c334776e3138f5a5456ed41bb146969b2c2 (patch)
treef016f7d18db2f1dc6d6a864152b1221af7a86eee /autoload
parent8ce6d47ef6f2153b702f3f774910ad7747ced185 (diff)
downloadale-62862c334776e3138f5a5456ed41bb146969b2c2.zip
Experimental code for showing results as soon as each linter completes
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/engine.vim74
-rw-r--r--autoload/ale/list.vim27
-rw-r--r--autoload/ale/sign.vim54
3 files changed, 93 insertions, 62 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index 944aab3a..3049ab5b 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -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')
+
+ 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)
- " 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 = []
+ " 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')
diff --git a/autoload/ale/list.vim b/autoload/ale/list.vim
index f446bbac..75b4ef38 100644
--- a/autoload/ale/list.vim
+++ b/autoload/ale/list.vim
@@ -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
diff --git a/autoload/ale/sign.vim b/autoload/ale/sign.vim
index 687d5671..f4ebed8b 100644
--- a/autoload/ale/sign.vim
+++ b/autoload/ale/sign.vim
@@ -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)'))
+
+ call s:PlaceNewSigns(a:buffer, l:grouped_items, l:current_sign_offset)
+endfunction
- " 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
+function! ale#sign#RemoveDummySignIfNeeded(buffer) abort
+ if !g:ale_sign_column_always
execute 'sign unplace ' . g:ale_sign_offset . ' buffer=' . a:buffer
endif
endfunction