1
0
mirror of https://github.com/golang/go synced 2024-10-01 12:48:33 -06:00
Commit Graph

3289 Commits

Author SHA1 Message Date
Koichi Shiraishi
028e009f40 internal/lsp: fix typo on license year
Change-Id: I3cd4a55c633fd7a154d35fd3669e13562295242b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181897
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-06-12 17:47:02 +00:00
Rebecca Stambler
7db4ac6d26 internal/lsp/debug: add newlines to debug messages
Change-Id: Ie8232bf857b8a277abb789e3788a6b6e12048731
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181938
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-12 17:36:44 +00:00
Rebecca Stambler
ecc01b7716 internal/memoize: document the complicated parts of the memoize package
This change is more of an exercise for myself to better understand the
implementation of the memoize package. It adds detailed documentation
for the get function in particular.

I also modified the tests to use a table-driven test format. I'm not
certain if this was the right approach (in case we want to add a
different type of test case in the future), but for now, it seems to
work fine.

Change-Id: I191a3b65af230e0af54b221c9f671582adec6c79
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181685
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-12 16:51:35 +00:00
Muir Manders
d73e1c7e25 internal/lsp: fix errors when adding new file to existing package
Previously when you added a new file to an existing package, the new
file would get stuck with the "no package for file" error until you
saved the file and then made changed a different file in the
package. There were two changes required to fix the errors:

First, we need to invalidate the package cache when a new file is
added to a package so that the package will actually re-parse and
re-type check. We now notice if file names changed when updating a
package's metadata and invalidate the package cache accordingly.

Second, when dealing with overlay (unsaved) files, we need to map
the *goFile to the package even if we fail to parse the
file (e.g. the new file fails to parse when it is empty). If we don't
map it to the package, the package won't get refreshed as the file is
changed.

Fixes golang/go#32341

Change-Id: I1a728fbedc79da7d5fe69554a5893efcd1e1d902
GitHub-Last-Rev: e7c3d4c1f8f73b12c87ee76d868cc04893e55808
GitHub-Pull-Request: golang/tools#111
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181417
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-11 22:22:05 +00:00
Rebecca Stambler
3c1b0c2805 internal/lsp: fix panic when file deleted
Change-Id: I6eb7e5ae7fb9de74d5a3fb42031adb4e933d99d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181680
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-11 22:01:47 +00:00
Rebecca Stambler
6050b95026 internal/lsp: create types for package paths and IDs
This change replaces the strings that were previously used for both the
ID and package path fields. This is a precursor to the change that will
replace the uses of package path with package ID.

Change-Id: I353e98aedede9b85c7a183fdd49048ff43b1e26d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181757
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-11 21:58:02 +00:00
Ian Cottrell
d303ba255a internal/lsp: move the fixup and parallel limits into the main parse function
Previously these were only applied from inside parseFiles, which also made it
harder to refactor the remaining parse logic.
This theoretically means fixup is now called in more places than it was before,
but should cause no change in behaviour.

Change-Id: Ic6d006c1d36daca7514626653aaedf90d76e1d0f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181544
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-11 20:13:05 +00:00
Ian Cottrell
346706fc3d internal/lsp: memoize all the parsing
Change-Id: Ic7864a564f88b3fe0a421bb825b01d750610dee9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181119
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-11 20:12:58 +00:00
Ian Cottrell
ce2cddb08b internal/lsp: using memoize for all file contents
Change-Id: I7293bbcfea33c0df90f7b6df8e991aae9a03f2ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180846
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-11 20:12:47 +00:00
Rebecca Stambler
5b939d657d internal/lsp: fix type checking for unsafe package
Change-Id: I229a9329f38b8fc7f38e964652c582858c4edb5b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181678
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-11 19:41:53 +00:00
Muir Manders
1d0142ba47 internal/lsp: improve error handling while parsing
If the context is canceled (or times out) during parsing, we were
previously caching the package with no *ast.Files. Any further LSP
queries against that package would fail because the package is already
loaded, but none of the files are mapped to the package. Fix by
propagating non-parse errors as "fatal" errors in
parseFiles. typeCheck will propagate these errors and not cache the
package.

I also fixed the package cache to not cache errors loading
packages. If you get an error like "context canceled" then none of the
package's files are mapped to the package. This prevents the package
from ever getting unmapped when its files are updated. I also added a
retry mechanism where if the current request is not canceled but the
package failed to load due to a previous request being canceled, this
request can try loading the package again.

Updates golang/go#32354, golang/go#32360

Change-Id: I466ddb8d336aeecf6e50f9f6d040787a86a60ca0
GitHub-Last-Rev: 5f1e7ef9c883b76a9c1b3636936d91ec0821d922
GitHub-Pull-Request: golang/tools#110
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181317
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-11 16:41:26 +00:00
Rebecca Stambler
a99d5a724b internal/lsp: add a Version constant
This change will allow users in $GOPATH mode to have some
semblance of a gopls version.

Change-Id: I1b490d18fdf7550c54d56653ae500dc4dc25ee3b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181238
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-11 16:30:27 +00:00
Ian Cottrell
25a4f13759 internal/span: handle empty paths correctly
Change-Id: I3f411c5e27bcada26a756485a3b9de3514ac7955
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181677
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-11 15:43:01 +00:00
Rebecca Stambler
ff694a2184 internal/lsp: stop requiring a .go extension for all Go files
This change should fix the TryBot failures exposed by
https://golang.org/cl/181317.

Updates golang/go#31561

Change-Id: Ie77c9e3bfd6825dcd2608523e72f804f81d3f48c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181546
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-11 15:22:25 +00:00
Muir Manders
4bfb4c74ac internal/lsp: fix check for changed imports
We weren't comparing the right values when checking to see if a file's
import statements had changed. This was causing us to not refetch a
package's metadata when needed in certain cases. In particular, if you
typed out an import path by hand you would get stuck with "no metadata
for package" until you added or deleted another import line to trigger
metadata refresh.

Updates golang/go#32516, golang/go#32232

Change-Id: I1c99e9ee56d18f02c44c749d33679aa4e561c620
GitHub-Last-Rev: 20d46b30b520572b05e3228d9e43ba46dfd1be3d
GitHub-Pull-Request: golang/tools#112
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181578
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-06-11 15:01:45 +00:00
Ian Cottrell
f8d1dee965 internal/memoize: a new library to memoize functions
This library holds onto results with a weak reference, and guarantees that for
as long as
a result has not been garbage collected it will return the same result for the
same key.

Change-Id: I4a4528f31bf8bbf18809cbffe95dc93e05d769fe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180845
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-10 23:17:49 +00:00
Heschi Kreinick
0945d3616f internal/imports: suggest x for x_tests
golang.org/cl/170238 forgot that it's okay for an x_test to import a
package in the same directory. Only skip the candidate if the package
we're looking for has the same name as the one being fixed.

Fixes golang/go#32440

Change-Id: I7806d9f4174ca217ac83887da5e23b28cd102095
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181338
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-10 21:48:47 +00:00
Ian Cottrell
e88138204b internal/span: change URI.Filename so it just returns the filename
We panic if the uri was not a valid file uri instead
They always are a valid file URI, and we would fail miserably to cope if they were
not anyway, and there are lots of places where we need to be able to get the filename
and don't want to cope with an error that cannot occur.
If we ever have not file uri's, you will have to check if it is a file before calling
.Filename, which seems reasonable anyway.

Change-Id: Ifb26a165bd43c2d310378314550b5749b09e2ebd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181017
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-10 21:39:43 +00:00
Rebecca Stambler
fe937a7521 internal/lsp: allow fine-grained control over vet checks
This change adds an "experimentalDisabledAnalyses" configuration
to the "gopls" configuration. A user can specify a list of excluded
analyses by analyzer name.

Fixes golang/go#31717

Change-Id: I4b162fcd61ecfcef5c926bd0e96f182748a7721d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179920
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-10 19:43:59 +00:00
Suzy Mueller
bca362e842 internal/lsp: add find all references
This change implements the find all references feature by finding all of
the uses and definitions of the identifier within the current package.

Testing for references is done using "refs" in the testdata files and
marking the references in the package.

Change-Id: Ieb44b68608e940df5f65c3052eb9ec974f6fae6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181122
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-10 19:06:22 +00:00
Rebecca Stambler
5ae6a9745e internal/lsp: track missing imports, re-running packages.Load
This change marks any unresolved packages discovered as imports by
go/packages.Load. It re-runs go/packages.Load for any package with
missing imports, which will result in the LSP registering changes in
dependencies.

However, this means that we re-run go/packages.Load on
package's with unresolved imports much more than we normally would, so
it may result in a slowdown or unexpected behavior. I'm not sure if this
is necessarily the correct approach here.

Updates golang/go#32232

Change-Id: Id611fa1876e42c88ca2c3e4db30da66dc66945fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180537
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-10 18:15:09 +00:00
Rebecca Stambler
f68ef2071d internal/lsp: enable "ignoreFuncBodies" and fix caching
This change enables the trimmed ASTs behavior and fixes the broken
tests by caching parse errors along with the ASTs that are being reused.

Change-Id: Ia8e7cdb138c62a8be88659f801506e03f213fe8c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181357
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-10 18:14:45 +00:00
Heschi Kreinick
e9a20a1396 internal/imports: actually cache resolvers
I forgot to actually save the resolver instances...

Change-Id: Ieff4f22d29038895dc15be97491476f414544a5c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181337
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-10 16:54:38 +00:00
Rebecca Stambler
e6ce0ddf03 internal/lsp: add an implementation for textDocument/didSave
This change marks the overlay for a saved file as "on disk".
This will reduce the number of overlays we provide to go/packages, which
can be expensive.

Updates golang/go#31796, golang/go#32457

Change-Id: I8e69503ab80bba29caf4e42491d87e643bf17f1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181123
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-06-10 16:29:40 +00:00
Rebecca Stambler
eacb66d2a7 internal/lsp: reply with nil, rather than empty, signature help
Change-Id: I9326ad59fb3ee33aba2ba9d05758dae5c3451bde
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181358
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-08 02:21:20 +00:00
Heschi Kreinick
755ce86c76 internal/imports: fix TestNoMainModule
https://golang.org/cl/179998 made it an error to run go mod download
without args and without a go.mod. Don't do that.

Fixes golang/go#32488

Change-Id: Icd845feb8fecae69b6a8363438bb9ee546a310dc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181298
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-07 22:46:22 +00:00
Rebecca Stambler
68211a626c internal/lsp: fix some issues with trimming ASTs
This change correctly invalidates the cache when we
have to go from a trimmed to untrimmed AST.

The "ignoreFuncBodies" behavior is still disabled due to a racy test.

Updates golang/go#30309

Change-Id: I6b89d1d2140d77517616cb3956721a157c25ab71
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180857
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-07 20:08:10 +00:00
Than McIntosh
5aed7825b1 go/internal/gccgoimporter: update package to match std lib version
Import changes from std lib version, specifically

          https://golang.org/cl/181118

related to importing inlinable function bodies.

Change-Id: Ie5fe1db508f7ec2cbef2dcdc96e2136c8e4f23ad
Reviewed-on: https://go-review.googlesource.com/c/tools/+/181120
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-06-07 13:55:18 +00:00
Rebecca Stambler
0139d5756a internal/lsp: attach documentation to signature help
This change refactors hover to generate documentation for just the
declaration portion of an identifier.

Updates golang/go#29151

Change-Id: I16d48a99b56c36132e49cc87e2736f85c88ed14a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-06 17:46:28 +00:00
Tobias Klauser
d0a3d01286 go/internal/gccgoimporter: update importer tests to match std lib version
Import CL 174738 and CL 164862 from std lib version. This should fix
test failures of issue31540.go on gccgo versions < 7, e.g. on
solaris-amd64-smartosbuildlet

Change-Id: I0a41ca9fe2b248d301fbdf14c9bac3aa3e7b091c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180897
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
2019-06-06 12:41:16 +00:00
Ian Cottrell
4d9ae51c24 internal/lsp: remove source.FileContent
On FileHandle Read now just returns the data hash and error
This makes it more obvious that you should handle the error, rather than hiding
it all in a struct.
We also change the way we get and return content, the main source.File
constructs now hold a FileHandle that then updates on invalidation

Change-Id: I20be1b995355e948244342130eafec056df10081
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180417
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-06 05:02:23 +00:00
Ian Cottrell
596a85b56b internal/lsp: don't queue content changes
This updates overlays immeditely, and uses the handle identity change to
correctly update the content on demand.

Fixes golang/go#32348

Change-Id: I3125a6350cac358b7c0f7dc11f2bd11ae1f41031
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179922
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-06 04:44:31 +00:00
Ian Cottrell
a544cfa389 go/internal/gcimporter: skip stdlib tests in race mode as they are too slow
The duration causes them to be flakey on the builders.

Change-Id: I968c6418054e42e3758a6ba4030750f12c4d4b66
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180844
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2019-06-06 04:44:10 +00:00
Ian Cottrell
2c3de6a5ae internal/lsp: change file system to allow lazy reads
We split aquiring a "handle" from reading a files contents so that we can do the
former eagerly and the latter lazily.
We also "version" the handles so that the same file at different versions is a
different handle.

Change-Id: I06cc346d4b4c77d784aa454702c54689f2f177e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179917
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-06 01:09:34 +00:00
Rebecca Stambler
8aaa1484dc internal/lsp: add some basic tests for imports
This change adds a few simple tests for the goimports behavior of gopls.
There are still missing cases for non-standard library, but this is a
good start.

Change-Id: I2f9bc2cc876dcabf81413384b83fa3508517adf0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179918
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-03 23:13:51 +00:00
Koichi Shiraishi
70bf279967 internal/lsp: support build flags on processConfig
Add 'buildFlags' config to processConfig and pass that value to packages.Config.
We can avoid incorrect diagnostics such as if current source codes require any build tags.

Change-Id: Id191469ec75eedaa82b75ec4fdec084fa78c2c5d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178782
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-06-03 21:18:25 +00:00
Rebecca Stambler
b012c19798 internal/lsp: trim ASTs for which we do not require function bodies
This change trims the function bodies from the ASTs of files belonging to
dependency packages. In these cases, we do not necessarily need full
file ASTs, so it's not necessary to store the function bodies in memory.

This change will reduce memory usage. However, it will also slow down
the case of a user opening a file in a dependency package, as we will
have to re-typecheck the file to get the full AST. Hopefully, this
increase in latency will not be significant, as we will only need to
re-typecheck a single package (all the dependencies should be cached).

Updates golang/go#30309

Change-Id: I7871ae44499c851d1097087bd9d3567bb27db691
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178719
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-03 19:34:55 +00:00
Rebecca Stambler
a4e9122f10 internal/lsp: fix regression from CL 179439
Fixes golang/go#32378

Change-Id: I7c5b794ba6137084a56e3e7bf8027a6f65819b34
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179919
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-03 19:23:55 +00:00
Rebecca Stambler
178e83bc9d internal/lsp: build the builtin package preemptively
This change fixes a regression introduced by the building the builtin
package on demand. Although this change increases the startup tasks of
gopls, it is necessary to ensure that we ignore diagnostics from
builtin.go.

Change-Id: I897e747a273056d70cecba486a74c75a736d8f80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179921
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-03 18:19:26 +00:00
Ian Cottrell
359a0754b7 internal/jsonrpc2: adding rpc trace tasks
Change-Id: I101957f7aeb95034a71ab2db47e0422721c500f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179717
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 17:43:23 +00:00
Ian Cottrell
37dc81f201 internal/lsp: add memory debugging page
Display the memory statistics provided by the runtime package.

Change-Id: I3ae9c51a847fc1808c15faaadbbdc7a4874c11f0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179517
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 17:43:05 +00:00
Ian Cottrell
df5f646307 internal/lsp: debug pages for sessions views and files
Change-Id: Id21f391bd66513615d274588ce7d1d1efe407074
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179438
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 17:39:32 +00:00
Ian Cottrell
08e0b306e8 internal/lsp: move PrintVersionInfo to the debug package
Also add a new rendering mode, and clean up the plain text one.
Then use it to add an info page to to the server in debug mode.

