1
0
mirror of https://github.com/golang/go synced 2024-09-30 04:34:33 -06:00
Commit Graph

5229 Commits

Author SHA1 Message Date
Rebecca Stambler
78fed78f7d internal/lsp: handle modifications to the workspace module
We should be able to smoothly add and remove modules from the workspace.
This change moves the module-related fields from the view into the
snapshot so that they can be easily modified and recomputed. The
workspace module is now a workspaceModuleHandle.

Updates golang/go#32394

Change-Id: I6ade7f223cc6070a29b6021b825586b753a0daf1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254940
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>
2020-09-18 22:49:48 +00:00
Danish Dua
e94ab72881 internal/lsp/source/completion: improve import suggestion labels
This change improves the labels for import suggestions to only show the
last part of the path. Since VSCode fuzzy searches for labels in text
edit, we now return only the last part of path as text edit instead of
replacing the full import path. Just changing label while returning full
path leads to bad user experience.

Closes golang/go#35877

Change-Id: Ib10e7a3e030dc9b850ff1d9ec8d45240b75b64a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255837
Run-TryBot: Danish Dua <danishdua@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>
Trust: Danish Dua <danishdua@google.com>
2020-09-18 20:11:33 +00:00
Heschi Kreinick
d56e4e40bc internal/lsp/cache: set GO111MODULE=auto in 1.16
1.16 wants to set GO111MODULE=on. There are, AFAIK, two differences
between "auto" and "on". First, if you're in a directory outside of GOPATH
and with no go.mod, "on" will run in module mode with GOMOD=os.DevNull.
I don't think we care very much about that. Second, if you're in GOPATH
with no go.mod, "on" will run in module mode, breaking GOPATH mode.

Breaking GOPATH mode may be desirable for the go command generally, but
for gopls I think it will lead to an unnecessarily bad user experience.
Users will find out when they do their first build or test; there's IMO
no need to also break their editor.

Flip the default back to "auto".

Change-Id: I280e001a9f7e80d65e68c0cb94353d70a7f5425e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255781
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>
2020-09-17 22:16:17 +00:00
Jay Conrod
3791637d67 all: fix tests in preparation for GO111MODULE=on by default
This CL does not fix failures in ./gopls/internal/regtest, which will
be fixed separately.

In refactor/rename.TestDiff, add a go.mod file.

In internal/imports.ProcessEnv.buildContext, set an I/O hook if
GO111MODULE=off in ProcessEnv but not in the current process's
environment.

Context allows the user to set GOPATH, GOOS, GOARCH, and a few other
environment variables, but not GO111MODULE. Context.Import may return
different results than packages.Load if the latter is invoked with a
GO111MODULE value that differs from the caller's environment. Setting
an I/O hook forces Import to run in GOPATH mode, not invoking 'go list'.
This is undocumented, but it should be stable while GOPATH is
supported.

For golang/go#41330

Change-Id: I5679e8941e32dc95b05c234cb2e3fec5cabebced
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255398
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
2020-09-17 22:14:52 +00:00
Danish Dua
d148ae1e14 internal/lsp/source/completion: convert deep completion to bfs
This change converts deep completion from depth first search to breadth
first search.

Change-Id: Iebc7ba8d3acb44928220596065d4e8de53ea9b48
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254542
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-17 21:30:16 +00:00
Heschi Kreinick
0511c4cc7a internal/imports: use ProcessEnv to filter files
In CL 247797 I accidentally used the default build.Context instead of
one generated from the ProcessEnv to match files. This has essentially
no effect because we only allow overriding GOROOT and GOPATH, but it's
still a mistake.

Change-Id: Ibe23c97590fe21609252f048bc2e925f3043dec4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255777
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-09-17 20:40:15 +00:00
Danish Dua
75ebdcb73b gopls/internal/regtest: add expected ranges in completion tests
This change adds tests for package completion in multiline comments and package completion on a newline. It also adds expected ranges in completion tests since simply testing for returned item labels won't catch regression. For more info, see the discussion at https://go-review.googlesource.com/c/tools/+/253177.

Change-Id: Ia42e2645e26647617b32f676952767d2da90e427
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255278
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-17 19:21:54 +00:00
Rob Findley
60aba8ac75 internal/lsp: always show errors from running commands
Some failure modes for suggested fixes were not displaying a failure
message. Refactor so that all errors result in a message.

Fixes golang/go#41413

Change-Id: I939d707626c2bd93c19e28f2197f4f1c66c6947c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255128
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-17 16:15:30 +00:00
Jay Conrod
63098cc47d internal/imports: don't set Context.WorkingDir, which was renamed
This field was renamed to Dir during the 1.14 development cycle. We
don't need to look for it anymore.

