summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorShaun Duncan <shaun.duncan@gmail.com>2022-08-23 07:22:52 -0400
committerGitHub <noreply@github.com>2022-08-23 20:22:52 +0900
commit6996d1c14dd109cc5112d1a60c86683e5308d14c (patch)
tree10e39b7a944f2096bebea6fc3c14dad060d18483 /autoload
parentd93bc2baf7532818e83bf2fac61fcd591beb6151 (diff)
downloadale-6996d1c14dd109cc5112d1a60c86683e5308d14c.zip
Allow callbacks for floating preview popups (#4247)
* Add extra config options for virtualtext * Undo virtualtext changes and move to floating preview * revert changes to pass hightlight group to floating preview * rename var * Document changes * Add updates based on feedback * Check for string type and attempt to call the function * Fix lint errors Co-authored-by: Shaun Duncan <shaun@speedscale.com>
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/floating_preview.vim45
1 files changed, 35 insertions, 10 deletions
diff --git a/autoload/ale/floating_preview.vim b/autoload/ale/floating_preview.vim
index 1063a2db..b6deec4c 100644
--- a/autoload/ale/floating_preview.vim
+++ b/autoload/ale/floating_preview.vim
@@ -1,6 +1,7 @@
" Author: Jan-Grimo Sobez <jan-grimo.sobez@phys.chem.ethz.ch>
" Author: Kevin Clark <kevin.clark@gmail.com>
" Author: D. Ben Knoble <ben.knoble+github@gmail.com>
+" Author: Shaun Duncan <shaun.duncan@gmail.com>
" Description: Floating preview window for showing whatever information in.
" Precondition: exists('*nvim_open_win') || has('popupwin')
@@ -133,15 +134,18 @@ function! s:NvimPrepareWindowContent(lines) abort
endfunction
function! s:NvimCreate(options) abort
+ let l:popup_opts = extend({
+ \ 'relative': 'cursor',
+ \ 'row': 1,
+ \ 'col': 0,
+ \ 'width': 42,
+ \ 'height': 4,
+ \ 'style': 'minimal'
+ \ }, s:GetPopupOpts())
+
let l:buffer = nvim_create_buf(v:false, v:false)
- let l:winid = nvim_open_win(l:buffer, v:false, {
- \ 'relative': 'cursor',
- \ 'row': 1,
- \ 'col': 0,
- \ 'width': 42,
- \ 'height': 4,
- \ 'style': 'minimal'
- \ })
+ let l:winid = nvim_open_win(l:buffer, v:false, l:popup_opts)
+
call nvim_buf_set_option(l:buffer, 'buftype', 'acwrite')
call nvim_buf_set_option(l:buffer, 'bufhidden', 'delete')
call nvim_buf_set_option(l:buffer, 'swapfile', v:false)
@@ -151,7 +155,8 @@ function! s:NvimCreate(options) abort
endfunction
function! s:VimCreate(options) abort
- let l:popup_id = popup_create([], {
+ " default options
+ let l:popup_opts = extend({
\ 'line': 'cursor+1',
\ 'col': 'cursor',
\ 'drag': v:true,
@@ -170,7 +175,9 @@ function! s:VimCreate(options) abort
\ get(g:ale_floating_window_border, 5, '+'),
\ ],
\ 'moved': 'any',
- \ })
+ \ }, s:GetPopupOpts())
+
+ let l:popup_id = popup_create([], l:popup_opts)
call setbufvar(winbufnr(l:popup_id), '&filetype', get(a:options, 'filetype', 'ale-preview'))
let w:preview = {'id': l:popup_id}
endfunction
@@ -204,3 +211,21 @@ function! s:VimClose() abort
call popup_close(w:preview['id'])
unlet w:preview
endfunction
+
+" get either the results of a function callback or dictionary for popup overrides
+function! s:GetPopupOpts() abort
+ if exists('g:ale_floating_preview_popup_opts')
+ let l:ref = g:ale_floating_preview_popup_opts
+
+ if type(l:ref) is# v:t_dict
+ return l:ref
+ elseif type(l:ref) is# v:t_string
+ try
+ return function(l:ref)()
+ catch /E700/
+ endtry
+ endif
+ endif
+
+ return {}
+endfunction