After moving the filepath.Walk example to a standalone example file
in CL 122237 (so it could use a standalone function), godoc includes
the build tag annotation ("// +build !windows,!plan9" in this case)
in the runnable example. The example runs correctly, but the
annotation might be confusing for new users.
Change the behavior so that godoc skips these annotations when
displaying examples.
To avoid false positives in older versions of "go vet", which are still used
on the build dashboard, we avoid using a multiline string in the test.
Fixesgolang/go#26490.
Change-Id: I1da4b3b7e1e5a85a76773e25d9355b3f92479c19
GitHub-Last-Rev: bc5ed29bd368e5bcf11fed7a0c7f14b872fef065
GitHub-Pull-Request: golang/tools#42
Reviewed-on: https://go-review.googlesource.com/126256
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
We ask the underlying tool to produce export data if needed, but if it
cant we should fall back to source rather than just failing.
Change-Id: I376d41b4c8ad4d3c1aef3ca4ab4e3d0466b83b56
Reviewed-on: https://go-review.googlesource.com/126875
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
go list has been changed so that when -tests is added it reports the
test packages as well as the test mains in the initial set.
This fixes all the tests that assumed the old behaviour.
I changed the test that checked the initial set to check the entire
graph because the comparison became unreadable with the expanded set,
and this seemd like a nicer standardised way to check the behaviour.
Change-Id: I69404f8ef77cd092b0f02011a7789db71bee9b47
Reviewed-on: https://go-review.googlesource.com/126796
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Ensure that the filename passed via ?download= matches the given
regexp before showing the command-line instructions to download it.
Change-Id: Ieb7c6912409474f31637ff1193fd195eb9f172b3
Reviewed-on: https://go-review.googlesource.com/126717
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Add the Flags field to the Config struct in packages to provide a way
for users to pass along additional information to the underlying query
tool.
Since users that need Flags will already know something about the build
system they are using (and flags will vary depending on the underlying
build system), they can pass through the flags that they need for that
build system.
For example, build tags should be passed through using the Flags field in go build,
using "-tags=".
Change-Id: Ia65bf0d003db2f6d9aaad6cd09c602f4bc5bf3e3
Reviewed-on: https://go-review.googlesource.com/125302
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
If a 'word' provided to go/packages' Load function starts with contains,
go/packages will interpret that word as the package containing the given
file.
For example:
packages.Load(config, "contains:/usr/local/go/src/fmt/format.go")
would load the fmt package from the Go installation at /usr/local/go.
This implementation uses "go list ." in the directory the file is
contained in to find the package, but this won't work in the module
cache. We plan to add support to go list directly to help find the
containing package. Then, because we won't need to change directory,
go list will have knowledge of the correct vgo root module, and will
be able to surface correct results.
Change-Id: I6bff62447c12f13dae5e4c0c65f729d9f271c388
Reviewed-on: https://go-review.googlesource.com/126177
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This reverts commit faa8a71ab5.
Reason for revert: +build tag in test causes build to fail :(
Change-Id: I8942a6dcc29faaceada23b63ba80ea881b3b2ca6
Reviewed-on: https://go-review.googlesource.com/126195
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
After moving the filepath.Walk example to a standalone example file
in CL 122237 (so it could use a standalone function), godoc includes
the build tag annotation ("// +build !windows,!plan9" in this case)
in the runnable example. The example runs correctly, but the
annotation might be confusing for new users.
With this change, godoc skips these annotations when displaying examples.
Fixesgolang/go#26490.
Change-Id: Ice3d6a2ce4db5b5176c9c6fcabc01b69c323016d
GitHub-Last-Rev: 52beabd3d2a9cb9a556bfa3bd998a2e31ac96960
GitHub-Pull-Request: golang/tools#40
Reviewed-on: https://go-review.googlesource.com/125040
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Test that the import graph for packages in the GOPATH that use vendoring
are correct and are keyed by the import path as it appears in the source
file.
Change-Id: Ibf9a516b4bfcc9f2d45f349d2ae49a0dbf958e30
Reviewed-on: https://go-review.googlesource.com/125298
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Paths to files in a Package should exist and be absolute.
Check that both GoFiles and OtherFiles are absolute paths.
Change-Id: I381830425ef313a91fa49be4d1751631d0a3a0c8
Reviewed-on: https://go-review.googlesource.com/125536
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
The go/loader based implementation was too different. Instead
Just call go list twice to get all the dependencies. This immediately
enables more functionality.
Change-Id: I22883492e996133bc61664314318c5e0a9cc10dc
Reviewed-on: https://go-review.googlesource.com/125939
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
It got broken when we renamed all the modes, and because it is just an
example binary it is not testsed.
Change-Id: Ia6608af574d0abebb4fe0d967e1bed88af6563bd
Reviewed-on: https://go-review.googlesource.com/125937
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This separates the go list specific behavior from the generalised go/packages
loading behaviour, to enable alternate build system back ends.
Change-Id: I07e7649f8f2afc7470a3ee3d0d743cbbcc6f713e
Reviewed-on: https://go-review.googlesource.com/125715
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
After a discussion in cl/125535 this is a proposal to clean up some
internal function signatures that were becomming unwieldy.
Change-Id: I37a9e525ab18dface9ea9fb0b0ec68ac942ee632
Reviewed-on: https://go-review.googlesource.com/125659
Reviewed-by: Michael Matloob <matloob@golang.org>
The test was looking for strings found in specific Go versions
without checking for the actual Go version running the test.
Used ReleaseTags to check whether the current go version should
execute a test or not.
P.S. The version info is inferred from the binary running the test.
But the test builds godoc using the "go" binary in $PATH. In case
one is testing different go versions, please ensure to run tests
by changing the $PATH variable to point to different go versions,
rather than using a custom go binary in a different path.
Fixesgolang/go#26531
Change-Id: I16dda81518021e865e79c9c29fc2d9e8a83e7057
Reviewed-on: https://go-review.googlesource.com/125755
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
If go list fails because it doesn't support the new flags added
for Go 1.11 (which will be also released in Go 1.10.4) try again
using the Loader to approximate the packages requested.
This implementation is incomplete. It will never support test packages
because of the two phase test loading process of the Loader. It
also doesn't reliably have access to export data so it will
always do an upgraded whole-program query. But we'll try to get
the best level of support we can for the go/packages interface
given the limitations of the loader.
Once Go 1.12 is released, we'll delete this support. By then, most
Go users should have at least switched to Go 1.10.4.
Change-Id: I5248e20980032695a86b052caa9ff368ecf7b142
Reviewed-on: https://go-review.googlesource.com/125616
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Collapse the main entry points to the single Load function.
Make public the Mode enumeration in the Config.
Add a lowest level mode that does not do the import graph.
Remove PkgPath.
Remove the DisableCgo option.
Rename some fields of Package:
Srcs -> GoFiles
OtherSrcs -> OtherFiles
Type -> Types
Files -> Syntax
Info -> TypesInfo
delete the All function
Change-Id: I54e5dc3ca5cb0b7e33fe6aa6f70cc66e18ea8cac
Reviewed-on: https://go-review.googlesource.com/125535
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This makes Package a struct we can re-use in other places/algorithms.
Change-Id: I2e095a624bf44223319ba1ea3d60deb727b38f81
Reviewed-on: https://go-review.googlesource.com/124855
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
I made a pass through the documentation trying to simplify
and make it more accessible to readers who are unfamiliar
with all the ins and outs of the implementation.
I also added TODOs about things I don't understand
and names that we should think about changing.
Change-Id: I633316bd407f3360eb8a683bc8d85fba93ca381e
Reviewed-on: https://go-review.googlesource.com/125305
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
We have not yet settled on the meaning of Package.IsTest, and more
deeply which packages are test and which are non test packages.
This change will remove Package.IsTest in the meantime to avoid
confusion. We may later add a boolean or some other way to distinguish
test and non-test packages.
Change-Id: If6b128f7914009fdd42b8bc3de3bff73c8f006cd
Reviewed-on: https://go-review.googlesource.com/124388
Reviewed-by: Russ Cox <rsc@golang.org>
Follow-up to CL 85396, which only did types, funcs, and methods.
This adds version info to struct fields (in the form of small
comments) if the struct field's version is different from the struct
itself, to minimize how often this fires.
Updates golang/go#5778
Change-Id: I34d60326cbef88c108d5c4ca487eeb98b039b16e
Reviewed-on: https://go-review.googlesource.com/124495
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Devon O'Dell <dhobsd@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change reads $GOROOT/api/go1.*.txt when godoc starts and caches
information about which versions of Go introduce functions, types, and
methods. This information is displayed currently only in HTML output.
Functions, types, and methods introduced as part of Go 1 are not
annotated, as their presence at that version is implied.
This change does not address constants or variables, and completely
ignores the syscall package. The former are future work, the latter is
likely an exercise in futility. In all cases, this is because the story
around displaying the version information is not well developed.
Fixesgolang/go#5778
Change-Id: Ieb3cc0da7b18e195bc9c443f14fd8a82e8b2bbf8
Reviewed-on: https://go-review.googlesource.com/85396
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Devon O'Dell <dhobsd@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change adds optional Dir string and Env []string options
that are passed through to the build system's metadata query.
As with exec.Cmd, the defaults are inherited from the parent
process.
Options.GOPATH is gone. If the client needs to override
GOPATH, they must use Env, but typically the inherited environment
is correct.
The tests not longer use os.Chdir.
We now guarantee that Package.Srcs are absolute file names.
Added test for Options.Dir and relative patterns.
This is a copy of golang.org/cl/123777, which had a merge conflict.
Change-Id: I301724581f3d8c712ea78fa5ab5cabd909940dca
Reviewed-on: https://go-review.googlesource.com/123777
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
In the go build system, test packages and executables do not have a
name distinct from the package under test; they are implied, so
"go test fmt" means build those packages but "go build fmt" does not.
This change adds a Tests boolean option to indicate that implied
tests are desired during pattern expansion.
It has no effect on build systems that have explicit names
for tests, such as Blaze/Bazel.
The gopackages diagnostic tool now has a -test flag.
Change-Id: I424f343958c4286539e518d5f30067da19a57f3b
Reviewed-on: https://go-review.googlesource.com/123775
Reviewed-by: Michael Matloob <matloob@golang.org>
We should add support for older go commands using the multiple-calls
approach of earlier drafts of go/packages.
Also, tag tests for go1.11 to make 1.10 builder happy.
Change-Id: Ia04979528af25cbcd4b4fa5b21cb91d014d530c1
Reviewed-on: https://go-review.googlesource.com/123756
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This package defines a new API for applications that need information
about Go packages, such as their source files, tests, dependencies,
and (optionally) typed syntax trees. It is intended to replace both
go/build and golang.org/x/tools/go/loader with an API that is simpler
yet supports a range of build systems including 'go build', vgo,
Bazel, and Blaze.
This CL contains the API, the "go list"-based implementation, and some
basic tests. More tests, more features as described in doc.go, and
implementations for bazel and blaze will follow.
Read doc.go for orientation and a list of open questions.
Change-Id: Ib39f15b5e4e2f854553e7185fec5cf135641ffb0
Reviewed-on: https://go-review.googlesource.com/116359
Run-TryBot: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
This is reapplying CL121995 after rolling back the change to the importing
methods. There is still a need for a flag to control tags.
The original CL decription:
The feature has been requested but, like build tags in general,
only works in a directory, not when files are specified explicitly.
Unlike the build tools, report when the feature is misused like this
to avoid confusion.
Fixesgolang/go#9449
Change-Id: I732627d5f2e6323367e3bdd5de746923868890a9
Reviewed-on: https://go-review.googlesource.com/122537
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The fix in golang/go#23709 introduced a separate bug where extra blank
lines were sometimes inserted. This fixes that newly introduced bug.
Fixesgolang/go#26246
Change-Id: I78131cc1d01ae246922ed9e4336ebb31d1c6cfa1
Reviewed-on: https://go-review.googlesource.com/122538
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This will be true in general for Go modules, so it's the right fallback.
Note that if the package can be found in GOPATH, the code still
uses the actual package name from GOPATH, so this only changes
the fallback path. The fallback path is what currently executes
when using modules (because they are not in GOPATH).
Change-Id: I3d48517583eae9431e139371d363ce354c89340a
Reviewed-on: https://go-review.googlesource.com/122616
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
A follow-on to CL122095, which normalized the marker but
did not include the arguments.
Output now looks like this:
// Code generated by goyacc -o expr.go -p expr expr.y. DO NOT EDIT.
Change-Id: I20577ea90943516f45478d778353b5bd2f485dfa
Reviewed-on: https://go-review.googlesource.com/122540
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Roll back my two recent changes. Stringer is now very slow again,
but works in most use cases.
My git foo is insufficient to do this as a revert, but it is a by-hand
reversion of CLs
https://go-review.googlesource.com/121884https://go-review.googlesource.com/121995
See the issue for a long conversation about the general problem.
Update golang/go#10249
Update golang/go#25650
Change-Id: I7b6ce352a4c7ebf0977883509e9d7189aaac1251
Reviewed-on: https://go-review.googlesource.com/122535
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Add "// Code generated by goyacc. DO NOT EDIT." to the top of the
generated go output file.
Fixesgolang/go#26158
Change-Id: I5dd66af9cd8ccccd27440886c55cd604686472e3
Reviewed-on: https://go-review.googlesource.com/122095
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
The feature has been requested but, like build tags in general,
only works in a directory, not when files are specified explicitly.
Unlike the build tools, report when the feature is misused like this
to avoid confusion.
Fixesgolang/go#9449
Change-Id: I079d363c5eeb5bc647fd2f0f3d88d28d630644d8
Reviewed-on: https://go-review.googlesource.com/121995
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Revert "cmd/stringer: use source importer when available"
This reverts CL 40403.
The idea is to avoid type-checking and use just parsing, which should be
enough for stringer.
Separately reopening golang/go#10249 because the original change closed that issue,
but the change is itself causing other problems as described in the discussion
at golang/go#25650.
This reversion restores the old behavior of stringer and will be followed
with other fixes if they can be worked out.
Change-Id: I8404d78da08043ede1a36b0e135a3fc7fdf6728d
Reviewed-on: https://go-review.googlesource.com/121884
Reviewed-by: Ian Lance Taylor <iant@golang.org>
The current implementation uses the added import specs EndPos to fixup
the comments position after import specs is sorted. If two or more
import specs have the same EndPos, a comment associated with one of them
is always added to the last import spec.
This commit uses the current import spec position to compute new
position for next import spec. So there is never two or more specs have
the same EndPos.
Fixesgolang/go#23709
Change-Id: I60ace9431d871e94a2b3d90892aa80d0671aeea0
Reviewed-on: https://go-review.googlesource.com/121878
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Otherwise it was just blank. With this CL, this URL should start rendering docs:
https://tip.golang.org/pkg/syscall/js/
Tested locally.
Change-Id: I2d9b7286f374e9372be372987bb5d12ce5044ce9
Reviewed-on: https://go-review.googlesource.com/121315
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Richard Musiol <neelance@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
...to show information about indirectly mentioned packages.
Change-Id: Ib74b56493861bf41d9720760e76ace186efae2ea
Reviewed-on: https://go-review.googlesource.com/121195
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
https://go-review.googlesource.com/c/go/+/120875 changed the name
of types.NewInterface2 to NewInterfaceType. Adjust x/tools code to
match new API.
For golang/go#25301.
Change-Id: I21e13566f7c88591a16ce461cb4cce8901980b05
Reviewed-on: https://go-review.googlesource.com/120895
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>