diff options
author | w0rp <w0rp@users.noreply.github.com> | 2016-10-13 15:02:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-13 15:02:58 +0100 |
commit | 86ee54e271955e3a7e72cc395f6f3b67c93b1c81 (patch) | |
tree | a82b9d58d287bee2936eb09b5427b39e096fe4d6 /autoload | |
parent | f4159ac7eeb3787574692a451bff9159b039d395 (diff) | |
parent | f74d4938d0642823bf4171eee830137f0b690105 (diff) | |
download | ale-86ee54e271955e3a7e72cc395f6f3b67c93b1c81.zip |
Merge pull request #97 from neersighted/statusline-count
Implement a more efficient statusbar
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/cleanup.vim | 8 | ||||
-rw-r--r-- | autoload/ale/engine.vim | 27 | ||||
-rw-r--r-- | autoload/ale/statusline.vim | 47 | ||||
-rw-r--r-- | autoload/ale/util.vim | 20 |
4 files changed, 64 insertions, 38 deletions
diff --git a/autoload/ale/cleanup.vim b/autoload/ale/cleanup.vim index 2f636eee..45eccb98 100644 --- a/autoload/ale/cleanup.vim +++ b/autoload/ale/cleanup.vim @@ -2,14 +2,18 @@ " Description: Utility functions related to cleaning state. function! ale#cleanup#Buffer(buffer) abort - if has_key(g:ale_buffer_should_reset_map, a:buffer) - call remove(g:ale_buffer_should_reset_map, a:buffer) + if has_key(g:ale_buffer_count_map, a:buffer) + call remove(g:ale_buffer_count_map, a:buffer) endif 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_should_reset_map, a:buffer) + call remove(g:ale_buffer_should_reset_map, a:buffer) + endif + if has_key(g:ale_buffer_sign_dummy_map, a:buffer) call remove(g:ale_buffer_sign_dummy_map, a:buffer) endif diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 7342a541..1d0ad3d5 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -98,7 +98,7 @@ function! s:HandleExit(job) abort " 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(g:ale_buffer_loclist_map[l:buffer], 'ale#util#LocItemCompare') + call sort(g:ale_buffer_loclist_map[l:buffer], 's:LocItemCompare') if g:ale_set_loclist call setloclist(0, g:ale_buffer_loclist_map[l:buffer]) @@ -108,6 +108,11 @@ function! s:HandleExit(job) abort call ale#sign#SetSigns(l:buffer, g:ale_buffer_loclist_map[l:buffer]) endif + if exists('*ale#statusline#Update') + " Don't load/run if not already loaded. + call ale#statusline#Update(l:buffer, g:ale_buffer_loclist_map[l:buffer]) + endif + " Mark line 200, column 17 with a squiggly line or something " matchadd('ALEError', '\%200l\%17v') endfunction @@ -136,6 +141,26 @@ function! s:FixLocList(buffer, loclist) abort endfor endfunction +function! s:LocItemCompare(left, right) abort + if a:left['lnum'] < a:right['lnum'] + return -1 + endif + + if a:left['lnum'] > a:right['lnum'] + return 1 + endif + + if a:left['col'] < a:right['col'] + return -1 + endif + + if a:left['col'] > a:right['col'] + return 1 + endif + + return 0 +endfunction + function! ale#engine#Invoke(buffer, linter) abort if has_key(a:linter, 'job') " Stop previous jobs for the same linter. diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim index 995fcd94..8a31bc39 100644 --- a/autoload/ale/statusline.vim +++ b/autoload/ale/statusline.vim @@ -1,20 +1,12 @@ " Author: KabbAmine <amine.kabb@gmail.com> " Description: Statusline related function(s) -function! ale#statusline#Status() abort - " Returns a formatted string that can be integrated in the - " statusline - - let l:buffer = bufnr('%') - let l:loclist = g:ale_buffer_loclist_map - - if !has_key(l:loclist, l:buffer) - return '' - endif - +" Update the buffer error/warning count with data from loclist. +function! ale#statusline#Update(buffer, loclist) abort let l:errors = 0 let l:warnings = 0 - for l:entry in l:loclist[l:buffer] + + for l:entry in a:loclist if l:entry.type ==# 'E' let l:errors += 1 else @@ -22,11 +14,36 @@ function! ale#statusline#Status() abort endif endfor - let l:errors = l:errors ? printf(g:ale_statusline_format[0], l:errors) : '' - let l:warnings = l:warnings ? printf(g:ale_statusline_format[1], l:warnings) : '' + let g:ale_buffer_count_map[a:buffer] = [l:errors, l:warnings] +endfunction + +" Returns a tuple of errors and warnings for use in third-party integrations. +function! ale#statusline#Count(buffer) abort + " Cache is cold, so manually ask for an update. + if !has_key(g:ale_buffer_count_map, a:buffer) + call ale#statusline#Update(a:buffer, get(g:ale_buffer_loclist_map, a:buffer, [])) + endif + + return g:ale_buffer_count_map[a:buffer] +endfunction + +" Returns a formatted string that can be integrated in the statusline. +function! ale#statusline#Status() abort + let l:buffer = bufnr('%') + + " Cache is cold, so manually ask for an update. + if !has_key(g:ale_buffer_count_map, l:buffer) + call ale#statusline#Update(l:buffer, get(g:ale_buffer_loclist_map, l:buffer, [])) + endif + + " Build strings based on user formatting preferences. + let l:errors = g:ale_buffer_count_map[l:buffer][0] ? + \ printf(g:ale_statusline_format[0], g:ale_buffer_count_map[l:buffer][0]) : '' + let l:warnings = g:ale_buffer_count_map[l:buffer][1] ? + \ printf(g:ale_statusline_format[1], g:ale_buffer_count_map[l:buffer][1]) : '' let l:no_errors = g:ale_statusline_format[2] - " Different formats if no errors or no warnings + " Different formats based on the combination of errors and warnings. if empty(l:errors) && empty(l:warnings) let l:res = l:no_errors elseif !empty(l:errors) && !empty(l:warnings) diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 17ce7c44..4217ac49 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -43,23 +43,3 @@ function! ale#util#GetFunction(string_or_ref) abort return a:string_or_ref endfunction - -function! ale#util#LocItemCompare(left, right) abort - if a:left['lnum'] < a:right['lnum'] - return -1 - endif - - if a:left['lnum'] > a:right['lnum'] - return 1 - endif - - if a:left['col'] < a:right['col'] - return -1 - endif - - if a:left['col'] > a:right['col'] - return 1 - endif - - return 0 -endfunction |