Commit Graph

5877 Commits

Author SHA1 Message Date
Rebecca Stambler 8f2cf6ccfc gopls/internal/regtest: clean up TestFillReturnsPanic
The test doesn't necessarily need to require exactly 2 log messages, so
the match doesn't need to be so exact.

Updates golang/go#46546

Change-Id: I6ec5dee820c76c41db7b1d4bad3925fc7afe25e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324760
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-03 18:03:08 +00:00
Rebecca Stambler 4abb1e2f28 internal/lsp: handle empty buffers in template parsing
Fixes golang/vscode-go#1540

Change-Id: I64514915d555bf0c0ff791b213bb834e9e99a0af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324758
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@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: Peter Weinberger <pjw@google.com>
2021-06-03 16:41:39 +00:00
Rebecca Stambler 7ac129f24a internal/lsp: don't diagnose/analyze intermediate test variants
As part of debugging CL 324394, I found that we were returning
intermediate test variant packages in packageHandlesForFile. This
happened because, even though these packages were not workspace
packages, they would still be picked up by the file URIs -> IDs map.

This is typically not a problem when we are picking out the widest or
narrowest package for a specific request, but for diagnostics on changed
files, we run them on all of the possible packages. This also led to us
analyzing these intermediate test variant packages. Filter them out, as
we will never want them for this purpose.

Change-Id: Ifa780cd104f9c4b3fe6c530402956e2337c8fcdc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324689
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-06-03 14:48:35 +00:00
Rebecca Stambler 1c2154ae38 internal/lsp: address some staticcheck warning
Change-Id: I5eea4d35ef6ad4159ca96ba2765477c4603a1ca6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324396
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-06-03 03:03:28 +00:00
Rebecca Stambler 384c392572 Revert "internal/lsp/cache: don't delete metadata until it's reloaded"
This reverts commit 46e69bf3b2.

Reason for revert: Still has bugs associated with it and want to do a release

Change-Id: Ifa80bde147aa23aa4029a157d5dbaf6479d53024
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324290
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-02 19:45:53 +00:00
Bryan C. Mills 29f5b8f057 internal/testenv: treat netbsd-arm*-bsiegert as slow builders
Change-Id: I80f22d6ffdb38085dabba12ec5f53c3e5034d132
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324229
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-06-02 19:26:46 +00:00
Bryan C. Mills 7922491030 go/packages/packagestest: make Export skip tests involving unsupported links
Also make Export create all parent directories before all files.
If the files are symlinks to directories, the target directory must
exist before the symlink is created on Windows. Otherwise, the symlink
will be created with the wrong type (and thus broken).

Fixes golang/go#46503
Updates golang/go#38772
Updates golang/go#39183

Change-Id: I17864ed66e0464e0ed1f56c55751b384b8c59484
Reviewed-on: https://go-review.googlesource.com/c/tools/+/234112
Trust: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2021-06-02 19:23:16 +00:00
Rebecca Stambler 726034ecff Revert "internal/lsp: enable semantic tokens by default"
This reverts commit 5ab822f631.

Reason for revert: Too early to enable since we need to figure out a plan for formatting directives

Change-Id: I46567b271d4ecd7e4af574221520a72bd8b8e500
Reviewed-on: https://go-review.googlesource.com/c/tools/+/324289
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-06-02 18:55:23 +00:00
Fazlul Shahriar 7271753b67 internal/jsonrpc2_v2: make TestIdleTimeout pass on Plan 9
Fixes golang/go#46175

Change-Id: I9c801ff42392dbff2fcb74dea7549d849c7e3624
Reviewed-on: https://go-review.googlesource.com/c/tools/+/323529
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-06-02 15:04:26 +00:00
Karthik Nayak 377464f22d internal/lsp: include function literals in outgoing call hierarchy
Currently we don't consider function literals in outgoing call
hierarchy, because we only consider expressions of type
`ast.SelectorExpr` and `ast.Ident`. So function literals are skipped.
Fix this by ensuring we traverse through other types even if we
don't add the type itself as an outgoing call hierarchy.

Fixes golang/go#43438

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>

Change-Id: I9eacbd5ec7a68224518bf0e405319adeb673c853
GitHub-Last-Rev: 3e7118a8fd090b339a3eacf32fa8d62e05a76b87
GitHub-Pull-Request: golang/tools#320
Reviewed-on: https://go-review.googlesource.com/c/tools/+/323809
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2021-06-01 22:58:04 +00:00
Muir Manders df07577eb1 lsp/completion: fix variadic param candidate ordering edge case
In cases like:

    var foo func(...interface{})
    var one int
    var two func() (int, int)

    foo(<>)

At <> we were preferring "two()" over "one" because we were really
excited that the multi return value function was usable. "one" was not
preferred because the expected value is interface{} (we default to
saying candidates _don't_ match interface{} to give non-type based
aspects of candidate inference a chance to shine).

Fix by applying the corresponding interface{} logic to the assignees
checking: ignore the case of completing into func(...interface{})
since all multi return value functions would match.

Fixes golang/go#46378.

Change-Id: I355daa75e067e8b14508ca50b8d3b6b727df5fec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/323509
Run-TryBot: Muir Manders <muir@mnd.rs>
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-06-01 17:02:03 +00:00
Dominik Honnef 6123e5fbf2 internal/gocommand: run 'go list' on the unsafe package when fetching release tags
The specific package we run on doesn't matter, but using unsafe will
be a lot faster than running on whatever package the working directory
is pointing at.

Change-Id: Iae65a262c9bb129f8c8442a72cebf131521357ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/323390
Trust: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-29 00:21:43 +00:00
Rebecca Stambler 5ab822f631 internal/lsp: enable semantic tokens by default
Change-Id: Ie094874849fce1ff06988c8b1809f48a5a34b555
Reviewed-on: https://go-review.googlesource.com/c/tools/+/323169
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@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: Peter Weinberger <pjw@google.com>
2021-05-27 19:51:27 +00:00
OneOfOne eb0b8a15bc internal/lsp: findIdentifier always return an error
Fixes golang/vscode-go#1522

Change-Id: I9da0e5486e1494cf7948beefa26f57d89d5b3933
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322651
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-27 19:51:01 +00:00
Rob Findley a3eb095d6a gopls/internal/regtest: skip TestDeleteModule_Interdependent
This test is flaky due to orphaned file reloading. Since it is for an
experimental feature, skip it until we understand the problem.

For golang/go#46375
Updates golang/go#46183

Change-Id: Id6b369f2b61730c8503e3532547708f7689343c3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322649
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-05-25 21:54:09 +00:00
Zvonimir Pavlinovic acaf218a7d vta: adds definition for VTA nodes and graph.
This is the first CL for the Variable Type Analysis (VTA) callgraph. It
provides the definition for VTA nodes and graph used to infer how types
flow through the Go program. This CL is first in the series of CLs that
build VTA type propagation graph.

The VTA algorithm is described in the paper called ``Practical Virtual Method Call Resolution for Java."

Change-Id: I2e4eafa139c6fdfba4bd709f041762ddc6174188
Reviewed-on: https://go-review.googlesource.com/c/tools/+/313749
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
Reviewed-by: Tim King <taking@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Tim King <taking@google.com>
Trust: Tim King <taking@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-25 21:38:43 +00:00
Dominik Honnef c3e30ffe92 gopls/internal/hooks: add Staticcheck's quickfix category of checks
Staticcheck's new quickfix category contains optional code
refactorings, such as turning a chain of if/else-if into a switch
statement, or simplifying boolean expressions.

These checks produce diagnostics with the "hint" or "information"
severities. Most use "hint", which produces a subtle hint in VSCode's
UI that a refactoring is available. "information" produces a blue
underline and is only used for those checks that have a very high
likelyhood of improving code readability.

Change-Id: I8f5b4eca67eb6b4e45c17510459d83eb673384e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322492
Trust: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-25 19:05:14 +00:00
Dominik Honnef 917abfb0e7 gopls: propagate Staticcheck's diagnostic severities
Each analyzer in Staticcheck is annotated with the appropriate
severity to use for its diagnostics. For example, most checks in SA*
produce warnings, but some produce errors (e.g. when passing an
invalid regular expression to regexp.Compile).

This will be especially important for a follow-up CL that enables
Staticcheck's new quickfix category, which contains optional
refactorings that shouldn't be flagged as warnings.

Change-Id: I6235303a3bb188ef79f52952c01e9585301a3270
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322491
Trust: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-25 19:05:09 +00:00
Dominik Honnef b95d58a81b gopls/internal/hooks: update for Staticcheck 2021.1
Change-Id: I3b10339b4049453cd3d9393df79c333c1e4f7c82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322490
Trust: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-25 18:39:40 +00:00
Rob Findley 874765c967 internal/testenv: update linux-arm to linux-arm-scaleway
CL 303230 renamed the linux-arm builder to linux-arm-scaleway, but the
x/tools ExitIfSmallMachine guard was not updated accordingly, resulting
in consistent failures for some tests.

For golang/go#45931
For golang/go#46183
Updates golang/go#32834

Change-Id: Ief5f17fc61cb38cf6b7cf63b6cd5e64f9d56261e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322409
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-05-25 10:46:47 +00:00
Rebecca Stambler 98f8936a45 go/internal/gcimporter: cleanup testenv functions
There was a lot of duplicated code throughout the gcimporter test.


Change-Id: Ib232717783b2b4053fa41139dfad05f37662072a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322290
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: 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-05-25 04:04:01 +00:00
OneOfOne 71e666b5c4 internal/lsp: don't crash on an empty import path
Fixes golang/vscode-go#1526

Change-Id: I70991491771df78ef4f4f6fdcc5d00ea9cde8e37
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322291
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: 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>
2021-05-24 21:23:15 +00:00
Suzy Mueller d5449c00d2 internal/lsp: fix mod file codelens
The two codelenses that are attached to the module statement are
'Run go mod tidy' and 'Create vendor directory'. In a 'go.mod' file
without any required modules, the only codelens that shows up is
the 'Create vendor directory'. With no required modules, there is nothing
to vendor, but 'Run go mod tidy' may actually clean up the go.mod and go.sum,
so this is the codelens we want to appear.

Change-Id: I7264f8c4c4427a66264684f71fd4407b2170609f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322292
Trust: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-24 20:38:17 +00:00
Peter Weinbergr 88a9bccae5 internal/lsp/protocol: update code generated for LSP
There are no changes that affect gopls. The changes are for forthcoming
3.17 features.

Change-Id: Ic18872a9de980ce777b6d5384166de6ee9944622
Reviewed-on: https://go-review.googlesource.com/c/tools/+/322249
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2021-05-24 18:03:47 +00:00
Muir Manders e64a37c1d5 lsp/completion: don't offer literal candidates requiring conversion
For example:

    type foo struct { i int }
    type bar struct { i int }

    var _ foo = <>

Previously at <> we would offer "bar{}" in addition to "foo{}" because
we knew "bar" was convertible to "foo". The "bar{}" completion wasn't
valid as inserted, however, because we didn't include the type
conversion. Anyway, it doesn't make sense to include convertible types
since the directly matching type should also be available. Fix by
tweaking the literal candidate code to skip candidates requiring
conversion.

Fixes golang/go#46113.

Change-Id: Ica5e4af7f2f8bb2f7e2361efe39694f8bb738c97
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319509
Run-TryBot: Muir Manders <muir@mnd.rs>
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>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Michael Knyszek <mknyszek@google.com>
2021-05-24 16:41:39 +00:00
Marwan Sulaiman 4061312594 internal/lsp: add list_known_packages and add_import commands
This CL adds two new commands that let a client request a list of importable packages relative to a Go file and then select which import a programmer would like to add to said file.

Updates golang/go#43351

Change-Id: If12518874a92ed4167bdd711a92e03ee21c7b949
Reviewed-on: https://go-review.googlesource.com/c/tools/+/281412
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>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-05-23 03:57:00 +00:00
johnnyjacobs 1e0c960986 tools: make printf analysis have more helpful output
- Use func.FullName() everywhere we can, since simply Printf or Errorf is often ambiguous.
- Give more specific error output when unsupported %w directive is used.

Change-Id: Ic2b423d87f9bedde459c79ce5aae622e9a4b5266
Reviewed-on: https://go-review.googlesource.com/c/tools/+/301949
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Trust: Damien Neil <dneil@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
2021-05-21 23:19:31 +00:00
Rebecca Stambler 2275bb55e0 internal/lsp: correct typo in orphaned file error message
Fixes golang/go#46265

Change-Id: I2ab862736b2ea17b24e90f17c7a703f56351b741
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321249
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-05-20 18:25:17 +00:00
Peter Weinbergr 30637901f8 internal/lsp/semantic: only return token types the client asked for
The old code mistakenly presumed all clients would want the standard
set of semantic tokens in the LSP specification, but clients have the
option of asking for fewer, so gopls should only use those.

Change-Id: Ic396bf3a2ba1fc3c9b48a380265a6cfded0a8bf6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321470
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-05-20 15:46:45 +00:00
pjw 0886cdd1dc internal/span: compute utf16 length directly
computing the length by hand avoids an allocation.

Change-Id: Idc15f9347628b3b68cb3722d03c2c706a4f60a68
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321469
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-05-20 14:08:36 +00:00
Rebecca Stambler 46e69bf3b2 internal/lsp/cache: don't delete metadata until it's reloaded
This CL moves to a model where we don't automatically delete invalidated
metadata, but rather preserve it and mark it invalid. This way, we can
continue to use invalid metadata for all features even if there is an
issue with the user's workspace.

To keep track of the metadata's validity, we add an invalid flag to
track the status of the metadata. We still reload at the same rate--the
next CL changes the way we reload data.

We also add a configuration to opt-in (currently, this is off by
default).

In some cases, like switches between GOPATH and module modes, and when a
file is deleted, the metadata *must* be deleted outright.

Updates golang/go#42266

Change-Id: Iff5e10b641fdb4be270af0cd887a10ee97ac1a19
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271477
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>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-05-19 23:21:03 +00:00
Shoshin Nikita f803486ed4 internal/lsp/source: refactor commentToMarkdown function
This change simplifies the code and fixes the issue with
extra new lines. It also adds unit tests.

Fixes golang/go#43257

Change-Id: If4f6d939b2b0521e7bcce930838d539a6f0f9004
GitHub-Last-Rev: b5dd778524dbf55c1cf83af8175cdb6e8f4959ae
GitHub-Pull-Request: golang/tools#300
Reviewed-on: https://go-review.googlesource.com/c/tools/+/307709
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: 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>
2021-05-19 23:19:09 +00:00
Pontus Leitzler 49064d2332 internal/lsp: report used semantic token order in registerCapability
The semantic token legend sent to the client in registerCapability
wasn't the one used when encoding semantic tokens.

If a client sent clientCapabilities support for token types and token
modifiers that wasn't ordered exactly as gopls defined them, all
semantic tokens was encoded incorrectly.

We now instead report the order used for encoding as legend in the
registerCapability request to the client.

Fixes golang/go#46244

Change-Id: I8273c9ed9d1f97a93c162d709f30df38bfd576aa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321029
Trust: Pontus Leitzler <leitzler@gmail.com>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2021-05-19 16:08:23 +00:00
Rob Findley a0f4b7b83e internal/lsp/lsprpc: implement cancellation using jsonrpc2_v2
Use the jsonrpc2_v2 Preemption option to support request cancellation.

Also fix the TestRequestCancellation to actually test request
cancellation, and add a V2 version of this test. For now, the
ForwardBinder is not exercised.

Factor out test set-up and tear down.

Change-Id: Ic104e922fa2d0ae570b69c3928e371175db28a9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/321014
Trust: Robert Findley <rfindley@google.com>
Trust: Ian Cottrell <iancottrell@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: Ian Cottrell <iancottrell@google.com>
2021-05-19 14:12:35 +00:00
Rob Findley f451690e36 internal/lsp/lsprpc: partial integration of the jsonrpc_v2 library
Update the protocol package to allow wrapping the jsonrpc2 API, and add
wrappers for v1 and v2 of the API, so that we may switch between them.

Add simple bindings for the lsprpc package for jsonrpc2_v2 package, and
get them working well enough to pass a version TestClientLogging test.
This seemed like a reasonable checkpoint.

Also add some type safety to client closing: all LSP clients must
implement io.Closer.

