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 · 11 comments

Comments

Projects
None yet
6 participants
@DeedleFake

DeedleFake commented Sep 26, 2018

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

@gopherbot gopherbot added the Proposal label Sep 26, 2018

@dsnet dsnet changed the title from proposal: provide means of specifiying that go doc should look in current package only to proposal: cmd/doc: provide means to resolve identifiers in current package only Sep 26, 2018

@rsc

This comment has been minimized.

Contributor

rsc commented Oct 3, 2018

/cc @robpike
SGTM at least.

@robpike

This comment has been minimized.

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

This comment has been minimized.

DeedleFake commented Oct 7, 2018

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Member

alexbrainman commented Oct 8, 2018

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

This comment has been minimized.

DeedleFake commented Oct 8, 2018

@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

This comment has been minimized.

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 from proposal: cmd/doc: provide means to resolve identifiers in current package only to cmd/go: "go doc . foo" not working on Windows? Oct 10, 2018

@rsc

This comment has been minimized.

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 label Oct 10, 2018

@DeedleFake

This comment has been minimized.

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

@bradfitz bradfitz added the OS-Windows label Nov 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment