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/doc: duplicated component in package path confounds partial package matching #25478

Closed
splace opened this issue May 21, 2018 · 4 comments
Closed
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@splace
Copy link

splace commented May 21, 2018

What version of Go are you using (go version)?

1.10.2

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

go get github.com/go-gl/gl/v3.3-core/gl
go doc gl

What did you expect to see?

documentation for gl package

What did you see instead?

doc: no buildable Go source files in ../go/src/github.com/go-gl/gl
exit status 1
(notice path truncated)

temp fixed by renaming /go/src/github.com/go-gl/gl -> /go/src/github.com/go-gl/GL

@AlexRouSg
Copy link
Contributor

If you just call go doc gl there would be no way for it to know which gl package you meant so it just selects the first found "package" and that so happens to be github.com/go-gl/gl which contains no source files.

So the proper way to use go doc would be to use the full import path go doc github.com/go-gl/gl/v3.3-core/gl

@splace
Copy link
Author

splace commented May 21, 2018

understood, and this isn't hugely important, but i do think go's tooling is one of its bright points, so..

"github.com/go-gl/gl" isn't even a package, there is only one package 'gl' installed, doesn't seem that hard for it to just keep going until it found a package, or, seems like a tree search leaf first would work, mostly.

also; if i already had a package 'gl' which was reporting documentation with 'gl', installing the above package, as a side-effect, breaks that, that's surprising to me, i would have hoped package installation was completely isolated. in some sort of shared development environment i might not be aware of other installs until it breaks.

@bcmills bcmills changed the title duplicate import path items misdirects doc tool cmd/doc: duplicated component in package path confounds May 23, 2018
@bcmills bcmills changed the title cmd/doc: duplicated component in package path confounds cmd/doc: duplicated component in package path confounds partial package matching May 23, 2018
@bcmills
Copy link
Contributor

bcmills commented May 23, 2018

Seems like it should be a fairly simple fix: if the directory suffix matches but the path can't be imported, keep searching.

Some starting points, if you'd like to give it a try:

go/src/cmd/doc/main.go

Lines 242 to 247 in 5776bd5

// See if we have the basename or tail of a package, as in json for encoding/json
// or ivy/value for robpike.io/ivy/value.
path, ok := findPackage(arg[0:period])
if ok {
return importDir(path), arg[0:period], symbol, true
}

go/src/cmd/doc/main.go

Lines 341 to 357 in 5776bd5

// findPackage returns the full file name path that first matches the
// (perhaps partial) package path pkg. The boolean reports if any match was found.
func findPackage(pkg string) (string, bool) {
if pkg == "" || isUpper(pkg) { // Upper case symbol cannot be a package name.
return "", false
}
pkgString := filepath.Clean(string(filepath.Separator) + pkg)
for {
path, ok := dirs.Next()
if !ok {
return "", false
}
if strings.HasSuffix(path, pkgString) {
return path, true
}
}
}

@bcmills bcmills added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 23, 2018
@bcmills bcmills added this to the Unplanned milestone May 23, 2018
@gopherbot
Copy link

Change https://golang.org/cl/114295 mentions this issue: cmd/doc: continue to search when package import fails

@golang golang locked and limited conversation to collaborators Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants