Commit Graph

2649 Commits

Author SHA1 Message Date
pjw fe74b5f080 internal/template: return available semantic tokens even on template error
Fixes golang/go#50801

Change-Id: Ic5c541d6244bd56b90bee204be7c2b2fdfa90264
Reviewed-on: https://go-review.googlesource.com/c/tools/+/381014
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-26 20:10:56 +00:00
pjw 772a39974b internal/template: return a Source with template diagnostics
Template diagnostics now return Soure 'template' instead of no Source.

Fixes golang/go#50786

Change-Id: Ifd7f26ffcee238b7168667c259c6b0006f8c03e6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/380974
Run-TryBot: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Peter Weinberger <pjw@google.com>
2022-01-26 16:53:13 +00:00
Bryan C. Mills c20fd7c261 internal/lsp/regtest: eliminate arbitrary timeouts
We care that gopls operations complete within a reasonable time.
However, what is “reasonable” depends strongly on the specifics of the
user and the hardware they are running on: a timeout that would be
perfectly reasonable on a high-powered user workstation with little
other load may be far too short on an overloaded and/or underpowered
CI builder.

This change adjusts the regtest runner to use the test deadline
instead of an arbitrary, flag-defined timeout; we expect the user or
system running the test to scale the test timeout appropriately to the
specific platform and system load.