For golang/go#34860

Change-Id: I313a931f070e3dc5a711233e7523c309995fe655
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255397
Run-TryBot: Jay Conrod <jayconrod@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-09-17 13:24:29 +00:00
Rebecca Stambler
655488c8ae internal/lsp: fix concurrency issues in view initialization
Address issues from CL 254940.

Change-Id: If4839a8694979fd1951b3fad77abb10860b42b7c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255349
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>
2020-09-17 05:02:09 +00:00
Rebecca Stambler
c537a342dd internal/lsp: pass options by reference instead of by value
We were previously behaving as though the slice/map values in the
options struct could be modified directly. The options should be cloned
before modification. Also, convert any usage of source.Options to
*source.Options.

Fixes golang/go#39592

Change-Id: Ib39f668bca0fa1038162206bd7793fd2049af576
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254558
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>
2020-09-16 22:53:23 +00:00
Heschi Kreinick
c9a70fc28c internal/lsp/cache: fix release tag parsing
A copy and paste error meant that gopls iterated over the built-in
release tags rather than the ones read from go list. If gopls was built
with an older release than the go command in use, it would read past the
end of the slice and die.

Change-Id: Ifc222c7a0bd9662bcd7deedaa069797e213df7b3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255360
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-16 19:50:26 +00:00
Heschi Kreinick
f128e626db internal/memoize: show key type in panics
gopls uses a lot of keys that are just strings, which print without any
type information. Include the type of the key explicitly.

Updates golang/go#41415.

Change-Id: I01cfc685184e7b44c1f562b6536f173da5ae4830
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255357
Trust: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-16 18:32:40 +00:00
Rebecca Stambler
587cf2330c internal/lsp/mod: handle nil pointers in code lenses
Fixes golang/vscode-go#650

Change-Id: I05a3991853d9e61a2e287d4d166264cdbf7231ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255127
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-16 15:04:07 +00:00
Koichi Shiraishi
56d9a0cd34 cover: fix sorting of profile segment boundaries
This is a backport of CL 116976 from cmd/cover in the go repository.

Updates #25767.

Change-Id: I54b8bbfa975141684661edf46081dbd9a304a641
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249619
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Robert Findley <rfindley@google.com>
Trust: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-09-16 14:01:29 +00:00
Rob Findley
c8d9e05b1c gopls/internal/regtest: simplify expectation return values
Returning 'metBy' from expectations was not an ideal API, as extracting
the result value was cumbersome and error prone. It also forced quite a
bit of plumbing.

Using OnceMet, we can improve this by instead using a 'ReadDiagnostics'
expectation that reads diagnostics into a variable.

For golang/go#39384

Change-Id: Ia73e5b496089240df3200626e5696305cb507c9a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255126
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>
2020-09-16 12:40:19 +00:00
Rob Findley
6ec2cde963 internal/lsp/source: add some additional symbol downranking
Downrank symbols if they are:
 1. Unexported and outside of the workspace. Since one wouldn't jump to
    these symbols to e.g. view documentation, they are less relevant.
 2. Fields and interface methods. Usually one would jump to the type
    name, so having fields highly ranked can be noisy.

To facilitate this change and more generally clean up, symbolCollector
is refactored to pass around slices of *ast.Idents rather than build up
'.' separated names as it traverses nested nodes.

For golang/go#40548

Change-Id: Ice4b91cee07b74a13a9b0007fda5fa9a8e447976
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254037
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>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
2020-09-16 12:25:06 +00:00
Rob Findley
e20053b796 gopls/internal/regtest: remove ExpectNow
ExpectNow was surpassed by OnceMet, which serves the same purpose but is
atomic. Since it's no longer used, remove it.

Change-Id: I8ae6c54c2e558e57ba17d2ff7917994c9a80b234
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255125
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:03:49 +00:00
Rob Findley
797bd0f00c gopls/internal/regtest: simplify regtest EditorConfig
WithEditorConfig(fake.EditorConfig{...}) seemed like unnecessary
boilerplate. Simplify the option to just 'EditorConfig'.

Change-Id: I11a3045388f8e642caff78a3f0caa13374b4713a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255124
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:02:33 +00:00
Rob Findley
cbbbe6237a gopls/internal/regtest: add an InitialWorkspaceLoad expectation
The pattern of awaiting initial workspace load has become very common in
regtests. Factor out an expectation variable for this, to clean up.

