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

cmd/go: "go doc . foo" not working on Windows? #27881

Open
DeedleFake opened this issue Sep 26, 2018 · 12 comments
Open

cmd/go: "go doc . foo" not working on Windows? #27881

DeedleFake opened this issue Sep 26, 2018 · 12 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@DeedleFake
Copy link

The documentation notes that starting an identifier with a capital letter forces the current package, but if you're attempting to look up something that is unexported then this workaround doesn't apply, which can be annoying sometimes. I propose, therefore, that prefixing an identifier with a ., such as go doc .testing, should force go doc to only look up the identifier in the current package. Alternatively, when looking something up the current package, as specified by the use of a capital letter, and -u is given, then it should also match unexported identifiers despite the case mismatch.

@gopherbot gopherbot added this to the Proposal milestone Sep 26, 2018
@dsnet dsnet changed the title proposal: provide means of specifiying that go doc should look in current package only proposal: cmd/doc: provide means to resolve identifiers in current package only Sep 26, 2018
@rsc
Copy link
Contributor

rsc commented Oct 3, 2018

/cc @robpike
SGTM at least.

@robpike
Copy link
Contributor

robpike commented Oct 6, 2018

To your first point: Instead of your suggested go doc .testing you can already say go doc . testing, which is only a space character different and is just the consequence of regular rules. I much prefer applying regular rules that already solve the problem than introducing special rules for a special job.

To the second point: I also don't like adding a special case for a special case, so to speak, although I am less bothered by it. It's just complication. The current rule is documented and works.

So one strong thumb down and one mild thumb down from me.

@DeedleFake
Copy link
Author

you can already say go doc . testing

You can't, though. go help doc says

The package path must be either a qualified path or a proper suffix of a
path. The go tool's usual package mechanism does not apply: package path
elements like . and ... are not implemented by go doc.

Attempting to run go doc . <identifier> with a little test package yields

doc: no such package: .

I certainly wouldn't have a problem with that working, though.

@robpike
Copy link
Contributor

robpike commented Oct 7, 2018

I just tried this and it worked. I am using (approximately) go 1.11.

% cd go/src/fmt
% go doc . Printf
package fmt // import "fmt"

func Printf(format string, a ...interface{}) (n int, err error)
    Printf formats according to a format specifier and writes to standard
    output. It returns the number of bytes written and any write error
    encountered.

% 

So please give an example that fails. I don't know why the documentation says it doesn't work but I'd like to understand your issue first.

@DeedleFake
Copy link
Author

DeedleFake commented Oct 7, 2018

I did some quick testing. It's working for me on Linux but not on Windows. I tried 1.11.1 on Windows and both 1.11 and 1.11.1 on Linux.

@robpike
Copy link
Contributor

robpike commented Oct 7, 2018

I suspect this is about the go command, not go doc. Do other commands work on Windows, for example go list .?

@alexbrainman
Copy link
Member

I just tried this on current tip on Windows, and I cannot reproduce the problem:

c:\>cd %GOROOT%\src\fmt

c:\Users\Alex\dev\go\src\fmt>go doc . Printf
package fmt // import "fmt"

func Printf(format string, a ...interface{}) (n int, err error)
    Printf formats according to a format specifier and writes to standard
    output. It returns the number of bytes written and any write error
    encountered.


c:\Users\Alex\dev\go\src\fmt>go version
go version devel +2bb91e093c Sat Oct 6 19:18:34 2018 +0000 windows/amd64

c:\Users\Alex\dev\go\src\fmt>go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Alex\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\users\alex\dev
set GOPROXY=
set GORACE=
set GOROOT=c:\users\alex\dev\go
set GOTMPDIR=
set GOTOOLDIR=c:\users\alex\dev\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Alex\AppData\Local\Temp\go-build455273446=/tmp/go-build -gno-record-gcc-switches

c:\Users\Alex\dev\go\src\fmt>

@DeedleFake what did I do wrong? Thank you.

Alex

@DeedleFake
Copy link
Author

@robpike go list . is working fine for me.

@alexbrainman I'm not sure. I was able to reproduce it on multiple Windows machines with both PowerShell and Cmd. I haven't tried with the latest master, though, only 1.11.1. I'll try building it and testing that when I get a chance.

@rsc
Copy link
Contributor

rsc commented Oct 10, 2018

It sounds like as far as a proposal is concerned, we don't need to do go doc .foo since we already have go doc . foo. And perhaps there is a bug about that not working on Windows.

@rsc rsc changed the title proposal: cmd/doc: provide means to resolve identifiers in current package only cmd/go: "go doc . foo" not working on Windows? Oct 10, 2018
@rsc
Copy link
Contributor

rsc commented Oct 10, 2018

@DeedleFake, please post the output of both go doc . and go list . in the example that's not working for you. Thanks.

@rsc rsc added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 10, 2018
@DeedleFake
Copy link
Author

DeedleFake commented Oct 10, 2018

Here's one with the latest master.

> cd (go env GOROOT)\src\fmt
> go doc .
doc: invalid identifier "$HOME\\Devel\\build\\go\\src\\fmt"
exit status 1
> go doc . printf
doc: no such package: .
exit status 1
> go list .
fmt

I get the exact same results with packages outside the standard library as well, whether or not they're in GOPATH and whether or not they're modules.

Here's the output of go env, which I apparently haven't posted yet, for one of the machines that I've tested this on:

set GOARCH=amd64
set GOBIN=
set GOCACHE=$HOME\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=$HOME\Devel\Go
set GOPROXY=
set GORACE=
set GOROOT=$HOME\scoop\apps\go\current
set GOTMPDIR=
set GOTOOLDIR=$HOME\scoop\apps\go\current\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=$HOME\AppData\Local\Temp\go-build244586810=/tmp/go-build -gno-record-gcc-switches

@gopherbot
Copy link

Change https://golang.org/cl/164759 mentions this issue: cmd/doc: fix handling of path parameters on Windows

@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Unplanned Jan 6, 2021
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

7 participants