Skip to content

Commit

Permalink
Add LSClientShowHover
Browse files Browse the repository at this point in the history
Closes natebosch#24

- Add a utility method to show some lines acting like a preview window
- Add hook to call `textDocument/hover` and wrap it up in a command
  • Loading branch information
natebosch committed Jul 30, 2017
1 parent 0e755e2 commit dcd9280
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
recursion to a while loop.
- Add `LSClientDisable`, `LSClientEnable` to disable or re-enable the client
for the current filetype during a session.
- Add `LSClientShowHover` to display hover information in a preview window.

# 0.2.2

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,8 @@ the response will be ignored.

While the cursor is on any identifier call `LSClientFindReferences` to populate
the quickfix list with usage locations.

### Hover

While the cursor is on any identifier call `LSClientShowHover` to request hover
text and show it in a preview window.
16 changes: 16 additions & 0 deletions autoload/lsc/reference.vim
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,19 @@ function! s:goTo(file, line, character) abort
exec 'normal! '.a:line.'G'.a:character.'|'
endif
endfunction

function! lsc#reference#hover() abort
call lsc#file#flushChanges()
let params = s:TextDocumentPositionParams()
call lsc#server#call(&filetype, 'textDocument/hover',
\ params, function('<SID>showHover'))
endfunction

function! s:showHover(result) abort
if empty(a:result) || empty(a:result.contents)
echom 'No hover information'
return
endif
let lines = split(a:result.contents, "\n")
call lsc#util#displayAsPreview(lines)
endfunction
19 changes: 19 additions & 0 deletions autoload/lsc/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,22 @@ function! s:QuickFixFilename(item) abort
endif
return bufname(a:item.bufnr)
endfunction

" Populate a hidden buffer with [lines] and show it as a preview window.
function! lsc#util#displayAsPreview(lines) abort
let view = winsaveview()
let alternate=@#
silent! pclose
sp __lsc_preview__
execute 'resize '.min([len(a:lines), &previewheight])
set previewwindow
setlocal bufhidden=hide
setlocal nobuflisted
setlocal buftype=nofile
setlocal noswapfile
%d
call setline(1, a:lines)
execute "normal \<c-w>p"
call winrestview(view)
let @#=alternate
endfunction
1 change: 1 addition & 0 deletions plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif

command! LSClientGoToDefinition call lsc#reference#goToDefinition()
command! LSClientFindReferences call lsc#reference#findReferences()
command! LSClientShowHover call lsc#reference#hover()
command! LSClientRestartServer call <SID>IfEnabled('lsc#server#restart')
command! LSClientDisable call <SID>Disable()
command! LSClientEnable call <SID>Enable()
Expand Down

0 comments on commit dcd9280

Please sign in to comment.