From 3ce44e976eddf42141e06c513624fe09d71d7a7f Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sun, 18 Jun 2023 21:12:57 -0700 Subject: [PATCH] doc: get package from LSP 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 #3546 --- autoload/go/doc.vim | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/autoload/go/doc.vim b/autoload/go/doc.vim index 36b49c6beb..c6745e4955 100644 --- a/autoload/go/doc.vim +++ b/autoload/go/doc.vim @@ -203,13 +203,32 @@ 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('') - 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 + 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('') + let &iskeyword = oldiskeyword + let word = substitute(word, '[^a-zA-Z0-9\\/._~-]', '', 'g') + let words = split(word, '\.\ze[^./]\+$') + endif endif if !len(words) @@ -229,14 +248,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