Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use gopls for balloons #2202

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,23 @@ function! s:completionErrorHandler(next, error) abort dict
call call(a:next, [[]])
endfunction

function! go#lsp#Hover(fname, line, col, handler)
call go#lsp#DidChange(a:fname)

let l:lsp = s:lspfactory.get()
let l:msg = go#lsp#message#Hover(a:fname, a:line, a:col)
let l:state = s:newHandlerState('hover')
let l:state.handleResult = funcref('s:hoverHandler', [function(a:handler, [], l:state)], l:state)
call l:lsp.sendMessage(l:msg, l:state)
endfunction

function! s:hoverHandler(next, msg) abort dict
" gopls returns a MarkupContent.
let l:content = substitute(a:msg.contents.value, '```go\n\(.*\)\n```', '\1', '')
let l:args = [l:content]
call call(a:next, l:args)
endfunction

" restore Vi compatibility settings
let &cpo = s:cpo_save
unlet s:cpo_save
Expand Down
13 changes: 13 additions & 0 deletions autoload/go/lsp/message.vim
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ function! go#lsp#message#Completion(file, line, col)
\ }
endfunction

function! go#lsp#message#Hover(file, line, col)
return {
\ 'notification': 0,
\ 'method': 'textDocument/hover',
\ 'params': {
\ 'textDocument': {
\ 'uri': go#path#ToURI(a:file)
\ },
\ 'position': s:position(a:line, a:col),
\ }
\ }
endfunction

function! s:position(line, col)
return {'line': a:line - 1, 'character': a:col-1}
endfunction
Expand Down
13 changes: 12 additions & 1 deletion autoload/go/tool.vim
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ function! go#tool#Exists(importpath) abort
endfunction

function! go#tool#DescribeBalloon()
return go#guru#DescribeBalloon()
let l:fname = fnamemodify(bufname(v:beval_bufnr), ':p')
call go#lsp#Hover(l:fname, v:beval_lnum, v:beval_col, funcref('s:balloon', []))
return ''
endfunction

function! s:balloon(msg)
if has('balloon_eval')
call balloon_show(a:msg)
return
endif

call balloon_show(balloon_split(a:msg))
endfunction

" restore Vi compatibility settings
Expand Down