Commit Graph

2040 Commits

Author SHA1 Message Date
Rebecca Stambler d49c4edd7d internal/lsp: do not allow non-Go files to be loaded in packages.load
Fixes golang/go#41962

Change-Id: I47ec376213541095386add09e63a5127473a6d27
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263983
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>
2020-10-21 00:02:07 +00:00
Rob Findley 226fd2f889 internal/lsp/fake: factor out working in a temp directory
In subsequent CLs, tests are added that don't need the full machinery of
fake.Workdir (file tracking, etc.). Factor out some of the facility for
writing a txtar-encoded temp directory, and working with relative paths.

Change-Id: Iae25c37a8fd8de2dfe6c91e507d9be01440d3492
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263523
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-10-20 16:11:33 +00:00
Hana 90550980fc internal/lsp/source: use 'gopls.' instead of 'gopls_'
And, export CommandPrefix const so api_json generator can use it.

Update golang/go#41187

Change-Id: Ie976b774d64ba707152b6f659a15aef19ef12dcd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263057
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-10-20 14:19:29 +00:00
Peter Weinbergr f5c826d190 internal/lsp: hold notifications until gopls is initialized
Errors in options generate showMessage notifications, but these
were lost if they were sent before the initialization handshake completes.

Change-Id: I011da2387467bb6bf188201a7294e1bb30805cbc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263518
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>
2020-10-20 12:34:48 +00:00
Heschi Kreinick b894a3290f all: use explicit -mod, -modfile fields for gocommand.Invocation
Build flags, -mod, and -modfile are all accepted by disjoint go command
verbs. Mixing them together had the effect of forcing gocommand users to
figure out which went where themselves, which was annoying and
error-prone. Add ModFlag and ModFile fields to Invocation and update all
uses to use them.

go/packages has a BuildFlags field that's bad for the same reason. Add
private modFlag and modFile fields that forward to the corresponding
Invocation fields.

imports.ProcessEnv gets the same treatment.

Fixes golang/go#41826.

Change-Id: If74d19146e9e62930d7c34f40859c27c25566c4e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263213
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-10-19 17:57:15 +00:00
Rob Findley 0a3dcccdcf internal/lsp/source: add a FileSource interface
Rename Snapshot.GetFile to GetVersionedFile, and make the signature of
GetFile consistent with the corresponding method on session and cache.
This allows algorithms that depend only on file state to be expressed
using this API. In a subsequent CL, this is used for building and
testing the workspace module.

Preeemptively add the FileSource interface for use in these algorithms.

Change-Id: I550906e554fd290dcdf4cac442d5f223e0f644c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263522
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-19 16:07:06 +00:00
Rebecca Stambler b2746f1d7a internal/lsp: fix nil pointer exception in initialization
Fixes golang/vscode-go#802

Change-Id: Ide3e834d413efcb394370a0c2e5ffa412a45e1a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263520
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: Peter Weinberger <pjw@google.com>
2020-10-19 15:59:33 +00:00
Rob Findley 6003fad69a internal/lsp/source: delete unused Snapshot.IsSaved
Change-Id: I0f71798d81618a0a9bb992056a3c2d5f71aed150
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263207
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>
Trust: Robert Findley <rfindley@google.com>
2020-10-17 00:14:24 +00:00
Rebecca Stambler a03874c3f7 internal/lsp: clean up unused parameters
Noticed these when I enabled the "unusedparams" analyzer. Not really
necessary to fix most of them, but seemed harmless.

Change-Id: I77c6e5f7c79f1abb701cd3332642486c34049736
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263203
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-10-16 23:51:31 +00:00
Rob Findley 2d76fa4fd5 gopls/internal/regtest: delete OpenFileWithContent
OpenFileWithContent is identical to CreateBuffer. Delete it in favor of
the latter, which (in my opinion) has the clearer name.

Change-Id: Icf0f017a9a71a273ace6d697c7d669a2df2e3ba8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263206
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>
Trust: Robert Findley <rfindley@google.com>
2020-10-16 23:30:35 +00:00
Rob Findley 593bd9b1d2 internal/lsp/cache: delay transitive invalidation in snapshot.clone
Currently, walking the transitive closure of invalidated packages
happens eagerly while we invalidate each file. Delay this until after
looping through invalidated files, so that we may more easily consider
invalidations not directly associated with an individual file change.

Change-Id: Id6a95098ce6d5d3ec70143c029ac7d2c9b8c7d28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263205
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-10-16 23:30:29 +00:00
Rebecca Stambler e52f5410cf internal/lsp: fix analysis in all experiments, disable unusedparams
The reason unusedparams wasn't showing up was because we didn't handle
the analyses settings correctly. Fix it and remove unusedparams.

