Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Go To Definition Not Working #966

Closed
mukeshdutt opened this issue May 5, 2017 · 20 comments
Closed

Go To Definition Not Working #966

mukeshdutt opened this issue May 5, 2017 · 20 comments

Comments

@mukeshdutt
Copy link

mukeshdutt commented May 5, 2017

Hi,
I'm using golang with latest version of vscode and here i'm getting issue go to definition but the same thing is working fine in Sublime Text editor.

In src folder of my golang workspace here is multiple projects when trying to find same project function, struct etc. those are able to find but when I'm trying go to definition for another project stuff then below message is appeared.

No definition found for "function name".

screenshot from 2017-05-05 10-15-15

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented May 5, 2017

@mukeshdutt

  • Is this a regression? i.e it worked before but not now?
  • Just to rephrase what you are saying: go to definition works for functions in the same package but not across multiple packages?
  • Have you changed the setting for go.docsTool, if yes can you share the value?
  • Have you set go.useLanguageServer to true ?
  • What is the version of Go extension you are using?
  • What platform are you in and version of Go ?

@erichiller
Copy link

I too am having this issue, I am unsure which version it began with. It previously did work, but hasn't for ~1-2 months.

Mostly for in-built libraries (runtime, net/http, etc...)

I do not have
go.useLanguageServer set to true (it is the default false)
Nor have I changed godocs

@ramya-rao-a
Copy link
Contributor

@erichiller Can you try setting go.docsTool to gogetdocs ?

@bennyscetbun
Copy link

@ramya-rao-a
Hi since last update, i have the same issue

  • It was working fine before the update
  • Yes go definition wasnt working between packages
  • No i havent changed go.docsTool
  • No i havent changed go.useLanguageServer
  • extension: 0.6.61
  • I am on MacOS 10.12.4

I just tried to use gogetdocs and it works better.

By the way even if my GOPATH was set. since last patch i have to set it manually in the vscode configuration.
Same thing for GOROOT... (i had an error cannot find go executable in PATH or GOROOT which is strange...).
Maybe it is related. I was about to make an issue.

@ramya-rao-a
Copy link
Contributor

@erichiller It is known issue that godef doesn't work well with built-in pkgs. See #599 The workaround is to use gogetdoc instead.

@bennyscetbun We use godef by default for the Go to definition feature. Can you run godef from the command line to see if it returns the right location? I cannot think of any reason why it would stop working suddenly.

@bennyscetbun About the GOPATH issue, can you log a separate issue?

@bennyscetbun
Copy link

bennyscetbun commented May 10, 2017

@ramya-rao-a
removing gopath, goroot and event godoctool from my configuration and restarting all the instance of visual studio fixed all my issues. (i hadnt close my mac session or visual studio since 2 month)

@ramya-rao-a
Copy link
Contributor

@bennyscetbun great that you are unblocked now. Happy Coding!

@erichiller @mukeshdutt Do you still have issues with the Go to Definition feature?

@erichiller
Copy link

@ramya-rao-a Yes - Sorry for the delay - I just changed my config - Restarted vscode as well to include go.docsTool to be gogetdoc
here are my non-default settings:

  // vscode-go
  // Run 'go build'/'go test -c' on save.
  "go.buildOnSave": false,
  // Run Lint tool on save.
  "go.lintOnSave": true,
  // "go.lintTool": "golint",
  // Run 'go tool vet' on save.
  "go.vetOnSave": true,
  "go.formatOnSave": false,
  "go.gotoSymbol.includeImports": true,
  "go.useCodeSnippetsOnFunctionSuggest": true,
  // Enable gocode's autobuild feature
  "go.gocodeAutoBuild": true,
  // Use gotype on the file currently being edited and report any semantic or syntactic errors found after configured delay.
  "go.liveErrors": {
    "enabled": true,
    "delay": 500
  },
  "go.editorContextMenuCommands": {
    "toggleTestFile": true,
    "addTags": true,
    "removeTags": false,
    "testAtCursor": true,
    "testFile": false,
    "testPackage": false,
    "generateTestForFunction": true,
    "generateTestForFile": true,
    "generateTestForPackage": false,
    "addImport": true,
    "testCoverage": true
  },
  "go.docsTool":"gogetdoc",
  // "go.gopath": "C:\\Users\\ehiller\\dev\\",
  // "go.toolsGopath": "C:\\Users\\ehiller\\dev\\",
  // "go.goroot": "C:\\Users\\ehiller\\AppData\\Local\\omega\\system\\go\\"
  "go.lintTool": "gometalinter",
  "go.lintFlags": [
    "--disable-all",
    // "--enable=varcheck",
    // "--enable=unused",
    // "--enable=ineffassign"
    // "--enable=goconst",
    // "--enable=interfacer",
    // "--enable=staticcheck",
    // "--enable=dupl",
    // "--enable=errcheck",
    // "--enable=golint",
    "--enable=gotype",
    "--enable=vet",
    "--enable=misspell"
    // // "--enable=gocyclo",
    // "--enable=goimports",
    // "--enable=gosimple",
    // "--enable=aligncheck",
    // "--enable=deadcode",
    // "--enable=ineffassign",
    // "--enable=structcheck",
    // // "--enable=unconvert"
  ],