Change-Id: Ib2e6906e0db0c94102a7e794de932d6b61d54670
Reviewed-on: https://go-review.googlesource.com/c/tools/+/320850
Trust: Robert Findley <rfindley@google.com>
Trust: Ian Cottrell <iancottrell@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: Ian Cottrell <iancottrell@google.com>
2021-05-19 14:12:23 +00:00
Rob Findley 17b3466692 internal/jsonrpc2_v2: consider ErrClosedPipe as a closing error
There was already handling in isClosingErr for errors from Stdin/Stdout
and TCP connections. Add handling for io.Pipe closing errors.

Change-Id: I8d171ab49a3fffe0fca9f0482f6b92d61b1fae1f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/320849
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: Ian Cottrell <iancottrell@google.com>
2021-05-18 18:21:53 +00:00
Rob Findley 6da3d7ace9 internal/lsp/source: re-parse if needed when collecting identifier info
With the new ParseExported logic, we can lose some unexported fields on
exported structs. This can lead to misleading or malformatted hover
information.

Fix this by ensuring we always extract the Spec from a full parse. Since
this path is only hit via user-initiated requests (and should only be
hit ~once per request), it is preferable to do the parse on-demand
rather than parse via the cache and risk pinning the full AST for the
remaining duration of the session.

For golang/go#46158

Change-Id: Ib3eb61c3f75e16199eb492e3e129ba875bd8553e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/320550
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-05-18 02:12:20 +00:00
pjw 8f301ca0d3 internal/lsp: more careful error handling for semantic tokens
The implementation now returns fewer errors to the client. The LSP
specification restricts errors to 'exceptions', so gopls no longer
returns errors if parsing or typechecking fails.

