Fix #3316 - Repeat -relative for ALERepeatSelection

This commit is contained in:
w0rp 2020-08-27 12:41:07 +01:00
parent f5aa0e8457
commit 66ff00c420
No known key found for this signature in database
GPG key ID: 0FC1ECAA8C81CD83
2 changed files with 35 additions and 16 deletions

View file

@ -1,14 +1,22 @@
" Author: w0rp <devw0rp@gmail.com>
" Description: Preview windows for showing whatever information in.
if !has_key(s:, 'last_selection_list')
let s:last_selection_list = []
if !has_key(s:, 'last__list')
let s:last_list = []
endif
if !has_key(s:, 'last_selection_open_in')
let s:last_selection_open_in = 'current-buffer'
if !has_key(s:, 'last_options')
let s:last_options = {}
endif
function! ale#preview#SetLastSelection(item_list, options) abort
let s:last_list = a:item_list
let s:last_options = {
\ 'open_in': get(a:options, 'open_in', 'current-buffer'),
\ 'use_relative_paths': get(a:options, 'use_relative_paths', 0),
\}
endfunction
" Open a preview window and show some lines in it.
" A second argument can be passed as a Dictionary with options. They are...
"
@ -81,19 +89,14 @@ function! ale#preview#ShowSelection(item_list, ...) abort
let b:ale_preview_item_list = a:item_list
let b:ale_preview_item_open_in = get(l:options, 'open_in', 'current-buffer')
" Remove the last preview
let s:last_selection_list = b:ale_preview_item_list
let s:last_selection_open_in = b:ale_preview_item_open_in
" Remember preview state, so we can repeat it later.
call ale#preview#SetLastSelection(a:item_list, l:options)
endfunction
function! ale#preview#RepeatSelection() abort
if empty(s:last_selection_list)
return
if !empty(s:last_list)
call ale#preview#ShowSelection(s:last_list, s:last_options)
endif
call ale#preview#ShowSelection(s:last_selection_list, {
\ 'open_in': s:last_selection_open_in,
\})
endfunction
function! s:Open(open_in) abort

View file

@ -63,6 +63,8 @@ Before:
let g:preview_called = 1
let g:item_list = a:item_list
let g:options = a:options
call ale#preview#SetLastSelection(a:item_list, a:options)
endfunction
After:
@ -110,7 +112,16 @@ Given typescript(Some typescript file):
bazxyzxyzxyz
Execute(Results should be shown for tsserver responses):
call ale#references#SetMap({3: {}})
" We should remember these options when we repeat the selection.
call ale#references#SetMap(
\ {
\ 3: {
\ 'ignorethis': 'x',
\ 'open_in': 'tab',
\ 'use_relative_paths': 1,
\ }
\ }
\)
call ale#references#HandleTSServerResponse(1, {
\ 'command': 'references',
\ 'request_seq': 3,
@ -158,8 +169,7 @@ Execute(Results should be shown for tsserver responses):
AssertEqual {}, ale#references#GetMap()
" We should be able to repeat selections with ALERepeatSelection
let g:ale_item_list = []
let g:item_list = []
ALERepeatSelection
AssertEqual
@ -170,6 +180,12 @@ Execute(Results should be shown for tsserver responses):
\ ],
\ g:item_list
AssertEqual {}, ale#references#GetMap()
AssertEqual
\ {
\ 'open_in': 'tab',
\ 'use_relative_paths': 1,
\ },
\ g:options
Execute(The preview window should not be opened for empty tsserver responses):
call ale#references#SetMap({3: {}})