@@ -8,7 +8,8 @@ let s:TYPE = {
88\ ' dict' : type ({}),
99\ ' funcref' : type (function (' call' ))
1010\ }
11- let s: FLOAT_WINDOW_AVAILABLE = has (' nvim' ) && exists (' *nvim_open_win' )
11+ let s: FLOAT_WINDOW_AVAILABLE = exists (' *nvim_open_win' )
12+ let s: POPUP_WINDOW_AVAILABLE = exists (' *popup_atcursor' )
1213
1314function ! s: AddPrefix (message) abort
1415 return ' [LC] ' . a: message
@@ -268,8 +269,8 @@ function! s:GetVar(...) abort
268269endfunction
269270
270271function ! s: ShouldUseFloatWindow () abort
271- let use = s: GetVar (' LanguageClient_useFloatingHover' )
272- return s: FLOAT_WINDOW_AVAILABLE && (use || use is v: null )
272+ let floatingHoverEnabled = s: GetVar (' LanguageClient_useFloatingHover' , v: true )
273+ return s: FLOAT_WINDOW_AVAILABLE && floatingHoverEnabled
273274endfunction
274275
275276function ! s: CloseFloatingHover () abort
@@ -321,14 +322,23 @@ endfunction
321322
322323" Open preview window. Window is open in:
323324" - Floating window on Neovim (0.4.0 or later)
325+ " - popup window on vim (8.2 or later)
324326" - Preview window on Neovim (0.3.0 or earlier) or Vim
325327function ! s: OpenHoverPreview (bufname , lines , filetype ) abort
326328 " Use local variable since parameter is not modifiable
327329 let lines = a: lines
328330 let bufnr = bufnr (' %' )
329331
330- let use_float_win = s: ShouldUseFloatWindow ()
331- if use_float_win
332+ let display_approach = ' '
333+ if s: ShouldUseFloatWindow ()
334+ let display_approach = ' float_win'
335+ elseif s: POPUP_WINDOW_AVAILABLE && s: GetVar (' LanguageClient_usePopupHover' , v: true )
336+ let display_approach = ' popup_win'
337+ else
338+ let display_approach = ' preview'
339+ endif
340+
341+ if display_approach == # ' float_win'
332342 " When a language server takes a while to initialize and the user
333343 " calls hover multiple times during that time (for example, via an
334344 " automatic hover on cursor move setup), we will get a number of
@@ -391,23 +401,30 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort
391401 execute ' noswapfile edit!' a: bufname
392402
393403 setlocal winhl= Normal :CursorLine
394- else
404+ elseif display_approach == # ' popup_win'
405+ let pop_win_id = popup_atcursor (a: lines , {})
406+ call setbufvar (winbufnr (pop_win_id), ' &filetype' , a: filetype )
407+ elseif display_approach == # ' preview'
395408 execute ' silent! noswapfile pedit!' a: bufname
396409 wincmd P
410+ else
411+ call s: Echoerr (' Unknown display approach: ' . display_approach)
397412 endif
398413
399- setlocal buftype = nofile nobuflisted bufhidden = wipe nonumber norelativenumber signcolumn = no modifiable
414+ if display_approach !=# ' popup_win'
415+ setlocal buftype = nofile nobuflisted bufhidden = wipe nonumber norelativenumber signcolumn = no modifiable
400416
401- if a: filetype isnot v: null
402- let &filetype = a: filetype
403- endif
417+ if a: filetype isnot v: null
418+ let &filetype = a: filetype
419+ endif
404420
405- call setline (1 , lines )
406- setlocal nomodified nomodifiable
421+ call setline (1 , lines )
422+ setlocal nomodified nomodifiable
407423
408- wincmd p
424+ wincmd p
425+ endif
409426
410- if use_float_win
427+ if display_approach == # ' float_win '
411428 " Unlike preview window, :pclose does not close window. Instead, close
412429 " hover window automatically when cursor is moved.
413430 let call_after_move = printf (' <SID>CloseFloatingHoverOnCursorMove(%s)' , string (pos))
0 commit comments