Change-Id: Ia8636c306d136a718d1d12a80326117b34f5da28
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263201
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-10-16 23:27:24 +00:00
Rob Findley eae18abd75 internal/lsp/cache: factor out guessPackagesForURI from snapshot.clone
To simplify snapshot.clone a bit, factor out the logic to figure out
which packages to invalidate when a new file arrives. This also made it
easier to improve the algorithm by caching os.Stat results when walking
known packages.

Change-Id: I012b60e8ad73eb4df80950aac48791204877e9e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263204
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-16 21:48:57 +00:00
Rebecca Stambler de28cda03d internal/lsp: remove staticcheck and gofumpt from all experiments
Change-Id: I7b60a06ca5442ce2736d3c1a2d55a0f91b4d44fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/263197
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-10-16 20:25:18 +00:00
Peter Weinbergr a2250d31f3 internal/lsp: add gopls semtok command and semantic token tests
The command 'gopls semtok <file>.go' produces a version of <file>.go
decorated with comments describing tokens as semantic tokens. The
format is described towards the top of cmd/semantictokens.go.

There are also tests in testdata/semantic/. a.go is used by lsp_test.go
(with -cover) to show that essentially all of semantic.go is executed.
b.go illustrates the handling of strange, but legal, constructs
like 'const false = nil and non-ascii'. The .golden files show
the expected results.

The implementation will panic, rather than log, on unexpected state.

gopls semtok has been run on all the .go files in x/tools and in
the source distribution. There were no unexpected messages nor panics.

Change-Id: I11715bcc8d6830d1951eb58239978c4a363bbc30
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262198
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>
2020-10-16 18:10:36 +00:00
Hana c90119023d internal/lsp/source/genapijson: add 'gopls_' prefix to commands
This CL adjusts the genapijson program as the follow up of the command
name change cls. The program loads the command list by parsing the
source code and uses the result to compute the codelens list.
Involved data types are also used for JSON marshalling, so I just
update the command name after codelens list loading is done using
the command data.

Updates golang/go#41187
Fixes golang/go#41985

Change-Id: Ic5e818e11b09c649f462fe87dabee0be64c96c2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262354
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-16 15:26:35 +00:00
Rob Findley a5d9e455e9 internal/lsp/source: be consistent about command identifiers
The primary identifier for gopls commands was changed from Command.Name
to Command.ID(), but this change was not made in the commands passed
back to the client via ExecuteCommandOptions.

Fix this, and ensure that our regtests actually check commands against
the list of supported commands that has been sent.

For golang/go#41985

Change-Id: If566584f157e8a86d26eac6353dbfd772b298cfc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262597
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-15 18:20:29 +00:00
Heschi Kreinick b29caf79d4 internal/lsp/source: include setting name in all settings errors
Every setting parse error should include the name of the error for user
sanity. Add it in the errorf method, clean up redundancy, and make
existing errors more consistent/correct.

Updates golang/go#41964.

Change-Id: I8f980ceb5d82d4238edcd4095ea0e9572ac9c271
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262353
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-10-15 17:44:10 +00:00
Heschi Kreinick 828e89dd29 internal/lsp: fix env setting type
We stored the user's environment settings as a string slice, but users
set it as a map. It turns out that we have code spread around to convert
it both back and forth, so rather than hack up the doc generator,
so centralize that code and change the native representation to a map.
We end up with slightly less code.

Fixes golang/go#41964.

Change-Id: I975c69524c7d79c7d09079f44cc44a27e72ba285
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262351
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-10-15 17:44:03 +00:00
Heschi Kreinick 6e6f73a58b internal/lsp: fix mismatches between doc and settings
Fix a few settings whose documentation was bad in various ways:
 - semanticTokens' was not camel case; changed to semanticTokens.
 - experimentalPackageCacheKey was not hooked up to a setting; do so.
 - literalCompletions is for tests only; hide it.
 - completionBudget should be specified as a duration string, not number
 of nanoseconds.
 - experimentalDiagnosticsDelay should have been affected similarly to
 completionBudget but is not mentioned in the bug.

env is next.

Updates golang/go#41964.

Change-Id: I3470958cbdfc46daa76da297fc1a56da4a3f10ce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262345
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-10-15 17:43:57 +00:00
Danish Dua 1610a49f37 internal/lsp/source/completion: use a minimum budget of 10ms for shallow completions
Type-checking can be very expensive for large packages and leave no
budget for shallow completions. This change adds a minimum budget of
10ms so we show the user at least some shallow suggestions.

