summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorThéo Cavignac <theo.cavignac@ecl16.ec-lyon.fr>2019-02-10 12:11:29 +0100
committerw0rp <w0rp@users.noreply.github.com>2019-02-10 11:11:29 +0000
commitd072d2654c68d1c0bf4a1cb8c15c31e989652669 (patch)
tree42747f3962720331f24cfabb5fa5c38abd203fd7 /autoload
parenta24f0b4d5f91f9214c64ae281fadcd981e0dadfc (diff)
downloadale-d072d2654c68d1c0bf4a1cb8c15c31e989652669.zip
Supporting filtered jump (#2279)
* Support filtered jump based on loclist item type (E or W for now) * Use flags to customize the behavior of ALENext and ALEPrevious * Update <plug> bindings with flags * Update documentation about ALENext and ALEPrevious * Use ale#args#Parse in JumpWrap
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/loclist_jumping.vim94
1 files changed, 82 insertions, 12 deletions
diff --git a/autoload/ale/loclist_jumping.vim b/autoload/ale/loclist_jumping.vim
index fd5ff922..c56f1a7a 100644
--- a/autoload/ale/loclist_jumping.vim
+++ b/autoload/ale/loclist_jumping.vim
@@ -9,7 +9,7 @@
" If there are no items or we have hit the end with wrapping off, an empty
" List will be returned, otherwise a pair of [line_number, column_number] will
" be returned.
-function! ale#loclist_jumping#FindNearest(direction, wrap) abort
+function! ale#loclist_jumping#FindNearest(direction, wrap, ...) abort
let l:buffer = bufnr('')
let l:pos = getcurpos()
let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []})
@@ -17,6 +17,18 @@ function! ale#loclist_jumping#FindNearest(direction, wrap) abort
let l:loclist = filter(copy(l:info.loclist), 'v:val.bufnr == l:buffer')
let l:search_item = {'bufnr': l:buffer, 'lnum': l:pos[1], 'col': l:pos[2]}
+ if a:0 > 0
+ let l:filter = a:1
+ else
+ let l:filter = 'any'
+ endif
+
+ if a:0 > 1
+ let l:subtype_filter = a:2
+ else
+ let l:subtype_filter = 'any'
+ endif
+
" When searching backwards, so we can find the next smallest match.
if a:direction is# 'before'
call reverse(l:loclist)
@@ -41,29 +53,57 @@ function! ale#loclist_jumping#FindNearest(direction, wrap) abort
\ l:search_item
\)
- if a:direction is# 'before' && l:cmp_value < 0
- return [l:item.lnum, l:item.col]
- endif
+ if (l:filter is# 'any' || l:filter is# l:item.type) &&
+ \ (l:subtype_filter is# 'any' ||
+ \ l:subtype_filter is# get(l:item, 'sub_type', ''))
+
+ if a:direction is# 'before' && l:cmp_value < 0
+ return [l:item.lnum, l:item.col]
+ endif
- if a:direction is# 'after' && l:cmp_value > 0
- return [l:item.lnum, l:item.col]
+ if a:direction is# 'after' && l:cmp_value > 0
+ return [l:item.lnum, l:item.col]
+ endif
endif
endfor
" If we found nothing, and the wrap option is set to 1, then we should
" wrap around the list of warnings/errors
- if a:wrap && !empty(l:loclist)
- let l:item = l:loclist[0]
-
- return [l:item.lnum, l:item.col]
+ if a:wrap
+ for l:item in l:loclist
+ if (l:filter is# 'any' || l:filter is# l:item.type) &&
+ \ (l:subtype_filter is# 'any' ||
+ \ l:subtype_filter is# get(l:item, 'sub_type', ''))
+ return [l:item.lnum, l:item.col]
+ endif
+ endfor
endif
return []
endfunction
" As before, find the nearest match, but position the cursor at it.
-function! ale#loclist_jumping#Jump(direction, wrap) abort
- let l:nearest = ale#loclist_jumping#FindNearest(a:direction, a:wrap)
+function! ale#loclist_jumping#Jump(direction, ...) abort
+ if a:0 > 0
+ let l:wrap = a:1
+ else
+ let l:wrap = 0
+ endif
+
+ if a:0 > 1
+ let l:filter = a:2
+ else
+ let l:filter = 'any'
+ endif
+
+ if a:0 > 2
+ let l:subtype_filter = a:3
+ else
+ let l:subtype_filter = 'any'
+ endif
+
+ let l:nearest = ale#loclist_jumping#FindNearest(a:direction,
+ \ l:wrap, l:filter, l:subtype_filter)
if !empty(l:nearest)
normal! m`
@@ -71,6 +111,36 @@ function! ale#loclist_jumping#Jump(direction, wrap) abort
endif
endfunction
+function! ale#loclist_jumping#WrapJump(direction, sargs) abort
+ let [l:args, l:rest] = ale#args#Parse(['error', 'warning', 'info', 'wrap',
+ \ 'style', 'nostyle'], a:sargs)
+
+ let l:wrap = 0
+ let l:type_filter = 'any'
+ let l:subtype_filter = 'any'
+
+ if get(l:args, 'wrap', 'nil') is# ''
+ let l:wrap = 1
+ endif
+
+ if get(l:args, 'error', 'nil') is# ''
+ let l:type_filter = 'E'
+ elseif get(l:args, 'warning', 'nil') is# ''
+ let l:type_filter = 'W'
+ elseif get(l:args, 'info', 'nil') is# ''
+ let l:type_filter = 'I'
+ endif
+
+ if get(l:args, 'nostyle', 'nil') is# ''
+ let l:subtype_filter = 'style'
+ elseif get(l:args, 'style', 'nil') is# ''
+ let l:subtype_filter = ''
+ endif
+
+ call ale#loclist_jumping#Jump(a:direction, l:wrap, l:type_filter,
+ \ l:subtype_filter)
+endfunction
+
function! ale#loclist_jumping#JumpToIndex(index) abort
let l:buffer = bufnr('')
let l:info = get(g:ale_buffer_info, l:buffer, {'loclist': []})