@ramya-rao-a
Copy link
Contributor

@erichiller So you are saying that "Go to Definition" is not working even after changing to gogetdoc ?

@Emreu
Copy link
Contributor

Emreu commented May 15, 2017

Hi everyone! I had possibly same issue.
After some research found root of problem (at least for my case) - function isPositionInString (utils.ts:238) returns incorrect values for some specific but usual in golang cases. If you have empty string ("") or some bizzare escaped string ("\\") before your object of interest - go to definition didn't works.
Examples:
not_ok_1
not_ok_2
Replace string with something regular and everything works good:
ok

Please consider fixing double quotes counting logic.
Possible solution: count all quotes than subtract escaped quotes.

@ramya-rao-a
Copy link
Contributor

@Emreu Thanks for investigating. Next time feel free to submit a PR as well. You have found the root cause, I'd prefer you get the credit for fixing the issue as well :)

For now I have pushed in the fix.

@erichiller @mukeshdutt I'll wait a few more days for you to confirm if your case is similar to @Emreu

@mukeshdutt
Copy link
Author

@ramya-rao-a Sorry for the delay in my case I'm sending dynamic value(variable) instead of hard coded.

And now i changed go.docsTool value to gogetdoc after change this gogetdoc plugin was downloaded then again same go.useLanguageServer value to true after change the value same as go.useLanguageServer plugin tried to download but getting failed message.

@ramya-rao-a
Copy link
Contributor

@mukeshdutt

So you are saying setting go.docsTool to gogetdoc didn't work
And after that you tried, setting go.useLanguageServer to true also didn't work?

Are you using multiple GOPATHs?

@hjma29
Copy link

hjma29 commented Jun 7, 2017

When I use Visual Studio Code with Go exention or Atom with Go-plus, I got "No definition was found for 'Command'" error when trying to check declaration of the following code "&Cobra.Command". JetBrains' Gogland doesn't have this issue and can correctly jump to the Command(a struct) defintion.

https://github.com/spf13/cobra/blob/master/cobra/cmd/add.go#L32

var addCmd = &cobra.Command{
    Use:     "add [command name]",
    Aliases: []string{"command"},
    Short:   "Add a command to a Cobra Application",
    Long: `Add (cobra add) will create a new command, with a license and

@ramya-rao-a
Copy link
Contributor

@hjma29 Can you try setting go.docsTool to gogetdoc?

@hjma29
Copy link

hjma29 commented Jun 7, 2017

Thanks from prompt response. It works right away! Do we have plan to make "gogetdoc" as default or it has other issues comparing with godoc/godef?

@ramya-rao-a
Copy link
Contributor

gogetdoc tends to be slightly slower than godoc/godef. Other than that there are no other issues.

There is no current plan to make it default, but we can try it in one of the updates and see how it fares the larger audience

@ramya-rao-a
Copy link
Contributor

We'll use #1025 to track the discussion around making gogetdoc the default tool.

@mukeshdutt We haven't heard back from you in a while, hopefully the problem is resolved.

Closing this issue as the fix for the issue @Emreu is in master and will be out in the next update

@AdiedX
Copy link

AdiedX commented Jul 17, 2017

I had the same issue with:

VS Code 1.14.1 (June 2017)
Mac OS Sierra 10.12.2
Go Plugin 0.6.62
Go 1.7.5

Setting "go.useLanguageServer": true in settings.json, mentioned by @ramya-rao-a, fixed the issue for me.

@ITSecMedia
Copy link

@AdiedX Thank you, that solved my problem!

I'm using Windows here and useLanguageServer is not available but the setting needs to be activated to get the broken "Go to Definition F12" working again while using "go.docsTool": "gogetdoc",

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants