"Cannot find declaration to go to" for Go files


I'm unable to go to declaration of any variable or function in golang. Can someone please help?

I've tried below steps, but to no vail:

  • Remove *.iml files in .idea > didn’t work
  • Enable go plugin -> didn’t work
  • Checked Settings/Preferences | Editor | File Types -> *.go already not in registered text patterns


Could you check if:

  • Go sdk is added in Settings (⌘ + , on macOS or Ctrl + Alt + S on Win/Linux) > Languages & Frameworks > GOROOT:

  • Go home path is added in Settings (⌘ + , on macOS or Ctrl + Alt + S on Win/Linux) >Languages & Frameworks > GOPATH:

  • .go extension is registered as Go files file type in Settings (⌘ + , on macOS or Ctrl + Alt + S on Win/Linux) > Editor > File Types:

  • Right-click on the folder with source files in project window > Mark Directory as > Sources Root
  • Try to invalidate caches File > Invalidate Caches.. > Invalidate and Restart

If you still cannot go to any variable/method declaration, if possible please provide your project sample so that we can reproduce the issue on our side. Also, your IDE log file (Help > Collect Logs and Diagnostic Data).
You can upload both the zipped project folder and log files here: https://uploads.jetbrains.com, and provide the uploaded file ID.


I have the same issue.  I've followed all of the steps above.  It seems to lack a certain “intelli”gence when it comes to understanding Go projects.


Ed Randall 
Could you please share a screenshot or screen recording showing the entire IDE window (especially project tree in a project tool window and file in the editor) when this issue occurs? Do you have the Go plugin installed and enabled? If possible, please share a sample project to try and reproduce the issue on our end?

Also, please restart the IDE, reproduce the issue and share your IDE logs (Help > Collect Logs and Diagnostic Data). They contain information about your environment and possibly some exceptions/errors related to the issue.

You can zip all of those files and upload them securely here: https://uploads.jetbrains.com, just provide the uploaded file ID.


Thanks - have solved this now.   It turned out to be an internal proxy problem.   Solution:

  1. Ensure GOROOT, GOPATH etc configured as above
  2. Settings > Languages & Frameworks > Go > Go Modules
    a) Tick “Enable Go modules integration”
    b) Environment: GOPROXY=https://atrifactory.ourdomain.com/artifactory/api/go/goproxy (this is the address of our internal artifact repository)
    c) Possibly also set HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables (depending on corp. requirements)

The way to test/experiment & find the configuration needed was by running:

go list -modfile=go.mod -m all

Until HTTP_PROXY, HTTPS_PROXY, NO_PROXY and GOPROXY were correct, each dependency URL was printed with a “Bad Gateway” message.


Please sign in to leave a comment.