Youcompleteme: GoTo command not work with vendor in Golang?

Created on 13 Apr 2018  路  12Comments  路  Source: ycm-core/YouCompleteMe

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside
the brackets) _before_ filing your issue:

  • [x] I have read and understood YCM's CONTRIBUTING document.
  • [x] I have read and understood YCM's CODE_OF_CONDUCT document.
  • [x] I have read and understood YCM's README, especially the
    Frequently Asked Questions section.
  • [x] I have searched YCM's issue tracker to find issues similar to the one I'm
    about to report and couldn't find an answer to my problem. (Example Google
    search.
    )
  • [x] If filing a bug report, I have included the output of vim --version.
  • [x] If filing a bug report, I have included the output of :YcmDebugInfo.
  • [x] If filing a bug report, I have attached the contents of the logfiles using
    the :YcmToggleLogs command.
  • [x] If filing a bug report, I have included which OS (including specific OS
    version) I am using.
  • [x] If filing a bug report, I have included a minimal test case that reproduces
    my issue, including what I expected to happen and what actually happened.
  • [x] If filing a installation failure report, I have included the entire output
    of install.py (or cmake/make/ninja) including its invocation
  • [x] I understand this is an open-source project staffed by volunteers and
    that any help I receive is a selfless, heartfelt _gift_ of their free time. I
    know I am not entitled to anything and will be polite and courteous.
  • [x] I understand my issue may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.

Issue Details

Provide a clear description of the problem, including the following key
questions:

  • What did you do?

Include steps to reproduce here.

  1. create main.go in gopath
package main

import (
    "go.uber.org/zap"
)

func main() {
    logger, _ := zap.NewProduction()
    defer logger.Sync()

    logger.Info("haha")
}
  1. run dep ensure -add "go.uber.org/zap"

  2. use vim, open main.go, jump to line 11, under Info of logger.Info, and run :YcmCompleter GoTo,
    got RuntimeError: Can't find a definition.

Include description of a minimal test case, including any actual code required
to reproduce the issue.

  • What did you expect to happen?

jump to definition of Info inner vendor directory.

Include description of the expected behaviour.

  • What actually happened?

nothing but RuntimeError: Can't find a definition.

Include description of the observed behaviour, including actual output,
screenshots, etc.

Diagnostic data

Output of vim --version

NVIM v0.2.2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/cc -g -O2 -fdebug-prefix-map=/build/neovim-OyJkBd/neovim-0.2.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -DDISABLE_LOG -Wdate-time -D_FORTIFY_SOURCE=2 -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -O2 -g -DMIN_LOG_LEVEL=3 -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -I/build/neovim-OyJkBd/neovim-0.2.2/build/config -I/build/neovim-OyJkBd/neovim-0.2.2/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim-OyJkBd/neovim-0.2.2/build/src/nvim/auto -I/build/neovim-OyJkBd/neovim-0.2.2/build/include
Compiled by [email protected]

Features: +acl +iconv +jemalloc +tui 
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Output of YcmDebugInfo

Printing YouCompleteMe debug information...                                                             
-- Client logfile: /tmp/ycm_k6wkcljd.log
-- Server Python interpreter: /home/jiajun/.py3k/bin/python
-- Server Python version: 3.6.3
-- Server has Clang support compiled in: False
-- Clang version: None
-- No extra configuration file found
-- Server running at: http://127.0.0.1:44727
-- Server process ID: 3464
-- Server logfiles:
--   /tmp/ycmd_44727_stdout_e296vmt2.log
--   /tmp/ycmd_44727_stderr_3hml12e5.log

Contents of YCM, ycmd and completion engine logfiles

Include link here to a gist containing the entire logfiles for ycm, ycmd
and any completer logfiles listed by :YcmToggleLogs.

OS version, distribution, etc.

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux testing (buster)
Release:    testing
Codename:   buster

Output of build/install commands

./install.py --go-completer

Most helpful comment

still not work, hope to be fixed

All 12 comments

I can reproduce the issue and the ycmd logs show this error (godef is used to jump to definition):

RuntimeError: Command godef -i -f=main.go -json -o=126 failed with code 2 and error "godef: no declaration found for logger.Info".

Running directly the command with the latest version of godef raises the same error:

$ godef -i -f=main.go -o=126 < main.go
parseLocalPackage error: no more package files found
godef: no declaration found for logger.Info

so it looks like an issue with godef. Would you mind reporting it to the godef repository?

okay, thank you

Ran into the same issue today, found out that vim-go's :GoDef will work as expected, if you've installed the upstream godef into your $PATH.

ycmd uses a old fork of godef which doesn't really deal with golang vendor directories.

you can use vim-go's :GoDef if you want this fixed ugly and fast.

autocmd FileType go nnoremap <C-c>g :<C-u>call go#def#Jump("vsplit")<CR>

@jiajunhuang

@timfeirg Did you read my comment? I tried with the latest version of Godef. Are you sure you are talking about the same issue?

I'm sorry, I didn't exactly carry out the steps to verify that it's fixed.

I just put the example code in main.go, go get -d go.uber.org/zap, and then did a :GoDef on the logger.info method, this does work, so I just assumed that the latest version of the upstream godef works.

Also, I was seeing the upstream godef correctly finds the dependencies in the vendor directories, and just think that it's pretty convincing. @micbou

The :GoDef command from vim-go is working because it uses Guru by default, not Godef. I guess we should switch to that tool.

hello, after compile latest YCM with --go-completer, auto completion code in vendor still not work, will this issue be fixed? thank you!

using language server protocol now.

still not work, hope to be fixed

Can I configure ycm to use guru in Golang?

No

We have switched to gopls which solves the issue with the GoTo subcommand.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vbextreme picture vbextreme  路  4Comments

kb100 picture kb100  路  4Comments

blackode picture blackode  路  3Comments

tgzhou98 picture tgzhou98  路  3Comments

2c2c picture 2c2c  路  3Comments