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

gogetdoc doesn't work without opening a folder #2246

Closed
karim opened this issue Jan 13, 2019 · 12 comments
Closed

gogetdoc doesn't work without opening a folder #2246

karim opened this issue Jan 13, 2019 · 12 comments

Comments

@karim
Copy link

karim commented Jan 13, 2019

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.

1

But if I opened a folder it started working...

2

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.

3

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.

@ramya-rao-a
Copy link
Contributor

@karim Can you try our latest beta version of the extension that has a couple of bug fixes that haven't been released yet?

@karim
Copy link
Author

karim commented Jan 21, 2019

@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.

@zmb3
Copy link
Contributor

zmb3 commented Jan 21, 2019

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.

@karim
Copy link
Author

karim commented Jan 21, 2019

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.

@zmb3
Copy link
Contributor

zmb3 commented Jan 21, 2019

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.

@karim
Copy link
Author

karim commented Jan 21, 2019

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.

2246

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.

@ramya-rao-a
Copy link
Contributor

@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

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 22, 2019

@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

@karim
Copy link
Author

karim commented Jan 22, 2019

@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. 👍

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Jan 22, 2019

Thanks for getting back to us @karim and for all the feedback

@zmb3
Copy link
Contributor

zmb3 commented Jan 22, 2019

Yes, thank you both for the report and troubleshooting as well as the quick fix! ❤️

@ramya-rao-a
Copy link
Contributor

The fix for this is now out in the latest update (0.9.0) to the Go extension

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

No branches or pull requests

3 participants