-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to use a popup menu for code actions (#1361)
For code actions, some people might find it more convenient to use a popup menu that shows up at the cursor position, instead of using the quickpick window at the bottom of the screen.
- Loading branch information
Showing
7 changed files
with
116 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
let s:Markdown = vital#lsp#import('VS.Vim.Syntax.Markdown') | ||
let s:Window = vital#lsp#import('VS.Vim.Window') | ||
|
||
function! lsp#internal#ui#popupmenu#open(opt) abort | ||
let l:Callback = remove(a:opt, 'callback') | ||
let l:items = remove(a:opt, 'items') | ||
|
||
let l:items_with_shortcuts= map(l:items, { | ||
\ idx, item -> ((idx < 9) ? '['.(idx+1).'] ' : '').item | ||
\ }) | ||
|
||
function! Filter(id, key) abort closure | ||
if a:key >= 1 && a:key <= len(l:items) | ||
call popup_close(a:id, a:key) | ||
elseif a:key ==# "\<C-j>" | ||
call win_execute(a:id, 'normal! j') | ||
elseif a:key ==# "\<C-k>" | ||
call win_execute(a:id, 'normal! k') | ||
else | ||
return popup_filter_menu(a:id, a:key) | ||
endif | ||
|
||
return v:true | ||
endfunction | ||
|
||
let l:popup_opt = extend({ | ||
\ 'callback': funcref('s:callback', [l:Callback]), | ||
\ 'filter': funcref('Filter'), | ||
\ }, a:opt) | ||
|
||
let l:winid = popup_menu(l:items_with_shortcuts, l:popup_opt) | ||
call s:Window.do(l:winid, { -> s:Markdown.apply() }) | ||
execute('doautocmd <nomodeline> User lsp_float_opened') | ||
endfunction | ||
|
||
function! s:callback(callback, id, selected) abort | ||
call a:callback(a:id, a:selected) | ||
execute('doautocmd <nomodeline> User lsp_float_closed') | ||
endfunction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters