joefitzgerald / go-plus

An Enhanced Go Experience For The Atom Editor
https://atom.io/packages/go-plus
Other
1.51k stars 128 forks source link

Generating documentation is not working properly due to incorrect setting of GOMOD #876

Open malkhamis opened 5 years ago

malkhamis commented 5 years ago

Prerequisites

Description

The problem manifests itself when Atom's Project tab contains multiple directories such that all directories are separate projects with their own go.mod file. I noticed that generating documentations (either by hovering or by pressing alt-d on the symbol only worked for a single project. The following output whenever a request for documentation is served was observed in Console: go-plus:

/home/[user]/go/bin/gogetdoc -pos /home/[user]/src/github.com/[path]/[repo]/[file].go:#1145 -linelength 999 -json failed with exit code 1.
/home/[user]/go/bin/gogetdoc stderr: cannot load package containing /home/[user]/src/github.com/[path]/[repo]/[file].go: go [list -e -json -compiled -test=false -export=false -deps=true -- /home/[user]/src/github.com/[path]/[repo]/[file].go]: exit status 1: go: directory ../[repo] outside available modules

Initially, I suspected that this is related to this issue in golang/cmd. However, it turned out that the problem only happens when there are multiple directories in Atom's Project tab. For some reason, go-plus assumes (maybe?) that the first directory in the Project tab is the only project and environment variable GOMOD gets set to the absolute path of the go.mod file for that project. If I navigate to another project in that same Atom instance and request documentation for a symbol, go-plus gets stuck showing Generating documentation... forever without giving back any results for showing documentation. Of course, I also observe error go: directory ../[repo] outside available modules in the console.

To confirm the above, I tried to move one directory up in the Project tab and reloaded Atom. I observed that GOMOD is now set to the other project that was moved up in the list and requests for documentations are served as expected

Output from atom -v && apm -v

~ $ atom -v && apm -v
Atom    : 1.34.0
Electron: 2.0.16
Chrome  : 61.0.3163.100
Node    : 8.9.3
apm  2.1.3
npm  6.2.0
node 8.9.3 x64
atom 1.34.0
python 2.7.5
git 2.16.2

Output From go env

GOARCH="amd64" GOBIN="" GOCACHE="/home/malkhamis/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/malkhamis/go" GOPROXY="" GORACE="" GOROOT="/usr/lib/golang" GOTMPDIR="" GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/malkhamis/[...]/github.com/[org]/[repo]/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build474342128=/tmp/go-build -gno-record-gcc-switches"

Steps to Reproduce

  1. Add multiple go projects to Atom's Project tab such that each directory contains go.mod file
  2. navigate to any project in the list other than the first
  3. open a .go file and request docs for any symbol by pressing alt-d

Expected Behavior

Should be able to generate docs for any project in the Project tab without the need to move the project up in the list and reload Atom

Actual Behavior

Gets stuck showing Generating Documentation...

zmb3 commented 5 years ago

Thanks for pointing this out. We do, indeed, just take the first project path.

In a multi-project workspace it turns out to be difficult to tell which project a particular editor is associated with. The very first time isn't too tricky, as you can expect the file to live inside the project directory, but from there if you navigate to a dependency (in GOPATH or the module cache) then you cant simply look at the path of the open file.

malkhamis commented 5 years ago

I see what you are saying... If this is difficult to fix, then may I suggest that this is mentioned in go-plus documentation somehow ? I think this will save other users a lot of guess work in regards of why it may not be working :)

macseem commented 5 years ago

@malkhamis I agree, because I spend up to 1 hour to understand what's the reason.

macseem commented 5 years ago

My STR: 2 projects. The First one is a react native and the second one is a golang api. So when I move golang project on top in the atom tree view, documentation feature works.

Fercho120 commented 5 years ago

Same Issue here, I had an Opencv.js webapp in one project and a golang api in the other. This should be mentioned in go-plus documentation

SkyHustle commented 4 years ago

Atom version 1.49

I have the exact same issue, except my project tab contains only 1 directory but I'm getting the same behavior and the same output to the atom console when I hover over any piece of code.

Any suggestions on how to fix this? It's driving me a little crazy.

Screen Shot 2020-08-10 at 12 25 04 PM