Skip to content

Commit

Permalink
doc: get package from LSP
Browse files Browse the repository at this point in the history
Get the package name of the identifier under the cursor using the doc
link provided by lsp. This fixes two problems: performance of trying to
rely on go list via go#tool#Imports()  to get the package name and that
the package name is sometimes being set incorrectly to a method
receiver.

Fixes fatih#3546
  • Loading branch information
bhcleek committed Jun 19, 2023
1 parent e3008d9 commit a5f0594
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions autoload/go/doc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,33 @@ endfunction
function! s:godocWord(...) abort
let words = a:000
if a:0 is 0
let oldiskeyword = &iskeyword
" TODO(bc): include / in iskeyword when filetype is godoc?
setlocal iskeyword+=.
let word = expand('<cword>')
let &iskeyword = oldiskeyword
let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g')
let words = split(word, '\.\ze[^./]\+$')
if &filetype isnot 'godoc'
" TODO(bc): use LSP textdocumment/documentSymbol to get the symbols for
" the current document and figure out if the package of the symbol under
" the cursor when a:0 is 0
let [l:out, l:err] = go#lsp#DocLink()
if l:err
call go#util#EchoError(l:out)
return []
endif

if len(l:out) == 0
call go#util#EchoWarning("fubar")
return []
endif

" strip out any version string in the doc link path.
let l:out = substitute(l:out, '@v[^/]\+', '', '')
let words = split(l:out, '#')
else
let oldiskeyword = &iskeyword
" TODO(bc): include / in iskeyword when filetype is godoc?
setlocal iskeyword+=.
let word = expand('<cword>')
let &iskeyword = oldiskeyword
let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g')
let words = split(word, '\.\ze[^./]\+$')
endif
endif

if !len(words)
Expand All @@ -229,14 +249,6 @@ function! s:godocWord(...) abort
let exported_name = words[1]
endif

if &filetype isnot 'godoc'
let packages = go#tool#Imports()
if has_key(packages, pkg)
let pkg = packages[pkg]
endif
endif


return [pkg, exported_name]
endfunction

Expand Down

0 comments on commit a5f0594

Please sign in to comment.