Change-Id: I2fe0ad94e2584e447baa57b23d4fdf9f8550772e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255123
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:01:37 +00:00
Rob Findley
bf5c620a10 gopls/internal/regtest: move expectations to their own file
We've accumulated a lot of expectations, that could benefit from some
cleanup. Move them to a new file, and reorganize a bit as some of the
logical sections had gotten mixed up.

This change is purely moving code, no other changes.

Change-Id: Ib0a86a5cd686b167e555d5fae77d20d02cfd67a1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255122
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-09-16 12:01:01 +00:00
Rebecca Stambler
f4cefd1cb5 internal/lsp: enable multi-module workspace mode by default in tests
This change enables the multi-module workspace mode by default, so that
we can catch all of the test failures and edge cases. It is still
disabled in GOPATH mode and for any workspaces that contain a module
with a vendor directory.

A few minor changes had to be made to handle changes caused by the
workspace module pseudoversions.

Updates golang/go#32394

Change-Id: Ib433b269dfc435d73365677945057c1c2cbb1869
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254317
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-15 20:16:39 +00:00
Heschi Kreinick
2db8f0ff89 internal/lsp/cache: fix -mod=mod for workspace module setups
When we're in workspace module mode, there may not be a go.mod at the
root of the workspace, so checking modURI != "" doesn't tell us whether
module mode is on. Add a flag to workspaceMode which is exactly that.

There are probably many more places that should be updated, but since
the design is in flux I don't want to cause more churn than necessary.
This is enough to unblock -mod=readonly by default.

(I missed this in CL 253799 because I was running the wrong Go Version.)

Change-Id: I718ee44c7a2547c90f9d62393aba390c9b4b0f46
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254756
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-15 17:38:23 +00:00
Rebecca Stambler
6498648128 internal/lsp: check file kind before showing warning
We had been previously popping up warning for go.mod files.

Change-Id: I6ff016e94ec46467a5c60309f825798961df66f6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254939
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
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>
2020-09-15 03:16:44 +00:00
Rebecca Stambler
3c2036f9a9 go/packages: support overlays for replaced modules
This change implements the approach described in
https://github.com/golang/go/issues/37629#issuecomment-594179751.
This feature is necessary for multi-module workspace support in gopls.

Updates golang/go#32394

Change-Id: Iab328020a2681f8651405922cc25d9d06cb1ac82
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254368
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: 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>
2020-09-15 01:00:53 +00:00
Rebecca Stambler
2b477fad35 tools, gopls: update Go versions in go.mod files to 1.12
gopls is officially supported for Go versions 1.14 and 1.15, but we
test with 1.12 and 1.13 as well.

Fixes golang/go#41383

Change-Id: I89f1a876ccdb25a269a3c39a4d81dd3bf37bd12f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254754
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-09-14 22:26:08 +00:00
Rebecca Stambler
8f9ed77dd8 go/packages: add roots for overlaid packages for all query types
Previously, we only added roots for contains queries. Now, we borrow
some matching logic from the go command to add roots for any new
packages that originate from overlays, no matter the query pattern.
Ideally, we won't have to borrow this logic once 1.16 is released with
native overlay support.

Change-Id: Iaa06f5ecda47820bd41ed0e42d9c2d33a0539b11
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254418
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: Heschi Kreinick <heschi@google.com>
2020-09-14 19:08:12 +00:00
Rebecca Stambler
17fc728d0d internal/lsp: handle staticcheck in code actions
Missed this in CL 254038.

Change-Id: I485f6e9112628dc4ff83e7ea47b59b340742711f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254597
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>
2020-09-14 16:17:55 +00:00
Rob Findley
2350fe8b0e internal/lsp/source: fix panic in addFieldItems
I have no idea what I did to trigger this, but I got a panic in this
codepath. Since this is for completion, it should be OK to simply make
this code defensive, without fully understanding the cause.

Here's the panic:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0xc570f3]

goroutine 5914644 [running]:
golang.org/x/tools/internal/lsp/source/completion.(*completer).addFieldItems(0xc0996ee240, 0x1032020, 0xc0dd21e2a0, 0xc0b99b26f0)
        /usr/local/google/home/rfindley/src/tools/internal/lsp/source/completion/completion.go:1065 +0x193

Change-Id: I82350b30172ead95b6611962c2e040cc49259dc2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254697
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>
2020-09-14 15:58:11 +00:00
Rebecca Stambler
97363e29fc internal/lsp: handle staticcheck in didChangeConfiguration
As we have modified the ways that we control which analyzers get
executed for a given case, we have lost the behavior of enabling and
disabling staticcheck smoothly. This CL splits out the staticcheck
analyzers from the main group so that the "staticcheck" setting can
override whether or not a given staticcheck analysis is enabled.

Fixes golang/go#41311

Change-Id: I9c1695afe4a8f89cd0ee50a79e83b2f42a2c20cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254038
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-13 03:21:22 +00:00
Michaël Lévesque-Dion
6422fca01d report cycle when visiting a grey analyzer
Fixes golang/go#40408

Change-Id: I04cd852f816f072e0e89c8ed5af636b09d0b54b4
GitHub-Last-Rev: 627dd414eb90d239cab9fce38454d43be133276e
GitHub-Pull-Request: golang/tools#244
Reviewed-on: https://go-review.googlesource.com/c/tools/+/244799
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2020-09-11 19:35:55 +00:00
Heschi Kreinick
b43031a33b internal/lsp/cache: fix for default -mod=readonly
Go 1.16 may set -mod=readonly by default. To maintain current behavior,
gopls needs to override that by passing -mod=mod to all its go
invocations.

While this behavior should be safe on all modern versions of Go, I gated
it on 1.16 just for safety's sake.

Change-Id: Ic8088213d1ab9ab3a3ed0b51f47b2c222974d613
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253799
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-11 18:30:43 +00:00
Rebecca Stambler
7ad463ce66 gopls/internal/regtest: add a test for new symbols in test variants
I believe this has been fixed by previous file watching improvements.

Fixes golang/go#38358

Change-Id: I8feba96af8c87795533bf31769e2fcdbbb96d309
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253797
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-09-11 15:33:31 +00:00
Peter Weinbergr
d49a6cb6ca internal/lsp/protocol: add support for upcoming LSP 3.16
These are the changes needed to support Semantic Tokens in the LSP protocol.

Added a function to server.go to make generating server_gen.go work again.

Change-Id: I2e09220560b080dd666e25eaf1a39b9960b6f871
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253938
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-11 12:00:08 +00:00
Rebecca Stambler
d179df38ff internal/lsp/cache: automatically construct the workspace module
This change adds an experimental configuration, which when enabled,
shifts gopls to operate in multi-module mode. It implements the
super-module as described in
https://github.com/golang/proposal/blob/master/design/37720-gopls-workspaces.md.
Replace directives are also added when a workspace module requires
another workspace module (which has not yet been mentioned in the design
doc).

A user-provided workspace gopls.mod file is not yet supported, as it is
not yet testable. Clients will need to add support for change
notifications for the gopls.mod once it is added.

Updates golang/go#32394

Change-Id: I5089358603bca34c5c8db9e5a00f93e1cca0b93f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247819
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-11 04:00:25 +00:00
Rob Findley
571a207697 internal/lsp/source: fix duplicates in workspaceSymbols
The logic to de-dupe workspace symbols was broken in two ways:
 - The 'seen' map of files already processed was never written.
 - The key to 'seen' was *ast.File, which doesn't work if we parse
   twice.

Fix this by de-duping instead on span.URI.

Change-Id: Iedadfac17a0a993570ff4f8301a97815477f1c2c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/254117
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-10 22:23:12 +00:00
Rebecca Stambler
53e29e9d12 internal/lsp: show a warning message when opening an "orphaned" file
Build tags are a common stumbling block for users of gopls, as build
tagged files may be excluded from the initial workspace load without a
clear warning. This change adds a check for every opened file to confirm
if it maps to a package. If not, we show a message with suggestions.

A follow-up improvement might be to check if the opened file actually
has build tags to make the error message more precise (and give a better
example config).

Updates golang/go#31668

Change-Id: I829d8546edea65aa08274021bfde8ea2fb6eeaa1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253798
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-10 16:52:16 +00:00
Rob Findley
d6107fe4b8 gopls/internal/regtest: skip failing test for go1.13 and below
I missed that this test was failing when fixing the 1.12 build, because
I forgot that I moved the regtests to the gopls module. Hoisted by my
own petard.

Change-Id: I1cf601e730fa7bb92885f55b68845b539e57e1a0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253937
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-10 15:53:27 +00:00
Peter Weinbergr
b484961fa2 x/gools/gopls: document settings for working on source distribution
Gopls needs to use the right go command to work properly on a source
distribution. One way of getting this done is by setting go.alternateTools.

Fixes golang/go#38603

Change-Id: Ie379b372c48f651a22c73d93f8608194c5e3a417
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253297
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-10 14:38:07 +00:00
Rebecca Stambler
44a2922940 internal/lsp, go/packages: fix Go 1.15-related overlay bug
Something about the ordering of `go list` results must have changed in
Go 1.15, so overlays with test variants were failing to get the correct
imports. Technically, the correct solution would have been to support
overlays for a package *and* its test variant, but for the purposes of
gopls, it's actually more important that the overlays apply to the
package itself (rather than its test variant).

