Skip to content

Commit e95e83a

Browse files
authored
Merge pull request #2202 from bhcleek/lsp/balloon
use gopls for balloons
2 parents d1d285a + 60b5ec1 commit e95e83a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

autoload/go/lsp.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,23 @@ function! s:completionErrorHandler(next, error) abort dict
437437
call call(a:next, [[]])
438438
endfunction
439439

440+
function! go#lsp#Hover(fname, line, col, handler)
441+
call go#lsp#DidChange(a:fname)
442+
443+
let l:lsp = s:lspfactory.get()
444+
let l:msg = go#lsp#message#Hover(a:fname, a:line, a:col)
445+
let l:state = s:newHandlerState('hover')
446+
let l:state.handleResult = funcref('s:hoverHandler', [function(a:handler, [], l:state)], l:state)
447+
call l:lsp.sendMessage(l:msg, l:state)
448+
endfunction
449+
450+
function! s:hoverHandler(next, msg) abort dict
451+
" gopls returns a MarkupContent.
452+
let l:content = substitute(a:msg.contents.value, '```go\n\(.*\)\n```', '\1', '')
453+
let l:args = [l:content]
454+
call call(a:next, l:args)
455+
endfunction
456+
440457
" restore Vi compatibility settings
441458
let &cpo = s:cpo_save
442459
unlet s:cpo_save

autoload/go/lsp/message.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ function! go#lsp#message#Completion(file, line, col)
100100
\ }
101101
endfunction
102102

103+
function! go#lsp#message#Hover(file, line, col)
104+
return {
105+
\ 'notification': 0,
106+
\ 'method': 'textDocument/hover',
107+
\ 'params': {
108+
\ 'textDocument': {
109+
\ 'uri': go#path#ToURI(a:file)
110+
\ },
111+
\ 'position': s:position(a:line, a:col),
112+
\ }
113+
\ }
114+
endfunction
115+
103116
function! s:position(line, col)
104117
return {'line': a:line - 1, 'character': a:col-1}
105118
endfunction

autoload/go/tool.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,18 @@ function! go#tool#Exists(importpath) abort
112112
endfunction
113113

114114
function! go#tool#DescribeBalloon()
115-
return go#guru#DescribeBalloon()
115+
let l:fname = fnamemodify(bufname(v:beval_bufnr), ':p')
116+
call go#lsp#Hover(l:fname, v:beval_lnum, v:beval_col, funcref('s:balloon', []))
117+
return ''
118+
endfunction
119+
120+
function! s:balloon(msg)
121+
if has('balloon_eval')
122+
call balloon_show(a:msg)
123+
return
124+
endif
125+
126+
call balloon_show(balloon_split(a:msg))
116127
endfunction
117128

118129
" restore Vi compatibility settings

0 commit comments

Comments
 (0)