Updates golang/go#41434

Change-Id: If2ef59c3fbdcfa2ebaabb21256cf606a4f9c14d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262347
Trust: Danish Dua <danishdua@google.com>
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-14 23:16:27 +00:00
Danish Dua 64a9e34f37 internal/imports: dedupe import paths for standard library packages
This change dedupes cached standard library packages too since we might
see some of them again while reading disk.

Fixes golang/go#41745

Change-Id: I879bfd9e199dffdde2d88438124154f164f64f00
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261081
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-10-13 20:10:25 +00:00
Danish Dua c16b75f9e5 internal/imports: bump relevance for modules with higher major versions
This changes bumps relevance for modules with major versions >1 so the
results for unimported members are ordered by major version.

Updates golang/go#41800

Change-Id: I64f4a1cf78a101acf4229433d06b5793246962f5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261084
Run-TryBot: Danish Dua <danishdua@google.com>
Trust: Danish Dua <danishdua@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-13 19:42:24 +00:00
Pontus Leitzler 8c269738d7 gopls: add "go test" code action
This change adds "go test" as a code action and also introduce the
concept of explicit code actions, i.e. code actions that aren't returned
to the client unless it explicitly ask for it.

The purpose is to be able to have a mechanism that allows users to
execute a specific command in one shot, and future CL:s will add more of
the existing code lenses as explicit code actions. Code lenses can't be
used directly since they lack the range/kind combo to make them unique.

Updates golang/go#40438

Change-Id: I245df4e26c9e02e529662181e2c1bc44f999e101
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259377
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Peter Weinberger <pjw@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-10-13 16:52:01 +00:00
Rebecca Stambler 2db1cd7910 internal/lsp: extract mod errors in load and treat them like diagnostics
This change pulls out the logic to process module-related errors from
go/packages.Load out of internal/lsp and into internal/lsp/cache. This
simplifies diagnostic handling in internal/lsp, as we can just return
a *source.ErrorList. Most of this is just a code move, not really a
logical change.

This also fixes the staticcheck error :)

Change-Id: Ic6cad3f59a7e4492dea85b8dcfa9e3f24a371803
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260805
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-10-13 05:33:47 +00:00
Rebecca Stambler 5bd0538631 internal/lsp: move the workspaceMode into the snapshot
Workspace mode makes more sense as a property of the snapshot, since
it is determined based on the modules in the workspace. Move it to the
snapshot and enable the GOPATH to modules test. The mode switch means
that we may run `go mod` commands before a `go.mod` is on-disk, so add
handling for that case.

Also, remove the code added in CL 258121 to treat packages starting with
a "_/" the same way as command-line arguments--that's not actually
correct because perfectly valid packages can also have a "_/" package
path prefix.

Fixes golang/go#40340

Change-Id: I35044f5d108983ba00df1359698bf14217caa982
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260078
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-10-12 19:26:20 +00:00
Peter Weinbergr ed2f502026 internal/lsp/semantic.go: generate semantic tokens
This Cl adds all the support for producing semantic tokens.
vscode 1.49.1 (the current version) does not ask for semantic tokens;
vscode-insiders does.

There are no categories for statement labels, nor for constant
values of boolean types. (The former doesn't exist in Typescript, and
boolean isn't a type in Typescript.)

The CL after this one will provide for extensive testing.

Change-Id: I589f51d510b0e423c947f4d95f685e6ba696506d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258477
Run-TryBot: 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>
Trust: Peter Weinberger <pjw@google.com>
2020-10-11 14:58:50 +00:00
Rebecca Stambler 6e5c6d77dd internal/lsp: handle nil pointer in semantic tokens
Fixes golang/go#41873

Change-Id: I877478632654cee4210ab46daae45e4aa315c892
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260806
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: Peter Weinberger <pjw@google.com>
2020-10-10 14:55:03 +00:00
Rebecca Stambler fcf82128ed internal/lsp/source: handle a possible nil pointer in call hierarchy
Change-Id: I90e7b09853485cfd99a99eadd534e47fe69fb1ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260800
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: 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: Danish Dua <danishdua@google.com>
2020-10-09 16:22:40 +00:00
Rebecca Stambler 96877f285f internal/lsp, gopls: require a "gopls_" prefix on all commands
Updated the generator to check for this. Necessary to fix command name
collision in VS Code Go. Not the nicest solution, but seemed like the
least invasive one.

The codelens configuration is a little strange now, with the "gopls_"
prefixes, but the alternative is adding the prefix when processing the
config and that would make the default look different from the example.

Fixes golang/go#41187

Change-Id: I5cf42f4a96f6252016dcd5c40a4ac401e1b30a8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259204
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-10-09 03:22:23 +00:00
Rebecca Stambler 9ab7e51527 internal/lsp: don't show blank identifiers in outline
Fixes golang/go#41654

Change-Id: Ie8ac59051e19d2d312ba48b6649660f53b573731
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259142
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: Peter Weinberger <pjw@google.com>
2020-10-09 01:09:51 +00:00
Rebecca Stambler 7ddb464c7c internal/lsp: add "type " to hover messages for structs/interfaces/etc
Fixes golang/go#41357

Change-Id: Iccc039425110ea37499e18d8a81e577a9c1b0b01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260006
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: Peter Weinberger <pjw@google.com>
2020-10-09 01:01:41 +00:00
Heschi Kreinick d01b322e6f internal/lsp/cache: extract goimports code
Many of the View's fields are for goimports, which is a good sign it
should be extracted into a separate struct. Do so in preparation for
redesigning the lifecycle.

I'm not certain this is the right direction but I don't want to deal
with a zillion merge conflicts as I figure it out. I'll move it back
later if it does turn out to have been a mistake.

No functional changes intended, just moved stuff around.

Change-Id: Ide4c2002133d00f6aaa92d114dae2b2ea3ad18fc
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260557
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-10-08 18:49:44 +00:00
Rob Findley 4c6f507b8a gopls/doc: use enum value docstrings, if they exist
symbolStyle is a subtle enough setting to need documentation for its
possible values, but it is awkward to have to put this documentation in
the docstring for the type rather than the docstring for the value
specs. Update the generator to support this.

Change-Id: I276ec30c489719b2629a307faa506959decd6064
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258718
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Robert Findley <rfindley@google.com>
2020-10-08 18:01:53 +00:00
Rebecca Stambler ffec97847f internal/lsp: handle major versions above v0/v1 in workspace module mode
Workspace mode did not yet support major versions other than v0/v1. To
do so, we have to check the major version before creating the fake gopls
workspace pseudoversion that goes in the workspace module.

Fixes golang/go#41807

Change-Id: I108fe504fdf9e9a0ce23f7102991c9ae78f12a9f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260004
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-10-08 17:44:24 +00:00
Rob Findley 03e951c4ab internal/lsp/source: add an experimental new cache key for packages
We've recently noted that hashing the packages.Config into the cache key
for the type checked package is probably unnecessary, given that all the
other critical inputs into the typechecker are already included
(packageID, parsed files, and deps). Furthermore, when using a gopls
daemon this causes unnecessary cache misses, because the packages.Config
includes things like working directory that no longer matter once other
inputs to type checking have been computed.

Add an experiment flag that removes the packages.Config from the cache
key. An experiment is used to stage this change as comprehensively
testing the cache is ~impossible.

Change-Id: I7ba73daaa71a80ec996decaa9817ec515b5eeb6e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260737
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-10-08 17:20:56 +00:00
Rebecca Stambler 9df69603ba internal/lsp: don't pass build flags to `go mod` commands
This is a temporary fix--golang/go#41826 is a better approach.

Fixes golang/go#41803

Change-Id: Ia055c5e171fe5d4f6d67e9e2e9e7c85fe254605e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260000
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-10-08 02:52:39 +00:00
Rebecca Stambler 0806396f15 internal/lsp: don't show an error for "allExperiments" in (options).set
Missed this in CL 260002. Added to the unit tests :)

Change-Id: I81607fd3cbbf021771e09ecd75952f27a622e754
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260005
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-10-07 03:26:33 +00:00
Rebecca Stambler d5f20aad3b gopls: add regtest mode for experiments, like workspace module tests
This CL adds another regtest mode for trying out experiments, like the
workspace module mode. Before this CL, we lost coverage for default
mode when we turned experimental module mode on by default.

Removed TestNoWorkspaceModule, as it was just a placeholder until this
mode was available.

Change-Id: Ie3e4c2daec3e635c188bafa25b33dd178da875a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258518
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-10-07 01:32:53 +00:00
Rebecca Stambler 45061abf50 internal/lsp: add support for an "enable all experiments" settings
This setting automatically turns on all of the off-by-default gopls
features so that users can opt in to all experiments.

Fixes golang/go#41763

Change-Id: Ia6998128649a081c2a1e8eb08c2db6d795a73143
Reviewed-on: https://go-review.googlesource.com/c/tools/+/260002
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-07 01:14:59 +00:00
Rebecca Stambler a00137c514 internal/lsp: default to workspace module mode even with vendor dirs
We were previously opting out of workspace module mode when any module
had vendor directories. While we still haven't decided how to handle
vendoring, it simplifies things to opt experimentalWorkspaceModule users
in to the workspace module mode when they have modules with vendoring.

Temporarily require default mode for the inconsistent vendoring test
(golang/go#41819).

Fixes golang/go#41725

Change-Id: Ifa494daea51a2a3bb2e6bc3026bfb9e8118d31a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259623
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-10-07 00:01:20 +00:00
Danish Dua 454bc3d4df internal/lsp/source: show references to interface methods
This change adds ability to show references to interface methods.
Instead of just showing direct references to a type, we also show
references to the type through an interface now.

Change-Id: I9d313b3b77c75adb9971dc56ee86caa697d03c90
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259998
Trust: Danish Dua <danishdua@google.com>
Run-TryBot: Danish Dua <danishdua@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-06 22:15:05 +00:00
Heschi Kreinick 23a3aa10a2 internal/lsp: improve handling of files not in views
didModifyFiles and DidModifyFiles were tightly coupled but also repeated
each other's work a bit, and inconsistencies in the implementation led
to golang/go#41777.

Push all the work of assigning a "best view" down to the Session, and
always assign it somewhere, matching the logic in ViewOf. This would
in principle allow us to diagnose random files, but we only diagnose
workspace packages.

Fixes golang/go#41777.

Change-Id: I6dab32b98bdff6edd07032d84a8fec1b82ecd283
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259877
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-10-06 18:39:45 +00:00
Rebecca Stambler 90a82dd33a internal/lsp/cache: actually remove the view's modURI and sumURI
Should've done this in an earlier CL.

Change-Id: Id0b39c80802c4902f6986d1909112ebba3a9751c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258939
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-10-06 17:02:58 +00:00
Rebecca Stambler 576e169c3d internal/lsp: fix hover for builtin error method (Error)
Looks like this may never have worked. "Error" does not appear in the
builtin package's scope, so we have to look up "error" and then find
the method. A little convoluted, but it works.

Change-Id: I5fe4e96d5c51a1fdc683e44b9a80e0cbdab85422
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259143
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: Peter Weinberger <pjw@google.com>
2020-10-05 18:50:03 +00:00
Dan Kortschak 1ccce621de internal/lsp/cache: prevent version from including line break
Change-Id: I3caf8900039eaff9676c5a4040e693e52590d417
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259418
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
2020-10-05 18:47:51 +00:00
Rebecca Stambler 9854aba098 internal/lsp: unconditionally create changedFiles map
I don't think that creating it lazily was really buying us anything.

Fixes golang/go#41779

Change-Id: Ie19e1a62178a26744aca50cf6e40e380aed5afff
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259618
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-10-05 18:35:59 +00:00
Danish Dua ecd9fd270d internal/lsp/source: ignore empty package names for completion
Workspace packages seem to contain an empty package name when no
package is present, we can just ignore it since it leads to an
irrelevant completion suggestion.

Fixes golang/go#41746

Change-Id: I4820751ad0f741dd0d29b42485b41bb4c296a169
Reviewed-on: https://go-review.googlesource.com/c/tools/+/259217
Run-TryBot: Danish Dua <danishdua@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Danish Dua <danishdua@google.com>
2020-10-02 18:49:44 +00:00
Rob Findley 76a79a66c3 internal/lsp/source: factor out enum options pattern
Factor out processing of string enums when setting options results. In a
couple places this will result in errors being detected for invalid
values where they weren't before. Interestingly the default branch for
symbolMatcher was 'caseInsensitive', when in fact the default matcher in
the absence of any setting is 'fuzzy'. The command tests were implicitly
relying on this bug, passing 'default' to mean 'caseInsensitive'. Fix
this.

Also add a test, since option processing is not trivial.

Change-Id: Ib3ec4b1619add4c7315b6a689ca257e068da6027
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258658
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>
Trust: Robert Findley <rfindley@google.com>
2020-10-02 18:00:38 +00:00
Rob Findley 7e5cd54378 internal/lsp/source: improve documentation for symbolStyle
Now that we have documentation generation, improve the docstring for the
symbolStyle option.

Change-Id: I3c6de430eea501ecf797a11873c53c565cae9075
Reviewed-on: https://go-review.googlesource.com/c/tools/+/258617
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>
Trust: Robert Findley <rfindley@google.com>
2020-10-02 17:38:50 +00:00