This change replaces the env package with a new golangorgenv package.
The previous env package existed primarily to configure the godoc
instance that was running golang.org. By now, the golang.org website
has been factored out to x/website, which has its own env package,
but ends up still using this env package indirectly via x/tools/godoc.
The goal of this change is to make env available for other services
that run on subdomains of golang.org, so they can continue to safely
rely on the x/tools/playground, which will be modified in the next
commit to also use the new golangorgenv.
The golangorgenv package replaces the IsProd function with a more
specific one. Start using it in packages x/tools/{,cmd}/godoc. Also,
re-arrange the order of checks to give the host suffix check higher
priority than the environment variable check. This way, if the
environment variable isn't set, the host suffix check gets a chance
to run.
When getting the value of "X-AppEngine-Country" header, use its
canonical format "X-Appengine-Country" to avoid an allocation.
This does not change behavior.
Updates golang/go#30486
Change-Id: I97b47211a45ca0351f31fcb4fa6d408a4b0c4c7c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165459
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Instead of calling packages.Load on every character change, we reparse
the import declarations of the file and determine if they have
changed. We also introduce a metadata cache that caches the import
graph. This is used in type-checking and only updated on calls to
packages.Load.
Change-Id: I7cb384aba77ef3c1565d3b0db58e6c754d5fed15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165137
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Separate out functions to make the code more readable.
Change-Id: I4c48a8343ba5666de375c43499420bdf244aafd1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165022
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
It is difficult to debug gopls in combination with the incremental
changes feature. Because gopls is slow (caching CL is in progress), it
seems like the incremental changes can sometimes produce strange
behavior. Disable it for now until we can prioritize work on it.
Change-Id: I931aa39756f198d1af21dca359acc83ca3392c4c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165023
Reviewed-by: Michael Matloob <matloob@golang.org>
This reverts CL 164837 (0f64db555a)
Reason for revert: breaks vetall against tip (and thus go tip's trybots)
Change-Id: I5109691481f44a9807675a6139f1619a03b0c58d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165039
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Also, separate type-checking logic into its own file.
go/packages returns import cycle errors anyway, so we just return them instead.
Change-Id: I1f524cdf81e1f9655c1b0afd50dd2aeaa167bb2f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165021
Reviewed-by: Michael Matloob <matloob@golang.org>
Add the deepequalerrors analyzer to the vet command.
I don't really understand the comment in the file. I do want the analyzer to run
when the user explicitly calls go vet, but not automatically via go test.
I'm not sure this CL captures that.
Change-Id: Ie78ef110c7828ccbcc86735442c81dbb516dcf18
Reviewed-on: https://go-review.googlesource.com/c/tools/+/164837
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
It's possible to use a type which implements fmt.Formatter without
importing fmt directly, if the type is imported from another package
such as math/big.
On top of that, it's possible to use printf-like functions without
importing fmt directly, such as using testing.T.Logf.
These two scenarios combined can lead to the printf check not finding
the fmt.Formatter type, since it's not a direct dependency of the root
package.
fmt must still be in the import graph somewhere, so we could search for
it via types.Package.Imports. However, at that point it's simpler to
just look for the Format method manually via go/types.
Fixes#30399.
Change-Id: Id78454bb6a51b3c5e1bcb1984a7fbfb4a29a5be0
Reviewed-on: https://go-review.googlesource.com/c/163817
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Our tests depend on the dependency graphs of the errors which
is not guaranteed to have a stable dependency graph across go versions.
Especially because we're planning on making changes to the errors package
in Go 1.13.
Instead, use the container/list package, which is completely useless
and won't be changed (unless/until Go gets generics).
Fixesgolang/go#30448
Change-Id: Ia5f4853d1da336dde2f025b1dd5e1d6223571dd6
Reviewed-on: https://go-review.googlesource.com/c/164298
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The new error value proposal (https://golang.org/design/29934-error-values)
adds stack frame information to the errors produced by errors.New
and fmt.Errorf. This will break any test that compares errors
with reflect.DeepEqual.
This vet check finds any call to reflect.DeepEqual both of whose
arguments are of type error, or are of a type that can store
of value of type error.
Change-Id: I55939339344ed5b4f61557a7296734a710211918
Reviewed-on: https://go-review.googlesource.com/c/162939
Reviewed-by: Damien Neil <dneil@google.com>
This change adds severity levels to source.Diagnostics, allowing us to
pass this information along to the LSP. This allows compiler errors to
show up in red, while vet results show up in green.
Change-Id: I2bc0b27ed6629f987c05affe00fdbe4b9bfb3b3e
Reviewed-on: https://go-review.googlesource.com/c/164299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Address a few irritating glitches in the go list debug logging.
- Print a fully runnable command line, with args like "a" "b" "c"
instead of [a b c].
- Include stderr in the debug logs for cases where the command fails.
- Print the correct PWD environment var from cmd instead of cfg.
Change-Id: I58e77b370baf8378a21377b81ee2ba5d21a557ab
Reviewed-on: https://go-review.googlesource.com/c/163497
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
We left the golsp binary for a few weeks after migrating to gopls.
Remove it now.
Change-Id: Iad44a3c9cf1427be6e2d81cc7a8e9fc60ef6ee50
Reviewed-on: https://go-review.googlesource.com/c/163779
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Switch from test to use net/rpc instead of text/scanner, since net/rpc
is a frozen package that is guaranteed not to change.
Change-Id: I6ece679bc16737fa9a75ac896f9eb2190317a498
Reviewed-on: https://go-review.googlesource.com/c/163204
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Because diagnostics computations happen in parallel, we were getting
concurrent map writes by keeping one cache.
Change-Id: Ifa5adffe14c509168c9f8c5cb012f3fcd3a32441
Reviewed-on: https://go-review.googlesource.com/c/163161
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
text/scanner was used in tests because it was unlikely to change between
releases, but of course, a line number changed, breaking the tests. Use
a different constant for testing that remained on the same line.
Change-Id: I41425728e0918ffe388b3c8df9fd71e8371eb38e
Reviewed-on: https://go-review.googlesource.com/c/163197
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
These packages existed only to power cmd/godoc for the purpose of
serving the golang.org website. That functionality has moved into
x/website as part of golang/go#29206. x/website has become the
canonical source of golang.org in CL 162157, the golang.org-serving
code was removed from cmd/godoc in CL 162400, and these packages can
be deleted too now.
This removes the last dependency on the cloud.google.com/go module,
which results in a significant reduction of the number of indirect
dependencies in x/tools (this is due to issue golang/go#29935, which
affects the current version of the cloud.google.com/go module).
Run go mod tidy (using Go 1.12 RC 1).
Updates golang/go#29206
Updates golang/go#29981
Change-Id: If07e3ccae8538b3ebd51af64b6af5be5463f4906
Reviewed-on: https://go-review.googlesource.com/c/162401
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Channing Kimble-Brown <channing@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
The code to serve the golang.org website has been moved to
the golang.org/x/website sub-repository. x/website has become
the canonical source of the golang.org website as of CL 162157,
and so this code can be removed from here now.
This has the benefit of removing some external dependencies
that were only used by the website in production mode, and
in turn enabling x/tools to be a smaller tools-related module.
In future changes, the golang.org/x/tools/cmd/godoc command
will be reduced in scope to be a tool for serving Go package
documentation only, not the rest of the golang.org website.
Run go mod tidy (using Go 1.12 RC 1).
Updates golang/go#29206
Updates golang/go#29981
Change-Id: I61fd25627d0506901b04688dea8d8c9da9fe8f04
Reviewed-on: https://go-review.googlesource.com/c/162400
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Channing Kimble-Brown <channing@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
In CL 149609, a file was added to
src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/patch.go
to override the behavior of the V flag for cmd/vet.
That modification causes the behavior of cmd/vet to change when a
pristine copy of x/tools is vendored in, and module-mode vendoring
will only support pristine copies (see golang/go#30240).
Instead, allow cmd/vet to override the V flag by defining its own V
flag before it invokes unitchecker.Main.
Tested manually (by patching into cmd/vendor).
Updates golang/go#30240
Updates golang/go#30241
Updates golang/go#26924
Updates golang/go#30228
Change-Id: I10e4523e1f4ede94fbfc745012dadeefef48e927
Reviewed-on: https://go-review.googlesource.com/c/162989
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
When rendering the documentation of the fake package builtin,
there are two PageInfoMode flags that always get set,
regardless of what the user has provided via the ?m= query parameter.
They are:
• NoFiltering
• NoTypeAssoc
This is being done to make the documention of this special package more
usable and helpful (see golang/go#6645).
This change modifies the way those flags are set, so that any additional
flags the user may have set are no longer cleared. This makes it possible,
for example, to use ?m=src to view the source, as it is for all other
packages.
Also elaborate more about this behavior in the comments.
Fixesgolang/go#30300
Updates golang/go#6645
Change-Id: I77728bd2683191b97d8f58f19092f2833dfc474c
Reviewed-on: https://go-review.googlesource.com/c/162983
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This is a followup to CL 141397, which removed CLI support from the
godoc command for golang/go#25443. This change removes a few more
CLI-related fields from Presentation type, which are now unused.
It also removes the unused and no longer documented (since CL 143077)
NoHTML PageInfoMode.
Updates golang/go#25443
Change-Id: Ia4147515052889570e2f050e3c2394689d3c5d6c
Reviewed-on: https://go-review.googlesource.com/c/162982
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
This change adds a small number of integration tests for the godoc
command's -url flag, confirming that the behavior matches the local http
server tests in those cases. It fixes three bugs which prevent the -url
flag from working currently.
Fixesgolang/go#30259Fixesgolang/go#30260Fixesgolang/go#30261
Change-Id: I0ca1fe81f9f186d0ca02b31674cc8654af434e92
Reviewed-on: https://go-review.googlesource.com/c/162907
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
The documentation of the "flat" presentation mode was removed
inadvertently as part of post-CLI-removal documentation cleanup
in CL 143077. The FlatDir flag still exists and is supported.
This change re-adds it to cmd/godoc documentation.
Also fix a typo in the "src" presentation mode description.
Updates golang/go#25443
Change-Id: If4705d70bc5eafee92cdfd52409aca4606a0efd7
Reviewed-on: https://go-review.googlesource.com/c/162984
Reviewed-by: Agniva De Sarker <agniva.quicksilver@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This change adds a go.mod and go.sum file to the tools repo, following the
requirements stated in bcmills's comment here:
https://golang.org/issue/28136#issuecomment-462971974. It's
important to note that we will not be
adding versions to the repo for now.
The change was generated by running "go mod init" and "go mod tidy" using Go
1.11.5 in the top-level directory of the tools repository.
The tools repo has some extraneous dependencies, but they will be removed soon
(we expect a couple of weeks). At that point, our go.sum should shrink to a
small handful of entries.
Updates golang/go#28136
Change-Id: Ie7802d8d70094a855b112ad0507a47036cb81ba0
Reviewed-on: https://go-review.googlesource.com/c/162397
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Make sure to use the import path in the packages cache, rather than the
package path. Also, prefetch dependencies.
Change-Id: I0de3942346aa6755dbe904f973aca51d26ba0306
Reviewed-on: https://go-review.googlesource.com/c/162577
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Use packagestest to copy the code in the test directory to a GOPATH
in a temporary directory, so the test doesn't depend on accessing
the user's GOPATH.
Change-Id: I5895ad97ab478625048fdcd330ef516df9c428d3
Reviewed-on: https://go-review.googlesource.com/c/162777
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
These tests tried to access the user's GOPATH, which can't work if you're
running from a module! So use packagestest to set up a fake GOPATH.
Also remove a TODO that's never going to be done because we won't
be making more investments in go/build.
Change-Id: I379c74345ace91e6c4282a42ff62106bf325d0e0
Reviewed-on: https://go-review.googlesource.com/c/162757
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
It was using a mix of stdout and stderr. Most users won't notice, but
it's inconsistent for no apparent reason. In particular, I noticed as
some of my tool execution tests started failing.
Change-Id: I9afe5f5bed0a575d3ba20e8dc1cc593c35565cf9
Reviewed-on: https://go-review.googlesource.com/c/162717
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
Like the previous change to the FIle interface, we treat Read as if it were an
accessor, we remember the content part but not the error part, and we may fill
it in asynchronously, so this change makes it explicit.
In the future we should probably trap the error in the read and push it back
through another channel though, it will be the root cause of later errors.
Change-Id: I3d374dd557178b4e8c5544813cd77f5c0faefe5b
Reviewed-on: https://go-review.googlesource.com/c/162403
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This means the test excercise modules and gopath workspaces. That will
allow this test to run once tools becomes a module...
The test still doesn't pass under Windows.
Change-Id: Ic5e46b9b92c5aac909a6ceb56f30851832fc09ac
Reviewed-on: https://go-review.googlesource.com/c/162404
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
The ExecuteCommandParams field is optional, so it can be set to nil.
Change-Id: If440257e6b64ce5189b0a4b39a6ed7fc867da5af
Reviewed-on: https://go-review.googlesource.com/c/162402
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
we don't really use them, only generate them in cases where the failure is way more fundamental, and then also fail
to remember them for the next call to the same accessor. Better to not have them.
Change-Id: I0e8abeda688f5cc2a932ed95a80d89225c399f93
Reviewed-on: https://go-review.googlesource.com/c/162399
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Added this check in golang.org/cl/161077 and unintentionally removed it in
golang.org/cl/161497.
Change-Id: I66bd2b616f4b41c25f134f6e9457c97bbcd3f72b
Reviewed-on: https://go-review.googlesource.com/c/162398
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Small changes to handle the last line in the diff library, LSP tests,
and diff to text edits conversion.
Fixesgolang/go#30137
Change-Id: Iff0e53a04c2dabf6f54eb7c738b4c0837f16efba
Reviewed-on: https://go-review.googlesource.com/c/162217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This change adds a copy of the parseFiles function from go/packages for
file parsing. Also fix crash caused by lack of TypeSizes from
go/packages.Load when using LoadImports mode.
Change-Id: Ie8c3c653679ab81da45905c6839de7e63966d84c
Reviewed-on: https://go-review.googlesource.com/c/161670
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
This CL is based on the work and discussion in CL 24969 and CL 32392.
It simplifies the code further and makes trybots pass on Windows.
Also update the documentation and implementation of the subpackages
function slightly to make it more clear what it's doing.
Background
CL 24943 has made progress on fixing rename.Move behavior on Windows,
but hadn't re-enabled TestMoves at the time. CL 24969 attempted to do
so, but the tests weren't passing and it didn't get merged at the time.
Since that time, CL 65672 has fixed a bug in the subpackages function.
As a result, it's possible to simplify code in Move now.
The subpackages function returns a set of packages in the given srcDir
whose import path equals to root or has "root/" as the prefix.
After CL 65672, it correctly filters out ones that are not true
sub-packages of root. That's why it's not necessary to try to append
a trailing separator when doing the string replacement in Move now.
Given subpackages reports their import paths (always '/'-separated),
not filesystem paths, it's not necessary to use filepath.ToSlash either.
Updates golang/go#16384
Change-Id: Ia808fbaaeffe44ea1e51d7cc3ed9499bc2b438cf
Reviewed-on: https://go-review.googlesource.com/c/161777
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
This changes the analysis code from that which was in unitchecker.go
to that in checker.go, so we can run actions that get facts for dependencies
concurrently.
Adds the rest of the traditional vet suite to the LSP.
TODO(matloob): test that facts are actually propagated between packages
Change-Id: I946082159777943af81bcf10e503fecc99da521e
Reviewed-on: https://go-review.googlesource.com/c/161671
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>