Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move cursor into floating hover when hover is already open
  • Loading branch information
rhysd committed Mar 21, 2019
commit 05afc80787a5da4daeb80a0da29cbc197f668121
24 changes: 20 additions & 4 deletions autoload/LanguageClient.vim
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function! s:GetVar(...) abort
endif
endfunction

function! s:CloseFloatingHoverAfterCursorMove(win_id, opened) abort
function! s:CloseFloatingHoverOnCursorMove(win_id, opened) abort
if getpos('.') == a:opened
" Just after opening floating window, CursorMoved event is run.
" To avoid closing floating window immediately, check the cursor
Expand All @@ -277,7 +277,7 @@ function! s:CloseFloatingHoverAfterCursorMove(win_id, opened) abort
execute winnr . 'wincmd c'
endfunction

function! s:CloseFloatingHoverAfterEnterAnotherBuf(win_id, bufnr) abort
function! s:CloseFloatingHoverOnBufEnter(win_id, bufnr) abort
let winnr = win_id2win(a:win_id)
if winnr == 0
" Float window was already closed
Expand Down Expand Up @@ -374,15 +374,28 @@ function! s:OpenHoverPreview(bufname, lines, filetype) abort
if s:FLOAT_WINDOW_AVAILABLE
" Unlike preview window, :pclose does not close window. Instead, close
" hover window automatically when cursor is moved.
let call_after_move = printf('<SID>CloseFloatingHoverAfterCursorMove(%d, %s)', float_win_id, string(pos))
let call_on_bufenter = printf('<SID>CloseFloatingHoverAfterEnterAnotherBuf(%d, %d)', float_win_id, bufnr)
let call_after_move = printf('<SID>CloseFloatingHoverOnCursorMove(%d, %s)', float_win_id, string(pos))
let call_on_bufenter = printf('<SID>CloseFloatingHoverOnBufEnter(%d, %d)', float_win_id, bufnr)
augroup plugin-LC-neovim-close-hover
execute 'autocmd CursorMoved,CursorMovedI,InsertEnter <buffer> call ' . call_after_move
execute 'autocmd BufEnter * call ' . call_on_bufenter
augroup END
endif
endfunction

function! s:MoveIntoHoverPreview() abort
for bufnr in range(1, bufnr('$'))
if bufname(bufnr) ==# '__LanguageClient__'
let winnr = bufwinnr(bufnr)
if winnr != -1
execute winnr . 'wincmd w'
endif
return v:true
endif
endfor
return v:false
endfunction

let s:id = 1
let s:handlers = {}

Expand Down Expand Up @@ -651,6 +664,9 @@ function! LanguageClient#Notify(method, params) abort
endfunction

function! LanguageClient#textDocument_hover(...) abort
if s:FLOAT_WINDOW_AVAILABLE && s:MoveIntoHoverPreview()
return
endif
let l:Callback = get(a:000, 1, v:null)
let l:params = {
\ 'filename': LSP#filename(),
Expand Down