Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working directory not preserved correctly #54

Closed
nezorflame opened this issue Dec 29, 2018 · 9 comments
Closed

working directory not preserved correctly #54

nezorflame opened this issue Dec 29, 2018 · 9 comments

Comments

@nezorflame
Copy link

nezorflame commented Dec 29, 2018

Seems like gogetdoc (or, rather, go list?) is unable to get documentation for stdlib packages with GO111MODULE=on (/Users/nezorflame/.gvm/gos/go1.11.4 is where my Go is installed, through gvm):

Input:
~ gogetdoc -pos=/Users/nezorflame/.gvm/gos/go1.11.4/src/fmt/print.go:#7660

Output:
cannot load package containing /Users/nezorflame/.gvm/gos/go1.11.4/src/fmt/print.go: go [list -e -json -compiled -test=false -export=false -deps=true -- /Users/nezorflame/.gvm/gos/go1.11.4/src/fmt]: exit status 1: go: cannot determine module path for source directory /Users/nezorflame/.gvm/gos/go1.11.4 (outside GOPATH, no import comments)

If I explicitly set GO111MODULE=auto (or off) before invoking it, it works:

Input:
~ GO111MODULE=auto gogetdoc -pos=/Users/nezorflame/.gvm/gos/go1.11.4/src/fmt/print.go:#7660

Output:

import "fmt"

func Fprintln(w io.Writer, a ...interface{}) (n int, err error)

Fprintln formats using the default formats for its operands and writes to w.
Spaces are always added between operands and a newline is appended. It returns
the number of bytes written and any write error encountered.

Details on that issue can be found here: microsoft/vscode-go#2213

@ramya-rao-a
Copy link

cc @zmb3

@zmb3 zmb3 changed the title Failure for Go stdlib packages with GO111MODULE=on working directory not preserved correctly Dec 31, 2018
@zmb3
Copy link
Owner

zmb3 commented Dec 31, 2018

Thanks for tracking this down - the detail in your vscode-go issue helped tremendously.

This is an issue of preserving context properly. In its current state, gogetdoc uses the directory containing your file query as the working directory for go list. This is why your initial query succeeds.

When you try to navigate again from within the fmt package, we are using a working directory inside the go source instead of your original project directory, and the go tool cannot find the main module.

@ramya-rao-a
Copy link

@zmb3 In that case, I believe I can fix this from vscode-go just like I did previously for godef

I dont set a working directory for the child process being spawned for calling gogetdoc.
But for godef, I pass the current project opened in VS Code as the working directory.

Will doing the same help gogetdoc as well?

@zmb3
Copy link
Owner

zmb3 commented Dec 31, 2018

Will doing the same help gogetdoc as well?

Yes, it will. But I need to push a fix to gogetdoc before it will make a difference.

zmb3 added a commit that referenced this issue Jan 1, 2019
Editors must use the project working directory when invoking gogetdoc to 
ensure that we can jump across module boundaries.

Updates #54
@nezorflame
Copy link
Author

Seems like the issue is resolved now.
Thanks @zmb3!

@zmb3
Copy link
Owner

zmb3 commented Jan 9, 2019

Thanks for following up @nezorflame!

@zmb3 zmb3 closed this as completed Jan 9, 2019
@karim
Copy link

karim commented Jan 21, 2019

@zmb3 The fix for this issue introduced another issue. The details are here microsoft/vscode-go#2246. Would you mind taking a look at it?

@zmb3
Copy link
Owner

zmb3 commented Jan 21, 2019

@karim this is intentional. Editors must provide a working directory when invoking the tool. The fix will have to be made in the extension. Let’s take the conversation over to that issue.

@karim
Copy link

karim commented Jan 21, 2019

I see, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants