Commit Graph

5752 Commits

Author SHA1 Message Date
pjw ca627f833c internal/lsp/semantic: fix some type definitions
xyz and err in
type A func(xyz int) (err error), or
type B struct{xyz int}
were incorrectly marked as types, when they are not.

These are now marked as variables (although the choice is somewhat
arbitrary for A).

Fixes golang/go#45233

Change-Id: I2df4eab7606c356f30bf3337c12d9190e74bc392
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305209
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-03-30 15:15:52 +00:00
pjw 0459589001 internal/lsp/protocol/typescript: small cleanups and add tsconfig.json
It would be nice if tsc -script code.ts util.ts ran without errors,
but it doesn't. tsconfig.json documents which strict setting work and
which ones don't. code.ts and util.ts have some small typescript improvements
and running them has changed slightly, as documented in README.md.

Change-Id: Idee4934bede900df2f64165359e17a42d695f518
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305210
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-03-30 15:02:49 +00:00
Ian Cottrell b0e994dcc9 internal/jsonrpc2_v2: move the idle timeout handling out of the server
Change-Id: Ia7dedd84171f4fc4818fb00b154c21b04887391f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305129
Trust: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-30 14:25:40 +00:00
Rebecca Stambler 955357534d internal/lsp: remove unnecessary call to WorkspacePackages in mod tidy
Change-Id: I85ecae0af7176f35ffbc4a916d656ac28deaba35
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303210
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-30 04:13:47 +00:00
Shoshin Nikita 769264cf08 internal/lsp/source: fix docs for fields of anonymous structs/interfaces
There are 2 different anonymous struct declarations that require
different approaches:

1. var x struct{...}
2. x := struct{...}{}

For the first one we can use the existing solution with a minor update.
However, it returns the wrong docs for the fields of nested structs.
To fix this we need to visit all fields recursively.

The second one is not a generic declaration. So, the simplest solution
is to use the method Snapshot.PosToField.

Fixes golang/go#43675

Change-Id: I46685e7985cbf2c1c5b1b74ef3cd3a70b920feba
GitHub-Last-Rev: 8a5704c2ecc3f8a007c00c7adcd637e56d99106c
GitHub-Pull-Request: golang/tools#284
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300029
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-30 03:09:04 +00:00
Shoshin Nikita cb7d59931e internal/lsp/source: skip blank identifiers during the function extraction
The blank identifier is always a local variable. It can't be
a function parameter or a return value.

Fixes golang/go#44813

Change-Id: Ieca9da35aaa9f5826ab89ded73702bed952e1226
GitHub-Last-Rev: bb7a2353ab64eed7f13bd5b9cb3b85d90b71c0ed
GitHub-Pull-Request: golang/tools#294
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305429
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-29 19:56:10 +00:00
Muir Manders 94a19427f1 internal/lsp/completion: move postfix completions behind option
Move postfix completion functionality behind an experimental option
flag. For now users can enable it by setting
"experimentalPostfixCompletions" or "allExperiments".

I added a RunnerOption so regtest tests can tweak *source.Options. I
didn't refactor the "Experimental" mode to use the new RunnerOption
because I didn't fully understand its purpose.

Change-Id: I75ed748710cae7fa99f4ea6ea117ce245a4e9749
Reviewed-on: https://go-review.googlesource.com/c/tools/+/296109
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-29 18:55:49 +00:00
Muir Manders 09058ab085 internal/lsp/source/completion: add postfix snippet completions
Postfix snippets are artificial methods that allow the user to compose
common operations in an "argument oriented" fashion. For example,
instead of "sort.Slice(someSlice, ...)" a user can expand
"someSlice.sort!". The snippet labels end in "!" to make it clearer
they do something potentially unexpected. The postfix snippets have
low scores so they should not interfere with normal completions.

The snippets are represented (almost) entirely as Go text/template
templates. This way the user can create custom snippets to match their
general preferences or to capture common patterns in their codebase.
There is currently no way for the user to create snippets, but it
could be accomplished with a configuration file, custom LSP command,
or similar.

I started by implementing a variety of snippets to help flesh out the
various facilities needed by the templates. The most interesting
template capabilities are:
 - The ability to import packages as necessary (e.g. "sort" must be
   imported to call sort.Slice()).
 - The ability to generate unique variable names to avoid accidental
   shadowing issues.
 - The ability to weave LSP snippets into the template. Currently,
   only {{.Cursor}} is exposed, which corresponds to the snippet's
   final tab stop.

Briefly, these are the postfix snippets in this commit:
 - foo.sort => sort.Slice(foo, func(...){}) (slices)
 - foo.last => foo[len(foo)-1] (slices)
 - foo.reverse (slices)
 - foo.range => for i, v := range foo {} (slices/maps)
 - foo.append
     This snippet inserts a self-assignment append statement when
     appropriate, otherwise just an append expression.
 - foo.copy creates a copy of a slice
 - foo.clear empties out a map
 - foo.keys creates slice of keys
 - foo().var assigns result value(s) to variables
 - foo.print prints foo to stdout

Some of these are probably not very useful in practice, and I'm sure
there are lots of great ones I didn't think of.

Updates golang/go#39507.

Change-Id: I9ecc748aa79c0d47fa6ff72d4ea671e917a2d5d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272586
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-29 17:27:46 +00:00
Jonathan Amsterdam 2c039f7ffc internal/event/label: prevent unsafe get of non-string
Declare an unexported type and use it in OfString/UnpackString
so it is impossible to fool the Label.UnpackString into
accessing a non-string.

Change-Id: I840fcc99590e532a78a5f9a416cd40ce9ec2163a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/305309
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2021-03-29 12:54:38 +00:00
Andrey Bokhanko 4c8e4a8bc6 go/analysis/passes/inspect: fix typo in comment
Fixes golang/go#45079

Change-Id: I45b1eed6091e2b03971c631bb4d456b1b6341b6c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/302989
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-03-27 04:14:50 +00:00
Rob Findley 63ea654b47 internal/lsp: hold the gc details lock when storing diagnostics
At long last, with Pontus's help reproing on Github actions, we have
tracked down the race to the gc_details diagnostics.

Since toggling gc_details does not increment the snapshot ID, we have to
use careful locking to ensure that the gc_details diagnostics we store
are consistent with the current state of the gc_details toggle.

Updates golang/go#44099
Fixes golang/go#44826

Change-Id: I7b9108a829c98a84360c9012c1b60f4990839b5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/304169
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-25 17:12:39 +00:00
Shoshin Nikita 7f6d50ea3b internal/lsp/source: fix hover and completion with dot imports
Qualifier now returns empty package name for dot imports.

Fixes golang/go#44589
Fixes golang/go#45063

Change-Id: I740f6bd63f27fb27f6d19202a955e858815be090
GitHub-Last-Rev: ea8268691ecaf785b00e4fd110ef7ff1d5af885e
GitHub-Pull-Request: golang/tools#290
Reviewed-on: https://go-review.googlesource.com/c/tools/+/302589
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-25 00:32:48 +00:00
Rebecca Stambler b3556f0f83 internal/lsp: remove some unused parameters, mostly in the cache package
Change-Id: I0431843df432fa03a531e01dfc4fec537efadb15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/301950
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-25 00:26:08 +00:00
Rebecca Stambler 09a00c1ab1 internal/lsp: fix support for SourceFixAll code actions
Some of the refactoring changed the way that we label code action kinds,
and we need to add quickfix and fixall kinds for each diagnostic type.
Support a per-kind suggested fix, and fix a small issue in setting the
analyzer for a fixall code action.

Fixes golang/go#45111

Change-Id: I6bb32c9aa7427b690f42910672d3139579e84478
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303209
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-24 23:51:27 +00:00
Ian Cottrell 877f9c48b6 internal/jsonrpc2_v2: an updated jsonrpc2 library
Change-Id: I609173baa6842d33068a7e9596d54f03d89c5401
Reviewed-on: https://go-review.googlesource.com/c/tools/+/292169
Run-TryBot: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-24 21:26:20 +00:00
Koichi Shiraishi 52cb77242b gopls: upgrade mvdan.cc/gofumpt to v0.1.1
$ go mod edit -require=mvdan.cc/gofumpt@latest
$ rm -f go.sum; go1.16.2 mod tidy -v

Change-Id: Iaa724ae26f0f5082ec433004ea9da11ca047c740
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303849
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-24 18:15:38 +00:00
Koichi Shiraishi a1191f373a gopls: upgrade honnef.co/go/tools to v0.1.3
$ go mod edit -require=honnef.co/go/tools@latest
$ rm -f go.sum; go1.16.2 mod tidy -v

Change-Id: Id1fb0373334ada1daf8fb5b6c488bf2dfea055fe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303850
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-24 17:17:31 +00:00
Andrii Soluk d8aeb16bb5 internal/lsp: add defaultLibrary mod for basic types
Signed-off-by: Andrii Soluk <isoluchok@gmail.com>
Change-Id: Id0165f12f4c615b5b69663303bb00a424350b2b7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303370
Trust: Robert Findley <rfindley@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-22 19:13:07 +00:00
Heschi Kreinick aa0c72341e internal/lsp/cache: get control of reloadOrphanedFiles
According to its comment, reloadOrphanedFiles is intended to work around
overlay bugs. But as of 1.16, there are no overlay bugs that we know of.
So what is it still doing?

Apparently, quite a bit, not much of it useful. Clean up as much as
possible.

- Files with no valid package declaration are ignored by the go command.
There's no point trying to reload them; stop.
- During metadata invalidation, we clear out all IDs for a file, even if
only one of its IDs is invalidated, e.g. when a test package is removed.
That leaves valid metadata for the non-test, so we don't refresh it in
the workspace reload, and only catch it as an orphan. It seems to me we
should only remove the invalidated ID.
- If the client incorrectly sends us a didOpen for a non-Go file, we
will attempt to load it as an orphaned file. Fix the regtest that did
that.
- TestEmptyGOPATHXTest_40825 set up an invalid GOPATH: you can't work in
GOPATH/src. However, it exists to test code that no longer exists, so
just delete it.

After this change, almost none of the regression tests trigger orphaned
file reloading. It's difficult/impractical to rule it out entirely
because some of them only appear racily. Since I intend to remove the
code path, I'm not too worried about more creeping in before I'm done.

The only useful case is multiple ad-hoc packages. Because we only
allow one "command-line-arguments" package in the workspace, if you
switch between two the old one becomes orphaned. I hope to work on that
soon.

Change-Id: Ia355cf104280ce51f6189c6638e8da8f4aef2ace
Reviewed-on: https://go-review.googlesource.com/c/tools/+/302089
Trust: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-22 18:20:18 +00:00
pjw d7a25adab0 gopls/integration: remove obsolete code
The log replayer is obsolete, and the logs parser it uses is badly
out of date.

Change-Id: I7f6b0a3bd3176a7a08379c333083daf75c98a523
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303231
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-19 20:57:45 +00:00
pjw 9bdb41970f gopls/internal: add coverage command to compute test coverage
Running gopls/internal/coverage/coverage.go in the tools directory
produces a coverage file (/tmp/cover.out by default) and a report
showing how well the gopls tests cover the packages in internal/lsp.

Change-Id: I1a7a22321f807ae54194833ee6a8e2a80bd9dca0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303290
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-19 18:34:16 +00:00
Dan Kortschak d2e11a2bf3 present: don't drop commands that immediately follow text
Prior to this, the line identified as the start of a command by the test
for a leading dot was dropped. This behaviour is not documented in the
present package documentation.

Change-Id: Ib7354f0f4a661fccc65be5f92d487fe7f627302f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260899
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>
2021-03-19 17:28:02 +00:00
Dan Kortschak 695b16757a cmd/present2md: allow comments to be retained in translated document
Updates golang/go#41883

Change-Id: I94621f8583ee9fab492f64ae4df442ea856da400
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260898
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>
2021-03-19 17:27:47 +00:00
Dan Kortschak a14ff98a4d present: retain complete caption command when parsing captions
Updates golang/go#41883

Change-Id: I332aa821a6e414a77ff8d8cc384ba23b5955b05b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260897
Run-TryBot: Ian Lance Taylor <iant@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>
2021-03-19 17:27:31 +00:00
Makima0 1aac171fc6 Update emacs.md - add .dir-locals.el example
Change-Id: I96c6c3498c47902b694ef0b141175826b7ebe689
GitHub-Last-Rev: bf03d6e5a33cc1984a76ef9b45d642947a07bb85
GitHub-Pull-Request: golang/tools#275
Reviewed-on: https://go-review.googlesource.com/c/tools/+/294110
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-19 04:40:15 +00:00
Rebecca Stambler 2c4a88659b internal/lsp: remove module diagnostics from code actions
With -mod=readonly, all go.mod diagnostics are covered by go get quick
fixes on import statements, so we don't need to run `go mod tidy` on
save for Go files. The real issue with this bug is the call to
WorkspacePackages, which type checks every package in the workspace.

Fixes golang/go#45092

Change-Id: Ibb82a3e58ec345ebdb67c0cbef5e029dce2d5a30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/303149
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-18 22:41:28 +00:00
Heschi Kreinick 9b614f5d7b internal/lsp/cache: tolerate analysis panics better
Panics in type error analyzers shouldn't block diagnostics.

Fixes golang/go#45075.

Change-Id: I897f0949551ab65276371f7ec8140ccb689e5a7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/302533
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-17 18:27:22 +00:00
Rob Findley 9e9211a98e gopls/internal/regtest: fix race when printing regtest state on falure
Change-Id: Ia4d36510d5929789f045480a22e4e6c20d3c96c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/302289
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-16 19:06:39 +00:00
Rob Findley 6d45e3d999 internal/lsp: add a temp workspace per folder, and a helper command
Locating the workspace module by convention has multiple problems:
 + gopls's view of $TMPDIR might be different from the client
 + there might be multiple views
 + there might be multiple gopls sessions per pid

Instead, assign a temp workspace directory for each workspace folder,
and provide a command to access this information.

Cleaning up all these temp directories was overcomplicated. Instead,
create a temp directory for the gopls server to nest them under, that
can be removed up on server shutdown.

Also fix a bug where the snapshot was not acquired before copying its
workspace.

Updates golang/go#42252

Change-Id: I0641cebe09cd376dfa27373cac30397711c64a8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300409
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-15 23:11:33 +00:00
Marwan Sulaiman e409f12100 internal/lsp: add snippet completion for t.Fatal errs
This CL updates addErrCheckAndReturn to return "if err != nil { t.Fatal(err) }"
if the conditions for such snippet completion are met.The CL allows for
the following condition:

The enclosing functions takes a type that implements testing.TB which allows
for tests, benchmarks and extensions to the testing object to be completed.

Also, this CL doesn't explicitly check for the Test/Benchmark function
signature so that test helpers can also get the same benefits.

The remaining conditions for the current "if err != nil" checks also apply.

In the future, more testing completions UX can be added.

Fixes golang/go#43310

Change-Id: I45197ab25610e31fef629394c79cb3792b532e7d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/279488
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-15 21:39:02 +00:00
Russ Cox 8e4f4c8659 godoc: delete GoogleCN logic
The GoogleCN code is specific to the code for golang.org,
which no longer uses golang.org/x/tools/godoc.

For golang/go#32011.

Change-Id: If13e3ed93d57f9d8a6c0f8a09b8343567dd6c0b1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/296373
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2021-03-12 18:55:53 +00:00
Rebecca Stambler 44abc2a71b internal/lsp: only load by view when there are no go.mod files
In debugging the metadata CLs, I noticed that when a view's only go.mod
file became unparseable, we would fall back into reloading the entire
view. In such cases, we should just not reinitialize.

Change-Id: I1b552158da8855bf80e9ded8b29c346c67564239
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300674
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-11 22:40:02 +00:00
Heschi Kreinick 11e8f6b853 internal/lsp: refactor codeAction
As much as possible, try to unify the codeAction code paths. We always
run analysis now. And rather than assuming certain categories of
analyzers will generate certain kinds of code actions, mark them
explicitly and use that information to filter the actions afterward.

Change-Id: I8154cd67aa8b59b2a6c8aa9c3ea811de2e190db4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300170
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-10 19:04:36 +00:00
Rebecca Stambler 1523bb47d8 internal/lsp: fix time.Duration hover name check
Change-Id: I30a0e9848e5578b66628e055f6125d2a352dc6d5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300189
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-09 20:20:25 +00:00
Matheus Alcantara bcb2d7b23b internal/lsp: fix bad completion for variadic functions
Add variadic completion in functions only if snippets is enabled.

Fixes golang/go#42691

Change-Id: I0aebe86b5a58d2f7491f0b340ad14b15c184eeb1
GitHub-Last-Rev: 04b2ad0d1eb5be80fdb34bfaf3fc6eda0362f3f2
GitHub-Pull-Request: golang/tools#280
Reviewed-on: https://go-review.googlesource.com/c/tools/+/295950
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-09 20:04:04 +00:00
Heschi Kreinick 7ee29554cc internal/lsp/cache: refactor and improve go get quick fixes
Generating go get quick fixes in a single place only made it harder to
get them right. Do it during diagnostics generation, as is the new
norm.

Also improve the user experience. When we fail to import a package
because one of its dependencies is missing, it makes more sense to run
go get on the package we tried to import, not the one that's missing:
that will download all of its missing dependencies if there happen to be
more.

Change-Id: Ib6a8140bccfafcb9f966d25639799dd4c7347c3d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300072
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-09 19:56:34 +00:00
Ainar Garipov 1e524e26be internal/lsp/source: add the nilness analyzer
Fixes golang/go#44627

Change-Id: I4291b419862c7b7df8eff988abe7ab38d03e6189
Reviewed-on: https://go-review.googlesource.com/c/tools/+/299131
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-08 20:13:34 +00:00
Hana d34cf35d93 internal/lsp/source: return nil for foldingRange in case of parse error
When parse errors occur, go's parse package cannot recover nicely.
gopls tried to compute folding ranges based on the partial info
in this case, but returning partial folding range info confuses
editors (vscode) and results in dropping previous folding range
info from the region after the parse error location.

This CL makes gopls not to return anything - so the editor can
tell the result is not believable and ignore it.

The ideal solution is to return a response explicitly surfacing
this case, but currently LSP (3.16, as of today) does not have
a way to describe this condition. See the discussion in
https://github.com/microsoft/language-server-protocol/issues/1200.

We also tried to make gopls return an error. While it worked
nicely in VSCode, we are not sure about how other editors handle
errors from foldingRange. So, instead, we just let gopls return
an empty result - since foldingRange is already broken in this
case, we hope it doesn't add a lot of noise to existing users.

VSCode Go will check the response from the middleware. If the
response is empty but the file is not empty, VSCode Go will
ignore the response.
(https://go-review.googlesource.com/c/vscode-go/+/299569)

Updates golang/vscode-go#1224
Updates golang/go#41281

Change-Id: I917d6667508aabbca1906137eb5e21a97a6cfdaf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/291569
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-08 17:39:28 +00:00
Rob Findley c5f5f4bed3 gopls/doc: clarify how to set remote.listen.timeout
Change-Id: If0f9e951eb0edc7f4ea72d0bb2847844447f18eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/299729
Trust: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-08 14:22:49 +00:00
Rob Findley 3e1cb95235 internal/lsp/source: correct workspace symbol logic for unpacking receivers
The logic to extract the receiver identifier from a func decl was
incorrect, accepting only the common T and *T syntaxes, and panicking on
*(T).

Fix this by copying the logic from go/types.

Fixes golang/go#44806

Change-Id: I1c87ab21ac04e484972bc4161180ca1112df3c73
Reviewed-on: https://go-review.googlesource.com/c/tools/+/298852
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-05 19:21:50 +00:00
pjw 397283d209 internal/lsp/protocol/typescript: fix lint errors in .ts code
The only changes in this CL are semicolons.

Change-Id: Id13ef3d1e5634615cf6806c5465d066e1604554a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/299249
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-05 19:16:54 +00:00
pjw d19d8cffc1 internal/lsp/protocol/typecript: fix type merging
Typescript merges different definitions for a type. This CL inserts
a pass over the types to do merges better. It also has a lot of
tiny renumberings to match error messages to the line they are on.

There are two substantive changes to code.ts:
1. In the first pass over the parsed types, setData() (at line 195)
is more careful about conflicts.
2. The new pass is cleanData() at line 528. All the code down to
line 670 is used for this.
3. At line 1094, the names chosen for generated types (structs
embedded in structs) needed to be made unique. The old code only worked
by luck.
4. To merge, the code needs to change Nodes from the AST. Unfortunately
the members of ts.Node are readonly, so one has to cheat the type system.
This is done three times, using a varaible named 'fake'.

The generated code in tsprotocol.go contains types that are never used.
In Typescript these are parts of union types, but the Go code has
chosen at most one of them.

Change-Id: I15a9e5adedce35ea5f47c3fbce2a8a552fb7337e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297429
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-05 18:01:59 +00:00
Jay Conrod 50ca8d007d all: recognize new error from go command when no go.mod is found
This change fixes x/tools tests before CL 298650 lands. After that CL,
the go command reports a different error message when GO111MODULE=on
and it is invoked without a go.mod file (with a command that requires
a go.mod file). We plan to backport that change to 1.16.

For golang/go#44745

Change-Id: Idb3e146828703c89f788ae660ffc95aef16433e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/298792
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2021-03-04 22:10:16 +00:00
Rebecca Stambler 2cde57b5a5 internal/lsp: remove redundant didChange notifications
didSave notifications were triggering didChangeWatchedFiles, which in
turn were triggering didChange.

Change-Id: I74b0e3859aee2d8a4d971f2d4e4c91048cec2fc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/298770
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-04 20:41:31 +00:00
Heschi Kreinick 376db57240 internal/lsp: use pre-existing quick fixes for analysis diagnostics
Now that we're generating quick fixes at analysis time, we can use those
in code action requests and delete a fair amount of redundancy. The
codeAction function is a little cluttered, but I want to get it all in
one place before I decide how to split it up.

Change-Id: Icd91e2547542cce0a05c18c02a088833f71232a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297532
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-03 21:54:20 +00:00
Heschi Kreinick 144d5ced6b internal/lsp: run type error analyzers as part of diagnostics
Type error analyzers can be viewed as enhancing type errors, rather
than analyzers in their own right. Create a source.DiagnosePackage
function that combines the list/parse/typecheck diagnostics with type
error analyzers. This allows us to remove some special cases from the
analysis path, and is a first step in removing all the special
handling for analysis quick fixes.

Along the way:
Pass pointers to source.Analyzer after I spent half an hour chasing a
loop capture bug. Spend a further 2-3 hours chasing slowdown in the
command tests as a result.

Move Unnecessary tag generation into diagnostic creation rather than
as a mutating post-processing step that required cloning diagnostics.

Change-Id: Id246667a9dcf484dc79516f92d5524261c435794
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297879
Trust: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-03 21:51:40 +00:00
Heschi Kreinick 24439e3c78 internal/lsp/source: eliminate GetTypeCheckDiagnostics
Most callers of source.Package.GetDiagnostics do it via
GetTypeCheckDiagnostics. Push its logic up or down as appropriate and
delete it.

Rather than requiring fully populated maps of diagnostics, which was
rather subtle, call storeDiagnostics for every Go file in the package.

Change-Id: If43b0cc922af1013e80f969362246538df14985b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297878
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-03 21:21:28 +00:00
Shoshin Nikita dafbee5034 internal/lsp: show human-readable const time.Duration as a comment
The current hover information for constant time.Duration is not very
useful because it displays nanoseconds. So, show formatted duration
as an inline comment.

Fixes golang/go#44667

Change-Id: I6177455fb8932d1914d5cf623c0d9c4eff8f0b3f
GitHub-Last-Rev: e168968012741a1e614c66bc97fe60b196943ed3
GitHub-Pull-Request: golang/tools#281
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297310
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-03 20:04:07 +00:00
Rob Findley 9c452d8574 internal/lsp/cache: don't rely on related diagnostics if unsupported
In CL 295413 we fixed the handling of related type checker diagnostics
to correctly identify the primary and secondary errors at a position.
However, on clients that don't support diagnostic related information,
this can lead to confusing primary diagnostics.

Add handling for clients that don't support related information, to
embed the secondary error in the primary error.

Fixes golang/go#44735

Change-Id: I3d2470d2a4044661e6ed31ac9ffd2f9ff27f7d4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297875
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-03-03 15:21:54 +00:00
Heschi Kreinick 2ac05c832e internal/lsp: key GC details off package ID
Rather than using the directory of the package, store the package ID and
calculate the directory in GCOptimizationDetails. I think this is
slightly more readable/cleaner.

Change-Id: I13cac8a7552b73b2bd5d25ff582b5d4936a74827
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297877
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-03-02 22:01:38 +00:00