Change-Id: Ie127474e5d1e1d71177e0e38d8a4cba2ce415db3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188497
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Get quick fixes for the diagnostics related to import errors. These
fixes add, remove, or rename exactly one import.
This change exposes the individual fixes found by the imports package,
and then applies each of them separately to the source. Since applying each
fix requires a new ast anyway, we pass in the source to be parsed each time.
Change-Id: Ibcbfa703d21b6983d774d2010716da8c25525d4f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188059
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Fix typos and fix descriptions of methods where the behavior described
in the comment is not implemented by that method.
Change-Id: I2c34caff43399dcb4f0e5e41b67189d8d8404fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184697
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
goimports should not attempt to load package names for an empty list
of packages. 'go list' interprets an empty argument list as '.', which
may or may not be a package.
Fixesgolang/go#33175
Change-Id: Id8df148432437295905c52f2d5fb73d890277569
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188379
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
The "Create" and "Delete" WatchKind values were missing from the
generated code because their names were colliding with other
constants. Add "WatchKind" to go.ts prefix map to disambiguate.
Updates golang/go#31553
Change-Id: I60269969831c0822896e87b3f2332ded71748f42
GitHub-Last-Rev: 6d85cf9b3865ba5af0b5ec7f90358e5734ed9451
GitHub-Pull-Request: golang/tools#136
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186097
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Set the server state to initialized so that dynamic configuration
requests will be sent to the client.
Rename the mutex that guards state. The state field was previously named
initialized, so it only makes sense to similarly rename the mutex that
guards the state field.
Always unlock stateMu before calling other functions so that callees
that need to check state can acquire the lock.
Change-Id: Ia5592ca1dedfc6f004ae6b61548890624ae98d59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188097
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
String matching is used to find diagnostics that could be fixed by
organizing imports. Unused imports are of the form:
"X imported but not used"
"X imported but not used as Y"
Check that "imported but not used" is contained in the message to
include both named and unnamed imports.
Change-Id: I478d1fb239962e706eb1adf305b858fcc875b7f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188158
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
If the message is empty and there is and there is an error,
the description of the annotation should be the error message.
More info can be found here:
https://go-review.googlesource.com/c/tools/+/186679
Change-Id: Ica0a9cc132de912b2e14ab527baf4304f8b5d8ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188118
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
switch the ioLimit channel from a bool to a struct{} as the values
stuffed into the channel have no meaning.
A mix of consistency and comment cleanups in *importer.parseFiles.
sameFile is reported as unused, so removed, removing some now unused
imports.
The assignment to lit in *view.parseDeferOrGoStmt's for{} loop was
reported as ineffective.
Update the comment of fix a little for clarity.
Change-Id: I50f0442bfd7e4d0cc0e6fdadbf1f6272366a716c
Change-Id: I50f0442bfd7e4d0cc0e6fdadbf1f6272366a716c
GitHub-Last-Rev: 74d8a8bdb768a827db3c1fd1723a528818e222ee
GitHub-Pull-Request: golang/tools#109
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179957
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
The results of running 'go list -m' are only valid as long as the
current module and the modules in its replace directives do not
change their go.mod files. Store the 'go.mod' versions that are
used in the imports call, and reinitialize the module resolver if
they change.
Change-Id: Idb73c92b9e4dc243a276885e5333fafd2315134d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186597
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Packages with errors may still contain files that can be formatted.
Try to format the source of the files in packages that have errors.
This change will still not format files with parse errors.
Updates golang/go#31291
Change-Id: Ia5168d7908948d201eac7f2ee28534022a2d4eb0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/187757
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
strings.Trim treats the second parameter as a set of characters you
want to trim. It does not look for an entire string to trim.
This fix will maintain the current behavior, simply eliminating the dupe
character in the set.
Should we instead mean to really trim the entire string, this needs a
different fix.
Change-Id: Id3fa4105421819edc6a898efb1ffab26c8cea67a
GitHub-Last-Rev: 198e429869711ee1510fffe5a993acb07eff4502
GitHub-Pull-Request: golang/tools#142
Reviewed-on: https://go-review.googlesource.com/c/tools/+/187497
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
We should not be sending messages from within the telemetry worker. This does it in a new go routine now.
Change-Id: I55e3b6df04699b8e45bc37b99997463f45ee114e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186958
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Metrics will be added once the agent supports the json form.
Change-Id: I40f6790970311b020a7cab72474b71f4e2aa32e9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186679
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
The old code didn't stop after finding the fallthrough target, always
walking the entire list to the top. This would effectively break
fallthroughs, constructing an invalid graph, as the fallthrough target
would never be found.
The fix brings the loop condition in line with all the other
stack-walking loop conditions in the surrounding code, which abort
once the target block has been found.
Alternatively, the entire loop could been omitted, as 'fallthrough'
has to be the last statement in a case body and thus always refers to
the immediate element on the stack. However, since the builder already
handles malformed ASTs as gracefully as possible, it seemed better to
keep the loop and to construct a slightly less wrong graph in the
presence of malformed ASTs.
Before the fix, the following code
func fn(x int) {
for {
switch x {
case 1:
println("case 1")
fallthrough
case 2:
println("case 2")
}
}
}
would result in the following graph. Note the presence of an
undefined.branch block.
.0: # entry
succs: 1
.1: # for.body
x
1
succs: 4 6
.2: # for.done
.3: # switch.done
succs: 1
.4: # switch.body
println("case 1")
succs: 7
.5: # switch.body
println("case 2")
succs: 3
.6: # switch.next
2
succs: 5 9
.7: # undefined.branch
.8: # unreachable.branch
succs: 3
.9: # switch.next
succs: 3
After the fix, this graph is computed instead:
.0: # entry
succs: 1
.1: # for.body
x
1
succs: 4 6
.2: # for.done
.3: # switch.done
succs: 1
.4: # switch.body
println("case 1")
succs: 5
.5: # switch.body
println("case 2")
succs: 3
.6: # switch.next
2
succs: 5 8
.7: # unreachable.branch
succs: 3
.8: # switch.next
succs: 3
Change-Id: I3bb00eddec2a7da02cb929860f4c95cf477c848c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186857
Run-TryBot: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
A recent change to the go command broke these tests. Mark them as
go/packages incompatible for now, until we have time to fix them.
Updates golang/go#33175
Change-Id: Ib4c594bd032107fb1245bfe18fc80392fbab0730
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186838
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
These are hand written structs that when passed through the standard json
encoder produce output that mathches the json form of the open census protobuf
messages.
This allows us to talk to the agent without any extra dependancies.
Change-Id: I23d617018009520aad3832e0425ed0a53c51fd1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186678
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Save the packages found when scanning of the module cache.
The computed package may have a different import path due
to replace directives, so this needs to be updated
when the moduleResolver is initialized again.
Change-Id: Ib575fcc59b814ff263b431362df3698839a282f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186301
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
https://golang.org/issue/33157 explains the issues with overlays. The
gopls tests caught this bug, but the go/packages tests didn't, so modify
the go/packages tests correspondingly.
Change-Id: I8ea8e06e145aa2420655cbe4884e60f36acfad7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186299
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Also add enough support that using it from within the context of the lsp will
report back to the original client.
Change-Id: I081f157c289642454e9f0476747b2131dcd4e16c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185996
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
A detatched context ends up attributing all background work to the initialize
function.
Change-Id: I81206462752228d5ac81408fb1e3fb86ab36796e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186457
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
I dropped the line that added the stats to the context when merging the recent changes.
Change-Id: I66ab2958b0737360896b40bf30c5ca3c2cebbae5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186300
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This change adds a Logf field to the packages.Config.
Change-Id: I144a9a1e1181585bbe621898c4a3e6a007a38322
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185993
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
The imports ProcessEnv contains cached module and filesystem state. This change
allows gopls to use the same ProcessEnv and resolver across multiple calls to the
internal/imports library.
A ProcessEnv belongs to a view, because the cached module state depends
on the module that is open in the workspace.
Since we do not yet track whether the 'go.mod' file has changed, we
conservatively reset the cached state in the module resolver before
every call to imports.Process.
Change-Id: I27c8e212cb0b477ff425d5ed98a544b27b7d92ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184921
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This change removes the need for the ast and token fields on the *goFile
object. We switch to using source.ParseGoHandles on the package, which
means that we can easily access both the AST and token via the package,
which is already cached.
Change-Id: I5f78bbe09362f4d95eb15556617bdbd809a7a55d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185878
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
We only had the tracing on didChange before this
Change-Id: Iadec8a43d439931bf58925f149a1d32b3ae29c36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186199
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Noticed this because I was accidentally running these tests with Go
1.11.
Change-Id: Ic35d71bd1da9078b4bde6aa2ed62d54a8b95b0e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186298
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Refactors allpaths to print an adjacency list from "from" to "to", instead of
just the nodes. This allows other tools like modgraphviz to print the subgraph.
For example, the following command:
cd $GOPATH/src/cloud.google.com/go && \
go mod graph | \
digraph allpaths cloud.google.com/go golang.org/x/text@v0.3.2 | \
modgraphviz | \
dot -Tpng -o graph.png
Generates the following graph.png: https://user-images.githubusercontent.com/3584893/60481727-df0a8680-9c4b-11e9-8df9-c581d599edd1.png
Also splits out the allpaths tests into their own test, and adds many test
cases.
This is a breaking change. The previous behavior returned vertices; now it
returns edges. If you relied on the previous behavior, use:
my-application | digraph allpaths <from> <to> | digraph nodes
Change-Id: I2eb7c377f5fe1e1e90c5b74eaa78d5211192bb2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184337
Reviewed-by: Alan Donovan <adonovan@google.com>
There is a problem with this test failing in module mode only with the
tip of the go tree. Adding this file changes it from a pure overlay package
to one that has an extra file, which fixes it for now.
updates golang/go#33125
Change-Id: I87dae0b44691246a1f79df454afb190f944cc886
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186259
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
We recommend that gopls integrators apply the []TextEdit responses in
reverse order to get a correct resulting document. This strategy works
when the response is already sorted. Have gopls return sorted []TextEdit
for each file.
Fixesgolang/go#33123
Change-Id: Ib570881c9623695d2ae3194fa8a97b0a681a3250
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186258
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
And purge the loggers from the view and session.
Change-Id: I262958f340e9a5ac9cc9b3db9e9910381e457478
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185989
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
We merge them into a single interface and support multiple of them rather than
just one.
This will allow us to stack handlers with different responsabilities and extract
some core logic (like tracing) out to a handler where it belongs.
Change-Id: I6aab92138550c5062fcb1bed86171e0850d1eb38
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185879
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
In internal/lsp/link.go appeared a bug that error message is printed
even if error is not apeared. this commit is fixing this behaviour.
Fixesgolang/go#33087
Change-Id: I932546867d78c5c0c3d2c9dabd13287f6837f458
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186037
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>