gogetdoc doesn't work without opening a folder
Closed this issue · 12 comments
If I opened a .go file to edit, gogetdoc
doesn't work. It doesn't show functions docs and Go to Definition
doesn't work, if no folder is opened.
But if I opened a folder it started working...
Strangely enough, the folder doesn't have to be the parent folder for the .go file. It can by any sub-folder, even an empty one.
Go version: 1.11.4
VS Code: 1.30.2
Go plugin: 0.8.1-beta.5
gogetdoc
latest version from Go: Install/Update tools
I think my issue is somehow related to issue #2213? Because I searched for similar issues on why gogetdoc
isn't working for me. It wasn't working at all with Go plugin v0.8.0 (with and without opening folders) so I checked the latest beta version and it worked only with folders.
@karim Can you try our latest beta version of the extension that has a couple of bug fixes that haven't been released yet?
@ramya-rao-a I tried the latest version (0.8.1-beta.6) and it's still the same. I remember it was working before but then I updated Go tools from VS Code and it stopped working.
So I tried reverting to an older version of gogetdoc
to see when it stopped working. It turns out this is a gogetdoc
problem, and not the Go extension.
Commit zmb3/gogetdoc@1fd4a45 introduced the bug in this issue. I reverted back to zmb3/gogetdoc@c5ca8f4 and it started working again.
This fixed it for me...
>cd %GOPATH%\src\github.com\zmb3\gogetdoc
>git checkout c5ca8f4d4936d4852f065372f3b89c8785b948f7
>go install github.com\zmb3\gogetdoc
Feel free to close this issue and I will open the issue with gogetdoc
repo.
This actually is an issue with the extension and not gogetdoc. The only way to get documentation in both gopath and module mode is for the editor to set the working directory when invoking the tool.
It sounds like if you haven’t opened a folder then the extension is not able to detect the correct working directory. Which is reasonable - given only a single file it’s pretty hard to guess at what context you are working in.
I see, thanks for the clarifications. I thought the issue was with gogetdoc because it was working before without a problem then stopped working (without any changes to the extension).
given only a single file it’s pretty hard to guess at what context you are working in.
You are right, opening a folder, or a workspace, is working without a problem.
However, VS Code is the default application for .go files. I usually open .go files by double-clicking files randomly, without opening a folder/workspace, then it stops working.
Right. It worked when you downgraded, but the old version that worked for you would have failed with modules.
One thing to try that might work the majority of the time is to use the dirname of the file as the working dir.
Alternative approaches would be to search up the directory tree looking for $GOPATH/src or a go.mod file.
It worked when you downgraded, but the old version that worked for you would have failed with modules.
Actually it is working with modules too.
To sum everything up..
- zmb3/gogetdoc@c5ca8f4 works with both GOPATH and modules.
- Latest gogetdoc is working inside GOPATH only, but it does not work with modules without opening a folder. If I open a folder or a workspace then it works.
@karim zmb3/gogetdoc#54 was the issue that was fixed with the commit you are reverting in gogetdoc
The problem was not with the initial use of gogetdoc in a file in your project, but the subsequent uses in files. For eg, you tried to hover on fmt.Println
, now run Go to definition
on it, and then in the resulting file, try to run Go to definition
or hover over a symbol. That won't work. And that is fixed with zmb3/gogetdoc@1fd4a45
@karim I have pushed another fix. Can you try the latest beta version again? The version should be 0.8.1-beta.7
Try with the latest gogetdoc as well
@ramya-rao-a Thank you very much. It is working now. 😃
Using latest gogetdoc and 0.8.1-beta.7 the problem is fixed.
The problem was not with the initial use of gogetdoc in a file in your project, but the subsequent uses in files.
I understand it better now, thanks again.
@zmb3 Thanks for your quick reply and for this great tool. 👍
Thanks for getting back to us @karim and for all the feedback
Yes, thank you both for the report and troubleshooting as well as the quick fix! ❤️
The fix for this is now out in the latest update (0.9.0) to the Go extension