Change-Id: Ifa66a75260965d0e46e874200203ebbc4490e424
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179497
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-03 15:29:06 +00:00
Daniel Martí
2de7f9bf82 go/analysis/passes/structtag: allow field tag shadowing
In the following piece of code:

	type T1 struct {
		Shadowed string `json:"foo"`
	}
	type T2 struct {
		T1
		Shadowing int `json:"foo"`
	}

encoding/json will encode T2 using T2.Shadowing, ignoring T2.Shadowed
entirely. This can be a useful feature to replace some of T1's fields
when encoding it. Moreover, this feature is already in use in the wild,
even though it's probably never been documented.

This started being a problem, as the structtag pass started walking
through embedded fields a few months ago. To keep it from complaining
about these useful shadowing cases, make it only see duplicate field tag
names if they are at the same embedding level, in which case no
shadowing is happening.

The old code indexed these tags by encoding key and name, using a
[2]string. The new code needs to add a level integer, so start declaring
named types for the map, and use methods to simplify the code further
below. We still use a map pointer, to avoid allocating on every single
struct definition.

Updates golang/go#30846.

Change-Id: Iae53228d4f8bd91584c59dcc982cb1300970bc8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179360
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-06-02 11:28:58 +00:00
Jonathan Amsterdam
0abef6e9ec errorsas: handle single-actual case
Handle the case where there is syntactically only one actual argument
passed to errors.As.

Following the unmarshal check, we ignore this case.

Change-Id: Ia7d77d5b3c9eb5416b37a141104c9ad7ed290b5f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/178159
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-06-01 11:02:25 +00:00
Jonathan Amsterdam
b1dcc6b189 errorsas: ignore empty interface target
No longer report a problem if target's type is interface{}.
This avoids false positives like

```
var e error
var i interface{} = &e
... errors.As(..., i) ...
```

Change-Id: Ibf6e7163147248305130a5e650f92b80e34a44de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/175717
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
2019-06-01 10:43:45 +00:00
Edward Muller
26e35f15ed internal/lsp/cache: fix leaking wg.Done() and <-ioLimit
There were several returns in this function that could leak both the
wg.Done() and <-ioLimit. This refactors them into defers close to their
counterparts.

Additionally I refactored the function to favor early returns over
nested if statements.

Fixes golang/go#32368

Change-Id: I5357d11ee526c1cb7a6bd1a0f652c61d574c10ab
GitHub-Last-Rev: bfa160b9fd75c4464d2e0a2820c04ddae01de21f
GitHub-Pull-Request: golang/tools#107
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179878
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
2019-05-31 22:35:38 +00:00
Michael Matloob
b3315ee88b go/packages: update documentation for Package.Types and Package.Syntax
so that they don't refer to the deprecated LoadX LoadModes

Also break apart the NeedX from the LoadX fields so that the needX fields
are rendered in the godoc next to the definition of LoadMode

Fixes golang/go#32364

Change-Id: Ic8837950a5e25937c556b62fbedbd8dc5356cfdb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179741
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
2019-05-31 17:21:33 +00:00
Michael Matloob
75312fb067 go/packages: support new main packages in overlays
Refactor the overlay code to create package structs for
new packages that don't already exist. This requires
calling out to the go command to determine module
roots to figure out which module a package belongs to.
The extra go list call is done in sequence in this CL
but can easily be done in parallel with other go list
calls in the future.

Change-Id: Ia0f7812fba250d154033038cb1e2afa7dedf0e16
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179600
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-05-30 21:55:28 +00:00
Paul Jolly
ce1a3806b5 internal/lsp: send void client response to client/registerCapapbility
Following CL 179157, client/registerCapapbility and
client/unregisterCapapbility are both (void) requests, not
notifications. Hence the client must send a response, else the server
will wait forever.

Fixes golang/go#32322

Change-Id: I77969317465c0c31fb29d27519d655712d8c3c2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179359
Reviewed-by: Peter Weinberger <pjw@google.com>
2019-05-30 18:43:49 +00:00