Also, some internal routines that always returned nil errors no longer
return errors at all. The logging for the errors that //line directives
induce was too verbose, and has been turned off. (Many LSP requests
will fail if there are //line directives.)

Fixes golang/go#46176

Change-Id: I18b2cb164b55174f4edbc31e1376da7a8c505a1b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319249
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-05-17 17:18:20 +00:00
Rob Findley 09ab05b0db internal/lsp: exit graceful for modfiles in semantic tokens
Change-Id: I86e6dbdd6e51af9b947c34fd04489ed34687b3c3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319849
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-13 17:35:42 +00:00
Rob Findley cd1be5dbec gopls/internal/regtest: add a failing regtest for vscode-go#1489
Unimported completion computes invalid text edits with windows line
endings.

To enable this test, add support for windows line endings in the regtest
framework. Doing this required decoupling the txtar encoding from the
sandbox, which was a good change anyway.

For golang/vscode-go#1489

Change-Id: I6c1075fd38d24090271a7a7f33b11ddd8f9decf5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319089
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-05-13 13:20:04 +00:00
Rob Findley 57c3a74c41 internal/lsp: get file URI from beginFileRequest in SemanticTokens
Unguarded calls to span.URI.Filename() can panic. beginFileRequest
handles this, so use the URI of the returned FileHandle instead.

Fixes golang/vscode-go#1498

Change-Id: Ie48c27854e4a8ed8cca52ff6547ff580eccb5fd5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319529
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-12 22:01:29 +00:00
Fernandez Ludovic 8287d5da45 go/analysis/passes/sigchanyzer: copy to avoid modifying the AST
The sigchanyzer pass suggests fixes, but it does that
by altering the channel declaration argument.
That causes the buildssa.Analyzer fail to fail,
along with crashing other passes that depend on it.

To fix this, we make a copy of the channel's declaration arguments,
and modify the copy instead.

Fixes golang/go#46129

Change-Id: I807d36abd49cd3ccc2cc9f907aa98349b2e3231f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319211
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2021-05-12 20:59:48 +00:00
Heschi Kreinick 9dfac01ddd internal/lsp/cache: add missing error checks
I wrote this code as if there was going to be a final error check after
all the type checking attempts, but ended up using the result inside the
attempts, errors would likely have resulted in panics. Just do normal,
non-clever error checking.

Change-Id: I665f34f7e6d1a2c3465543cbdc39a723a22a1095
Reviewed-on: https://go-review.googlesource.com/c/tools/+/319371
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-05-12 16:42:30 +00:00
Jay Conrod be4aaae4cf all: update tests to use 'go mod download all' to populate go.sum
In anticipation of CL 318629, 'go mod download' without arguments will
not update go.mod or go.sum. Before 1.16, 'go mod download' would adds
sums for .mod files but not .zip files (which people didn't usually
notice). Many folks found the behavior of adding sums for .zip files
to be annoying.

This change alters tests to run 'go mod download all' to populate
go.sum files. This is equivalent to 'go mod download' without
arguments before CL 318629.

For golang/go#45332

Change-Id: I387d514176f798ae8f17b0b056194196718f57f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318811
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2021-05-11 20:42:14 +00:00
Heschi Kreinick cd1d0887dc internal/lsp/cache: trim more stuff in ParseExported mode
Despite the name, ParseExported only hollowed out declarations -- it
didn't actually drop any from the AST. This leaves a fair amount of
unexported crud behind. Unfortunately, there are a *lot* of ways to
expose an unexported declaration from an exported one, and it can be
done across files. Because of that, discarding unexported declarations
requires a lot of work.

This CL implements a decent attempt at pruning as much as possible from
the AST in ParseExported mode.

First, we analyze the AST of all the files in the package for exported
uses of unexported identifiers, iterating to a fixed point. Then, we
type check those ASTs. If there are missing identifiers (probably due to
a bug in the dependency analysis) we use those errors to re-parse. After
that we give up and fall back to the older, less effective trimming. The
pkg type changes slightly to accomodate the new control flow.

We have to analyze all the files at once because an unexported type
might be exposed in another file. Unfortunately, that means we can't
parse a single file at a time any more -- the result of parsing a file
depends on the result of parsing its siblings. To avoid cache
corruption, we have to do the parsing directly in type checking,
uncached.

This, in turn, required changes to the PosTo* functions. Previously,
they operated just on files, but a file name is no longer sufficient to
get a ParseExported AST. Change them to work on Packages instead. I
squeezed in a bit of refactoring while I was touching them.

Change-Id: I61249144ffa43ad645ed38d79e873e3998b0f38d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/312471
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-05-11 17:48:41 +00:00
pjw 2db0265cb2 internal/lsp: in semantic tokens, better distinguish between types and variables
If A is a type, then in
type B {
  A
} it is a type, but in
type C {
  A int
 }
it is a variable (and similarly in function types). The old code got this wrong.

Fixes: golang/go#46068

Change-Id: Ib7320914de81d2b7377214f53f99f4fea25e00fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318749
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: Robert Findley <rfindley@google.com>
2021-05-11 14:51:35 +00:00
Rebecca Stambler 9cddb0ea22 all: update all dependencies except for sergi/go-diff and golang.org/x/net
Post-release dependency upgrade.

Change-Id: Icee97a77e003cb875f38fb04daab148bfb01c131
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317692
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-05-11 14:29:16 +00:00
Rob Findley 18795da840 internal/typeparams: a new helper library for working with generic code
Tools like gopls will want to add additional features to support working
with generic code, but need to continue to compile at older Go versions
that don't support type parameters.

This CL contains an initial draft of a helper library that may be used
to interrogate generic type information from go/ast and go/types without
having to guard the calling code with a build constraint.

I will use this library to implement some generics features for gopls.
Once we're confident in the API, it could potentially be exported as
x/tools/go/typeparams.

Change-Id: I0ad3050b57cf8d8e8dda7d350d18f5e50f4105ff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317451
Trust: Robert Findley <rfindley@google.com>
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-11 03:28:22 +00:00
Rob Findley 79d39ff544 internal/lsp/source/completion: avoid a panic in package completion
For golang/vscode-go#1486

Change-Id: I48939224778155964712192faf5a437ee10cd2e1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318370
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-05-10 23:22:37 +00:00
Rob Findley fa05545715 internal/lsp/debug: add a facility to track known bugs
Sometimes users report issues related to edge cases in Gopls that aren't
reproducible. In some of these cases, we end up guarding against
conditions that shouldn't be possible, which is an unfortunately fragile
solution.

Add a new debug.Bug function to both annotate such branches as known
bugs, and help find them when they reoccur.  For now this just records
them in the debug server, but in the future we could send the user a
message to the effect of "hey, a known bug has occurred" for debug
builds of gopls.

Also included are some minor cosmetic fixes.

Change-Id: I95df0caf2c81f430661cabd573ce8e338fa69934
Reviewed-on: https://go-review.googlesource.com/c/tools/+/318369
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-05-10 23:21:19 +00:00