When the testing package gains support for per-test timeouts
(golang/go#48157), this approach will automatically apply those
timeouts too.

If we decide that we also want to test specific performance and/or
latency targets, we can set up specific configurations for that (as
either aggressive per-test timeouts or benchmarks) in a followup
change.

For golang/go#50582

Change-Id: I1ab11b2049effb097aa620046fe11609269f91c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/380497
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-25 21:51:33 +00:00
Bryan C. Mills 135972eb89 gopls/internal/regtest/codelens: use the test's deadline instead of a hard-coded timeout
We may want to generalize this to have regtest.Run always derive the
default timeout from the test's deadline. In the meantime, this is a
more targeted fix for the specific timeout in TestGCDetails.

Fixes golang/go#49902
(Maybe.)

Change-Id: Ie15735dc7b0d462ec047d3f3d8a2eceeb4411fa0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/380496
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-24 16:28:24 +00:00
Robert Findley 84f205d75e internal/typeparams/example: start adding a guide to generics for tools
This CL begins adding a guide for the new APIs introduced with Go 1.18
to support writing tools that understand generic Go code.

For now I've added a summary of the new APIs, an initial example, and
some discussion of the typeparams package. Subsequent CLs will add more
examples, and polish.

Updates golang/go#50447

Change-Id: I4ed8d7a2f43e748374d14f3f515673d69ab2d5a0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377834
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Dominik Honnef <dominik@honnef.co>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-01-22 21:07:13 +00:00
Robert Findley e7c9de23ff internal/lsp/cache: remove unsynchronized write to snapshot.files
snapshot.GetVersionedFile already memoizes the file handle in
snapshot.files. There is no reason to do another write, and this write
is unsynchronized.

Fixes golang/go#50747

Change-Id: Ib196395135de6f22dd59169accb756665ad10e58
Reviewed-on: https://go-review.googlesource.com/c/tools/+/380214
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-21 21:27:57 +00:00
Marwan Sulaiman 9f83dd3691 internal/lsp/source: use the real type parameter in snippet completions
This change makes source.FormatVarType return the instantiated type
parameter instead of the actual AST expression because that will just
refer to the abstract type parameter and not the insantiated one.
I am not sure if this covers all edge cases or if there's a better
solution but I'm happy to adjust to whatever is appropriate.

Fixes golang/go#50623

Change-Id: I6e0b2d93c47c9a0502f2995ca8d3668a9a31c056
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378714
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-01-21 14:07:19 +00:00
Robert Findley 7c251d6b2f internal/typeparams: improve the package documentation
Update and expand on the package documentation for the
internal/typeparams package.

Change-Id: I2af16250580abf9e6b3a8692356faa498ba83f29
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377654
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-19 20:29:36 +00:00
Robert Findley 2762b18206 internal/typeparams: simplify the IndexExpr API
The IndexExprData type of internal/typeparams was redundant now
that the typeparams.IndexListExpr type has been introduced. Remove it,
and change GetIndexExprData to an UnpackIndexExpr method, symmetric with
PackIndexExpr. With the IndexListExpr type, both UnpackIndexExpr and
PackIndexExpr can be moved to common.go.

Change-Id: I6c31f52ab594175decfbd1a4cd94b60a23a1e629
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377235
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-19 20:29:28 +00:00
Robert Findley a71de3f351 gopls/doc: fix inconsistent rendering of enum newlines
We have inconsistent rendering of newlines in enums, as pointed out in
CL 314189 (that change edited the markdown directly, which won't work).

Change-Id: Ie39b80fe65287bd447d18cacdaea60b24b4bd08f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/369957
Trust: Robert Findley <rfindley@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: Gopher Robot <gobot@golang.org>
2022-01-19 15:07:38 +00:00
Robert Findley 523d859406 internal/lsp/source: use the fastfuzzy matcher in experimental mode
The fastfuzzy matcher is around 3x faster than the fuzzy matcher for
queries that need to search a large number of symbols, and has improved
scoring due to built-in knowledge about the structure of Go symbols.

Enable it in experimental builds of gopls, with plans to enable it by
default in the next release.

For golang/go#50016

Change-Id: Ie2c333f248bb8397d92f52fbbfdd2bf623372d0a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377434
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-19 15:06:54 +00:00
Robert Findley 6299a6dbc2 internal/lsp/cache: keep going on per-file workspace symbol errors
I'm not sure how to hit this in practice, since it appears that symbols
should only return errors with some type of corruption, but we should
keep going when searching for symbols in snapshot files.

Change-Id: I9fcf6cc92fdc943520e8890ece51d28ec46e8812
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376363
Trust: Robert Findley <rfindley@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: Gopher Robot <gobot@golang.org>
2022-01-19 15:06:41 +00:00
Robert Findley 21ca3b3a93 internal/lsp/source: parse symbol queries when using fastfuzzy
Hook up the fastfuzzy symbol matcher to our fzf-style query parsing, for
consistency with the (slow) fuzzy matcher.

In the past I had wanted to implement this natively inside the
SymbolMatcher, but it is much simpler to keep using combinators. In the
common case we'll just be using fuzzy matching.

For golang/go#50016

Change-Id: I1c62c8c8e9d29da570cb1e4034c2b10782529081
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376362
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2022-01-19 15:06:07 +00:00
Robert Findley 3737ecd836 internal/lsp/fuzzy: consider whole word matching in SymbolMatcher
In the new SymbolMatcher, add an additional scoring feature that
considers whether the matching pattern streak is part of a whole-word
match. This differentiates matches of "foo" against "pkg.foo" and
"pkg.foobar".

For golang/go#50016

Change-Id: Ib84ff13eee0b7ec23143325592cef9a41be07375
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376361
Trust: Robert Findley <rfindley@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: Gopher Robot <gobot@golang.org>
2022-01-19 15:05:25 +00:00
pjw a8c745991d internal/lsp: bring the LSP stubs up to date
There are no changes to the internals of gopls. THe newest version
of the LSP has support for notebooks.

Change-Id: I6d12350e195f459df14efe3b349fff4cc917470c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/379114
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
2022-01-19 14:58:28 +00:00
Russ Cox fddb0d54e9 internal/lsp/analysis/noresultvalues: update for CL 379116 error message change
CL 379116 changes the format of the error this checker is looking for.
Update it to handle both the old and new form.

Change-Id: I91668e4fcbe203a9028d07b780fd17e9758fc838
Reviewed-on: https://go-review.googlesource.com/c/tools/+/379174
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-18 21:28:05 +00:00
Suzy Mueller f29bdf1b50 internal/lsp: add suggested fix for unusedparams analysis
Suggest replacing the unused function parameter with _.

Updates golang/go#36602

Change-Id: I53738e65907b8a4b4857dd8954f1477a043cf442
Reviewed-on: https://go-review.googlesource.com/c/tools/+/374254
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-14 17:47:02 +00:00
Robert Findley 7424a4db47 internal/lsp/cache: fix check for excluded paths in locateTemplateFiles
The pathExcludedByFilter helper function expects path to be relative to
the workspace folder. This is a confusing API, and led to us passing
absolute paths when checking for excluded template files.

Fix it, add a regtest, and add a TODO to clean up the API.

Fixes golang/go#50431

Change-Id: Iedcf0dd9710e541c9fb8c296d9856a13ef3fbcb6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378398
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-14 17:01:02 +00:00
Robert Findley 4e31bdea78 internal/lsp/cache: avoid panic in mod diags with redundant requires
modfile.File.SetRequire panics on duplicate requires with conflicting
versions. Avoid the panic by returning an error in this case.

Skip directness diagnostics that run into this error, rather than
invalidating all diagnostics.

Fixes golang/go#50425

Change-Id: Ic6379ecc48581e7fd7b470ed295e449833c351dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376394
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-13 21:34:46 +00:00
Robert Findley a222cdb107 gopls/internal/regtest: add regression tests for template diagnostics
Add some additional regressions tests for our loading of templates based
on language ID and/or the configured templateExtensions. Move these
tests to a new regtest package "templates", so that they may be easily
run together.

Fixes golang/vscode-go#1957

Change-Id: Ic83454725e9aec41b3c1f5202bb68d97cc73c839
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378394
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-01-13 20:57:08 +00:00
Robert Findley c4cfc425f2 gopls: change the default value for templateExtensions to be empty
There is no standard for go template file extensions, and users may not
want this functionality. Make template support opt-in by changing the
default value of templateExtensions to be [].

Updates golang/vscode-go#1957

Change-Id: I7e37d22b1bc63d8300634b3b0394b4036b43fa49
Reviewed-on: https://go-review.googlesource.com/c/tools/+/375874
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-13 20:56:24 +00:00
Robert Findley d34a02b6b5 internal/lsp/template: remove the skipTemplate guard
Having the explicit skipTemplate guard should not be necessary, since
with templateExtensions empty we should not detect any templates that
the user did not ask for. Remove it

For golang/vscode-go#1957

Change-Id: Idbe30bc61f47ed405d98fdb029f44a0841769ad0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378355
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-13 20:55:59 +00:00
Robert Findley 99c83b8bac internal/lsp: find templates based on file kind
Now that we honor the template file kind provided by LSP clients, we
need to use this to derive the set of active templates.

For golang/vscode-go#1957

Change-Id: If0883b2acff746fe6d187124b939f3a2d0e0d4f2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378354
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-13 20:55:50 +00:00
Robert Findley 3f6aab191a internal/lsp: honor the file kind provided by clients for overlays
Honor the file kind provided by clients for overlays, by passing the
FileHandle into View.FileKind and checking for overlays.

For golang/vscode-go#1957

Change-Id: I4a767cb64dc5205f1d10c3126a2cbe67c21a34e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/378314
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-01-13 20:54:45 +00:00
pjw 68b574acb9 internal/template: identify template files by the templateExtensions option
Make the language id (sent from the client) 'gotmpl' equivalent to 'tmpl'

Wherever a view is known, use its options to determine which files
are template files. Whenever the client sends an explicit
languageID, use that.

Partially fixes golang/vscode-go#1957

Change-Id: I04cd630d6c6c80e0a78c2fafb6ddc1166ce86829
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376854
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-13 17:30:17 +00:00
pjw d7a4bb4f6a internal/imports: avoid rare panic
(*token.File)MergeLine() can panic. Add code to avoid the panic
and request information from users.

Fixes golang/go#50329

Change-Id: I9c10a5c6cbee4ff8a34321e77e32971f7e588cb5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376274
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-11 14:03:54 +00:00
Robert Findley 0a91d41f6f internal/lsp/source: sort workspace symbol results for stability
Add additional order invariants to workspace symbol results to
differentiate between items of equal score: sort next by symbol length,
and then finally by lexical ordering.

For golang/go#50016

Change-Id: Ic5cda2628f57cecfe972b7585525c49b0f8518bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376360
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2022-01-11 13:58:16 +00:00
A_D eb07148636 gopls: add string join/split postfix completions
This adds two new snippets, centred around string manipulation.

The first snippet applies to variables of type string, and is called
split. When used, it replaces `someStringVar.split!` with
`strings.Split(someStringVar, "|")`, where `|` indicates the location of
the cursor.

The second snippet is essentially the same as the first, but in
"reverse". Meaning that rather than going from a string to a slice of
strings, it goes from a slice of strings to a single string:
`someStringSlice.join!` -> `strings.Join(someStringSlice, "|")`.

Change-Id: I0e303a39766463034687f76a5d9dbab419e2021b
GitHub-Last-Rev: 935cc418e75d54f0e5b1194cdb576c8829252a26
GitHub-Pull-Request: golang/tools#347
Reviewed-on: https://go-review.googlesource.com/c/tools/+/362474
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
2022-01-11 13:55:59 +00:00
Robert Findley f234b3d4ab internal/lsp/source: keep collecting symbols on metadata errors
Workspace symbols requests fail when a file in the workspace is missing
metadata, such as if a build-tagged file is open in an overlay. We keep
going if metadata is missing, but not on metadata errors (such as
packages.Load errors).

Change this to log and keep going on errors.

Fixes golang/go#50536

Change-Id: I41331e864bf21e4f39674248bc30bfc02a4c3d1d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/377234
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2022-01-10 19:19:50 +00:00
Robert Findley 94bfe6897a internal/lsp: don't get the snapshot asynchronously on config changes
Server.didChangeConfiguration spins off a goroutine to diagnose the
reconfigured view, but this goroutine was calling View.Snapshot(), which
is not safe to call outside of jsonrpc2 serialization, because
the view may have been deleted.

Instead acquire the snapshot synchronously and just release it after
diagnosing. This should be sufficient, because any subsequent snapshot
change should have triggered a diagnostic anyway.

Fixes golang/go#50327

Change-Id: I2977ce0093d31be833ace979e65d112a31ac1543
Reviewed-on: https://go-review.googlesource.com/c/tools/+/375875
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-01-07 17:27:56 +00:00
Bryan C. Mills 351aaa669b internal/lsp/tests: re-enable MultiModule tests on plan9
According to https://go.dev/issue/50478#issuecomment-1006947143, Plan
9 does not support renaming across directories. For the MultiModule
test cases we want to rename go.mod to testdata/go.mod, so we need to
fall back to copying if os.Rename fails.

Fixes golang/go#50478.

Change-Id: I30b7601e1d4b122ce114015f3585f6ba6d6c9714
Reviewed-on: https://go-review.googlesource.com/c/tools/+/376115
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-07 05:34:58 +00:00
Bryan C. Mills 778a20b1a0 x/tools/gopls/internal/regtest/modfile: skip TestUnknownRevision and MultiModule tests on plan9
For golang/go#50477
For golang/go#50478

Change-Id: If2a9d175c06446db70628a21a1552e32239627c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/375876
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-01-07 05:33:44 +00:00
Bryan C. Mills a1300ed2ba internal/lsp/tests: remove unnecessary uses of t.Helper
The purpose of t.Helper is to attribute test failures to the caller's
file and line number. However, in lsp.TestLSP (and in tests.RunTests)
the reason for a given failure tends to have little to no relationship
to the caller code, so it is more useful to attribute failures to the
specific part of the setup that fails.

For golang/go#50477

Change-Id: I7c37070d036efb20f68764cfb82ce2aab1ff933c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/375877
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-06 21:41:55 +00:00
pjw 04daf88756 templates: fix panic, and stop complaining about empty files
Fixes: golang/go#50430

Change-Id: I7f03c1d3517ddde2a94036dd56f25b6655746c17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/375454
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-01-05 19:26:31 +00:00
Rohan Verma 15409b55a9 internal/lsp: foldable multiline strings
This commit adds support for detecting multiline strings for folding
ranges.

Fixes golang/go#49554

Change-Id: Idf0afb16e1fc95240cf5cbfd405a72658d715618
GitHub-Last-Rev: 3894380fcda325a5758b951e06d8f7a362652c28
GitHub-Pull-Request: golang/tools#354
Reviewed-on: https://go-review.googlesource.com/c/tools/+/372414
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Trust: Robert Findley <rfindley@google.com>
2022-01-04 20:54:25 +00:00
ye.sijun 72cd390b55 x/tools: improving the error message for check fact type
Fixes golang/go#50235

Change-Id: Ic9f61cb61fbf1e2cd198cc5d20bcba794c3181dc
GitHub-Last-Rev: 32d212d858102507ab6d6e510264feca9b78787e
GitHub-Pull-Request: golang/tools#356
Reviewed-on: https://go-review.googlesource.com/c/tools/+/374016
Reviewed-by: Alan Donovan <alan@alandonovan.net>
Run-TryBot: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tim King <taking@google.com>
Trust: Keith Randall <khr@golang.org>
2022-01-04 19:51:13 +00:00
Jonathan Amsterdam 8d383106f7 gopls/doc: use improved code generator for API doc
Use github.com/jba/printsrc in place of github.com/sanity-io/litter to
generate the Go code with API documentation. It is smart enough
to elide type names, making the "massive hack" of deleting them
unnecessary. It also omits zero values from the output.

Change-Id: Ic1bb937b9a3695e6da6db72b74c6049be1c5b80d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/370840
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-16 11:15:33 +00:00
Robert Findley e06c10712b internal/lsp: normalize interface{} to any in test comparisons
The switch to use any in standard library signatures breaks many of our
tests that match signature strings exactly. Fix this by normalizing
strings to use 'any' in place of interface{}, before comparing.

Updates golang/go#49884

Change-Id: If18ce1035b3206f37d7de6e584cf2c2cae9481c5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/370294
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2021-12-09 13:40:01 +00:00
pjw 68cbf4169f internal/lsp/template: add missed hover cases
Templates were reporting 'oops' when hovering over a string.

Fixes: golang/go#50031

Change-Id: I9e256b1f7d193bf090590c1ec71e85fc8493d7f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/369956
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2021-12-07 22:04:29 +00:00
Shoshin Nikita feb39d0cd7 internal/lsp/source: don't format generated files
Fixes golang/go#49555

Change-Id: I53e3c0d34be6a545386d6766371fbeda8a2b2ffb
GitHub-Last-Rev: 516168765671c8135523fcf801f50455b352bdab
GitHub-Pull-Request: golang/tools#349
Reviewed-on: https://go-review.googlesource.com/c/tools/+/365295
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2021-12-06 16:11:25 +00:00
Robert Findley c882a49eac gopls/doc: fix rendering of example for the infertypeargs analyzer
Fixes golang/go#49774

Change-Id: I10d2ebd9d831325e0ede73cf11ff30b2adfb744d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/367844
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2021-12-03 18:55:11 +00:00
Robert Findley f64c0f46fa internal/lsp/analysis/fillreturns: update fillreturns for new type errs
The error messages produced by go/types related to an incorrect number
of return values have changed, and have been repositioned. Update the
fillreturns analyzer to handle the Go 1.18 form of these errors.

Ideally we'd use error codes here, but can't because they are not
forwarded by go/packages. Added a TODO to revisit when error codes are
exposed.

Change-Id: I4c594fd2fd1cb7423f37ff9c6a57e9490dcbc2a4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/367714
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2021-12-03 18:55:02 +00:00
Bryan C. Mills e212aff8fd internal/memoize: do not allow (*Generation).Acquire to fail
The Acquire method is nearly instantaneous; it only potentially blocks
on a small, constant sequence of cache misses, so there is no need to
avoid blocking in it when a Context is cancelled.

An early return when the passed-in Context is canceled was added in CL
242838 to avoid incrementing the Generation's WaitGroup after its
destruction has begun; however, that early return also bypasses the
WaitGroup accounting that blocks Destroy while the generation is still
in use. Instead, we need the invariant that Acquire is not called in
the first place after Destroy, which we can ensure by nilling out
the View's snapshot when we begin destroying it.

I was not able to reproduce golang/go#48774 locally, but I believe
that this CL will fix it. (It may, however, expose other races or
deadlocks that may have been masked by the early return, which we can
then fix separately.)

Fixes golang/go#48774

Change-Id: Iac36fceb06485f849da5ba0250b44b55f937c44b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/367675
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-12-02 03:25:35 +00:00
Robert Findley 2ac48c609c go/types/typeutil: add support for mapping generic types
Add support to the typeutil package for hashing the new types produced
when type-checking generic code.

Change-Id: I05a213baee80c53c673442f3c28fddb26ad0b03f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/366614
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: Tim King <taking@google.com>
2021-12-02 03:14:37 +00:00
Peter Weinberger d99d6faea5 internal/lsp/protocol: fix whitespace in comments
There's one case when doing something about newlines in comments is
necessary, but the existing code removed newlines from comments in
several other places. The new code fixes that and a few other
leftovers.

Change-Id: Ia7905f07584ea1774f4fde786bdd5ee732acc818
Reviewed-on: https://go-review.googlesource.com/c/tools/+/368214
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-01 19:09:57 +00:00
pjw 615f9a6b81 internal/lsp/protocol: bring the LSP stubs up to date
There are no changes, other than generated code, to gopls. The vscode
typescript implementation includes 3 new and undocumented RPCs:
InlineValues, InlineValuesRefresh, and ResolveWorkspaceSymbol.

There are some places that need work, marked by //PJW: comments in
code.ts.

Change-Id: I20e4c6792ae37323bb9c887ffefbe81930ef62fe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/367845
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-12-01 15:05:46 +00:00
Bryan C. Mills 2c9b078fb4 internal/memoize: record the caller of Destroy
The hypothesis for golang/go#48774 is that the generation is being destroyed by
a call to (*View).shutdown. This change adds a bit of logging to
confirm that hypothesis.

For golang/go#48774

Change-Id: I34be2e16a0dcab4cea7e9b704b56f4cf0abb0c71
Reviewed-on: https://go-review.googlesource.com/c/tools/+/367674
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-11-30 16:43:31 +00:00
Robert Griesemer 6e52f51f5b x/tools: temporarily skip a couple of tests
Skip tests so we can get CL 367196 submitted. After that
reenable tests (and adjust as needed).

Change-Id: Id0a6d6b873a0760ae438f6f0cb147c20d00b1ca6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/367574
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-11-29 20:12:13 +00:00
pjw a618923903 internal/lsp/template: fix error that causes crashes
When LSP asks for a completion it sends a position, which is the
position of the first character after the cursor. The old code
mistakenly thought it was the position of the last character seen,
and sometimes produced an impossible slice to parse.

The example at line 29 of completion_test.go used to cause a panic.

Fixes: golang/go#49600

Change-Id: I772fe38a1a12d3876ef866819e6a878b297bb92f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/366036
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: Hyang-Ah Hana Kim <hyangah@gmail.com>
2021-11-29 15:05:11 +00:00
Peter Weinberger 1e71a25a93 gopls: template suffix flags and documentation
Adds 'templateExtensions' (with default ["tmpl", "gotmpl"]) to control
which files gopls considers template files.

Adds template support documentation to features.md.

Fixes golang/go#36911

Change-Id: If0920912bf3748d1c231b3b29e7a008da186bede
Reviewed-on: https://go-review.googlesource.com/c/tools/+/363360
Run-TryBot: Peter Weinberger <pjw@google.com>
Trust: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
2021-11-23 16:39:20 +00:00