Fixes golang/go#40685

Change-Id: I3282557502f7f30bf484e1e6c17b90db824bc7d0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252681
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-09 21:09:14 +00:00
Heschi Kreinick
6a8222ee25 gopls/doc: generate settings JSON, docs
gopls has many settings. We want to automatically generate
documentation, and we want to allow clients to perform their own
validation if they so desire.

Using all three of AST, type information, and reflection, generate a
JSON description of the settings and their default values. Add a gopls
command that prints it. Add a documentation generator that uses it to
write settings.md.

I assumed that everything not explicitly documented was experimental,
and moved it into that section. I also moved expandWorkspaceToModule to
experimental; I hope it's not long for this world, personally.

Along the way, rename many fields, make the enum matching case
insensitive, and add a stringer call so that the defaults print nicely.

Fixes golang/go#33544.

Change-Id: Ibb652002933e355ed3c6038d6ca48345b39b3025
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252322
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-09 20:53:33 +00:00
Rebecca Stambler
201d438bce internal/lsp: add more tests for package completion
This change adds one more test for package completions (and slightly
modifies the way we pass in file content without a terminal newline).

Also, a few tiny modifications to the package completion code.

Change-Id: I3041b5ad648873881b2b8df17df6f78fbd1898e5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253177
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Danish Dua <danishdua@google.com>
2020-09-09 17:18:21 +00:00
Rebecca Stambler
12e1bf57a1 gopls/doc: add information about supported Go versions
Fixes golang/go#39146

Change-Id: I89c2883d8e2d9e97e7b5212e61d54fc03e1c2298
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253281
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-08 21:18:11 +00:00
Rebecca Stambler
a4118eb6f6 internal/lsp: break up fillstruct testdata to make it more manageable
Broke a.go into a few files (no real logic to it). These tests could be
categorized better, but it's a good start just to break up that huge
golden file.

Change-Id: I2c173f11ea2766e9232e3ec838c16f535cbee788
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253279
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-08 20:59:11 +00:00
Rebecca Stambler
2e7746ed96 internal/lsp: parse Go files through the new snapshot's cache in clone
I think we had discussed making this change after you finished your
cache rewrites, but I never got back to it. Let me know if you think
there's a better way to do this.

Change-Id: Ia7dfe6830110f21e0d2683e64f8ee0d2549afdea
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253280
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-08 20:42:25 +00:00
Rebecca Stambler
27b65b427b gopls/doc: add memory usage info to troubleshooting guide
This way, we can close the memory usage tracking issue.

Fixes golang/go#36943

Change-Id: I1933c103443797cb80dec3fa54fc3ddf281cf832
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253577
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-08 20:42:16 +00:00
Rebecca Stambler
77fbfaef01 internal/lsp: clean up some of the extract function code
This CL creates a struct that simplifies some of the extract function
logic. Also, add a test for extraction with an underscore in the
selection (Josh mentioned that this might not work, but it seems too).

Change-Id: If917614a5824e84fb79a07def3eb75f48f10a5b9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253277
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-08 20:39:53 +00:00
Rebecca Stambler
93a3566fcb internal/lsp/cache: don't set an error by default in load
Change-Id: Icd4495a37f6a3a2eb148d9a1b1949e3741cdd966
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252980
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-08 20:16:59 +00:00
Danish Dua
acefd226e2 internal/lsp/source: move completion to its own package
Completion is slowly becoming a large part of internal/lsp/source and it
makes sense to move to its own seperate package inside source to make
future refactors easier. As a part of this change, any unexported
members from source required by completion are now exported. Util
functions only required by completion are moved from
internal/lsp/source/util.go to internal/lsp/source/completion/util.go.

Change-Id: I6b7405ec598c910545e649bb0e6aa02ffa653b38
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253178
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-08 19:19:08 +00:00
Rob Findley
ea3a2cdbfb internal/lsp/source: support some fzf-like tokens in symbol matching
It's useful to be able to switch between case sensitive, case
insensitive, and fuzzy matching for symbol without having to reload
gopls. FZF has some nice syntax for this:
  https://github.com/junegunn/fzf#search-syntax

Adopt a subset of this syntax for our symbol search:
  ' for exact matching
  ^ for prefix matching
  $ for suffix matching

It would be straightforward to also support inversion, using
'!', but I deemed this unnecessary.

I think we should adopt this, since none of these symbols conflicts with
Go identifiers, or (AFAIK) with special syntax in major LSP clients.

Change-Id: If2e4d372d4a45ace5ab5d4e76c460f1dcca0bc2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248418
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-08 16:35:05 +00:00