Vscode Godef Unable to jump to a defined problem

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Original link: http://targetliu.com/vscode-can-not-go-to-def/

Before the study Golang has been used liteide, have to say, Liteide is really good, but the total feeling lack of beauty, is a very good editor. See everyone on the Internet good Vscode evaluation, after trying to find it is really good, layout concise, plug-in, support Chinese, through the vscode go extension can be very comfortable to write go code.

Problem description

However, in the actual use process found that the net package does not normally jump to the definition, the following code ResolveTCPAddr will not be normal jump

package mainimport (    "net")func main() {    _, err := net.ResolveTCPAddr("tcp", ":4040")}

Since Vscode go jumps to the definition using GODEF, the debug mode of Godef is used to view
Cause of the problem:

godef -debug -f main.go net.ResolveTCPAddr

The results of the operation are as follows:

2016/08/02 01:17:30 exprtype tuple:false pkg: *ast. selectorexpr Net. listentcp [2016/08/02 01:17:30 exprtype tuple:false pkg: *ast. Ident net [2016/08/02 01:17:30 exprtype tuple:false pkg: *ast. Importspec "NET" [2016/08/02 01:17:30], 0x0, Type{package "" *ast. Importspec "NET"}2016/08/02 01:17:30], 0xc820157860, Type{package "" *ast. Importspec "NET"}2016/08/02 01:17:30 member Type{package "" *ast. Importspec "NET"} ' listentcp ' {2016/08/02 01:17:30/usr/local/go/src/net/cgo_android.go:10:8: Cannot find identifier F or package ' C ': Cannot find package ' C ' in any of:/usr/local/go/src/vendor/c (Vendor tree)/usr/local/go/src/c (fro  M $GOROOT)/users/targetliu/dev/govendor/src/c (from $GOPATH)/users/targetliu/dev/golang/src/c2016/08/02 01:17:30} <nil>2016/08/02 01:17:30], 0x0, Type{bad "" <nil>}2016/08/02 01:17:30 exprtype tuple:false pkg: *ast. selectorexpr Net. listentcp [2016/08/02 01:17:30 exprtype tuple:false pkg: *ast. Ident NET [2016/08/01:17:30 exprtype tuple:false pkg: *ast. Importspec "NET" [2016/08/02 01:17:30], 0x0, Type{package "" *ast. Importspec "NET"}2016/08/02 01:17:30], 0xc820157860, Type{package "" *ast. Importspec "NET"}2016/08/02 01:17:30 member Type{package "" *ast. Importspec "NET"} ' listentcp ' {2016/08/02 01:17:30/usr/local/go/src/net/cgo_android.go:10:8: Cannot find identifier F or package ' C ': Cannot find package ' C ' in any of:/usr/local/go/src/vendor/c (Vendor tree)/usr/local/go/src/c (fro  M $GOROOT)/users/targetliu/dev/govendor/src/c (from $GOPATH)/users/targetliu/dev/golang/src/c2016/08/02 01:17:30} <nil>2016/08/02 01:17:30], 0x0, Type{bad "" <nil>}godef:no declaration found for net. Listentcp

Take note of this sentence:

cannot find identifier for package "C": cannot find package "C" in any of:

It turns out to be a net package import C , but C is not a specific real-life package, so godef cannot parse it, resulting in a definition not found.

Godef's GitHub author also found the same problem: Issue:net. Lookupip fails #41

Solution Solutions

On GitHub, Godef saw someone submit a solution to the problem: master-special treatment for "C" packages. #44

Depending on the submission, you can try to resolve it using the following methods:

    • Locate and open go/parser/parser.go this file for Godef

    • In the 1970行 left and right add (the code in the + number section, you can search by positioning):

      if declIdent == nil {              filename := p.fset.Position(path.Pos()).Filename              name, err := p.pathToName(litToString(path), filepath.Dir(filename)) +            if litToString(path) == "C" { +                name = "C" +            }              if name == "" {                  p.error(path.Pos(), fmt.Sprintf("cannot find identifier for package %q: %v", litToString(path), err))              } else {
    • Recompile godef

If you encounter the same problem, try the above, at least for me, the problem has been solved.
Also hope that the author can fix this problem as soon as possible.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.