Skip to content

Commit

Permalink
support g:go_info_mode='gopls' in go#complete#GetInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
bhcleek committed May 27, 2019
1 parent 8ca22ee commit 03febea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
7 changes: 6 additions & 1 deletion autoload/go/complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ endfunction
" go#complete#GoInfo returns the description of the identifier under the
" cursor.
function! go#complete#GetInfo() abort
return s:sync_info(0)
let l:mode = go#config#InfoMode()
if l:mode == 'gopls' && go#util#has_job()
return go#lsp#GetInfo()
else
return s:sync_info(0)
endif
endfunction

function! go#complete#Info(showstatus) abort
Expand Down
6 changes: 6 additions & 0 deletions autoload/go/complete_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ func! Test_GetInfo_guru()
unlet g:go_info_mode
endfunction

func! Test_GetInfo_gopls()
let g:go_info_mode = 'gopls'
call s:getinfo()
unlet g:go_info_mode
endfunction

func! s:getinfo()
let l:filename = 'complete/complete.go'
let l:tmp = gotest#load_fixture(l:filename)
Expand Down
40 changes: 35 additions & 5 deletions autoload/go/lsp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,32 @@ function! go#lsp#Info(showstatus)
let l:state = s:newHandlerState('')
endif

let l:state.handleResult = funcref('s:infoDefinitionHandler', [a:showstatus], l:state)
let l:state.handleResult = funcref('s:infoDefinitionHandler', [function('s:info', [1], l:state), a:showstatus], l:state)
let l:state.error = funcref('s:noop')
let l:msg = go#lsp#message#Definition(l:fname, l:line, l:col)
return l:lsp.sendMessage(l:msg, l:state)
endfunction

function! s:infoDefinitionHandler(showstatus, msg) abort dict
function! go#lsp#GetInfo()
let l:fname = expand('%:p')
let [l:line, l:col] = getpos('.')[1:2]

call go#lsp#DidChange(l:fname)

let l:lsp = s:lspfactory.get()

let l:state = s:newHandlerState('')

let l:info = go#promise#New(function('s:info', [0], l:state), 10000, '')

let l:state.handleResult = funcref('s:infoDefinitionHandler', [l:info.wrapper, 0], l:state)
let l:state.error = funcref('s:noop')
let l:msg = go#lsp#message#Definition(l:fname, l:line, l:col)
call l:lsp.sendMessage(l:msg, l:state)
return l:info.await()
endfunction

function! s:infoDefinitionHandler(next, showstatus, msg) abort dict
" gopls returns a []Location; just take the first one.
let l:msg = a:msg[0]

Expand All @@ -565,12 +584,22 @@ function! s:infoDefinitionHandler(showstatus, msg) abort dict
let l:state = s:newHandlerState('')
endif

let l:state.handleResult = funcref('s:hoverHandler', [function('s:info', [], l:state)], l:state)
let l:state.handleResult = funcref('s:hoverHandler', [a:next], l:state)
let l:state.error = funcref('s:noop')
return l:lsp.sendMessage(l:msg, l:state)
endfunction

function! s:info(content) abort dict
function! s:info(show, content) abort dict
let l:content = s:infoFromHoverContent(a:content)

if a:show
call go#util#ShowInfo(l:content)
endif

return l:content
endfunction

function! s:infoFromHoverContent(content) abort
let l:content = a:content[0]

" strip godoc summary
Expand All @@ -580,7 +609,8 @@ function! s:info(content) abort dict
if l:content =~# '^type [^ ]\+ \(struct\|interface\)'
let l:content = substitute(l:content, '{.*', '', '')
endif
call go#util#ShowInfo(l:content)

return l:content
endfunction

" restore Vi compatibility settings
Expand Down

0 comments on commit 03febea

Please sign in to comment.