From 66ff00c4204095e65d8547c86e94325b205365ea Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 27 Aug 2020 12:41:07 +0100 Subject: [PATCH] Fix #3316 - Repeat -relative for ALERepeatSelection --- autoload/ale/preview.vim | 29 ++++++++++++++++------------- test/test_find_references.vader | 22 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/autoload/ale/preview.vim b/autoload/ale/preview.vim index faf45cb0..8b94aa7a 100644 --- a/autoload/ale/preview.vim +++ b/autoload/ale/preview.vim @@ -1,14 +1,22 @@ " Author: w0rp " 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 diff --git a/test/test_find_references.vader b/test/test_find_references.vader index 9949362a..ca05f631 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -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: {}})