Commit Graph

45 Commits

Author SHA1 Message Date
Muir Manders dd255f2351 lsp/source: enable experimentalPostfixCompletions by default
Leave the options flag so people can disable it for now if needed.

Updates golang/go#39507.

Change-Id: I78bbac157caa18c5d9a8e2ffe1a5c5eba4c6c30f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/317389
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: Peter Weinberger <pjw@google.com>
2021-05-05 22:35:07 +00:00
Peter Weinbergr 7cab0ef2e9 internal/lsp: support template files
Provide some support for template files, implementing most of
https://docs.google.com/document/d/1clKAywucZVBXvL_v4mMhLQXso59lmQPMk1gtSpkV-Xw

Template support is controlled by the option 'experimentalTemplateSupport'
which defaults to false.

Most of the code is in a new 'template' package. Implemented are
semantic tokens, diagnostics, definitions, hover, and references,
and there is a stub for completions.

This code treats all the template files of a package together, so as
to follow cross-references.

Change-Id: I793606d8a0c9e96a0c015162d68f56b5d8599294
Reviewed-on: https://go-review.googlesource.com/c/tools/+/297871
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>
2021-05-05 01:45:45 +00:00
Pontus Leitzler 7c72a84860 go/analysis/passes/fieldalignment: clarify reported diagnostics in docs
It wasn't obvious that there are two different kind of diagnostics
reported by fieldalignment, one for struct size and another for pointer
bytes.

The documentation now mentions both types, and shows an example that
clarify what "pointer bytes" are.

Fixes golang/go#45541

Change-Id: Ia62fb05980ddddf52e579ac51459aaaed168cfa7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/314469
Trust: Pontus Leitzler <leitzler@gmail.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-27 20:55:22 +00:00
Rob Findley 7c93484b9a internal/lsp: add a command to start the debug server
The utility of the debug server is limited by the requirement to start
gopls with the `-debug` flag and then look in the logs to see which port
the debug server is bound to.

This CL adds a new custom command `gopls.startDebugging` to start the
debug server on demand if it isn't already running, and return its debug
address. It also does some gymnastics to make this turn on debugging for
any intermediate gopls forwarders, when using daemon mode.

For golang/go#45518

Change-Id: I48a90088f96aca54f34f93bedbfe864515320f61
Reviewed-on: https://go-review.googlesource.com/c/tools/+/309409
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-04-26 15:43:18 +00:00
Heschi Kreinick e435455aa1 internal/lsp: introduce MemoryMode
We still hear from users for whom gopls uses too much memory. My efforts
to reduce memory usage while maintaining functionality are proving
fruitless, so perhaps it's time to accept some functionality loss.

DegradeClosed MemoryMode typechecks all packages in ParseExported mode
unless they have a file open. This should dramatically reduce memory
usage in monorepo-style scenarious, where a ton of packages are in the
workspace and the user might plausibly want to edit any of them.
(Otherwise they should consider using directory filters.)

The cost is that features that work across multiple packages...won't.
Find references, for example, will only find uses in open packages or in
the exported declarations of closed packages.

The current implementation is a bit leaky; we keep the ParseFull
packages in memory even once all their files are closed. This is related
to a general failure on our part to drop unused packages from the
snapshot, so I'm not going to try to fix it here.

Updates golang/go#45457, golang/go#45363.

Change-Id: I38b2aeeff81a1118024aed16a3b75e18f17893e2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/310170
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-04-23 19:11:18 +00:00
Heschi Kreinick be791d07ff internal/lsp/source: small fixes to directory filters
Add missing newlines in documentation, and allow trailing slashes in the
filter expressions.

Change-Id: I90106b209222d8cc542e3517c6ff6edb2569243d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/308453
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2021-04-08 19:22:05 +00:00
Muir Manders 94a19427f1 internal/lsp/completion: move postfix completions behind option
Move postfix completion functionality behind an experimental option
flag. For now users can enable it by setting
"experimentalPostfixCompletions" or "allExperiments".

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

Change-Id: I75ed748710cae7fa99f4ea6ea117ce245a4e9749
Reviewed-on: https://go-review.googlesource.com/c/tools/+/296109
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Heschi Kreinick <heschi@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-29 18:55:49 +00:00
Rob Findley 6d45e3d999 internal/lsp: add a temp workspace per folder, and a helper command
Locating the workspace module by convention has multiple problems:
 + gopls's view of $TMPDIR might be different from the client
 + there might be multiple views
 + there might be multiple gopls sessions per pid

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

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

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

Updates golang/go#42252

Change-Id: I0641cebe09cd376dfa27373cac30397711c64a8f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/300409
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2021-03-15 23:11:33 +00:00
Ainar Garipov 1e524e26be internal/lsp/source: add the nilness analyzer
Fixes golang/go#44627

Change-Id: I4291b419862c7b7df8eff988abe7ab38d03e6189
Reviewed-on: https://go-review.googlesource.com/c/tools/+/299131
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2021-03-08 20:13:34 +00:00
Ainar Garipov b8d1a33f7a internal/lsp/source: add the unusedwrite analyzer
Fixes golang/go#44461

Change-Id: I0e002a26cd188cd9b5a14e44d7f880f9f414af36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/295172
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
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>
2021-02-23 16:31:19 +00:00
Rob Findley 8316e56472 internal/lsp/command: stub out the ListKnownPackages and AddImport commands
Add the ListKnownPackages and AddImport methods to command.Interface and
regenerate bindings. Add empty implementations to lsp.commandHandler.

These are our first commands returning results. I'll update our docgen
to support result in a subsequent CL.

Change-Id: Ic3b7c0d9383ac8f3e1cb546a71e9c496a92a7840
Reviewed-on: https://go-review.googlesource.com/c/tools/+/291129
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
2021-02-11 00:57:35 +00:00
Rebecca Stambler 51f72a196f internal/lsp: address Rob's comments from CL 289772
Change-Id: Ifc5431b2e549c5221d66f7771dac47fcb70afb56
Reviewed-on: https://go-review.googlesource.com/c/tools/+/290829
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-02-10 15:37:15 +00:00
Rebecca Stambler d459050367 internal/lsp: apply go.sum fixes to all modules in multi-module module
When go.sum updates are needed in experimental workspace module mode, we
don't necessarily know which module needs the correction. As a fix,
apply all of these fixes to each module in the multi-module workspace.

The "add dependency" quick fix also seems to be broken, but I'll fix
that in a separate CL.

Fixes golang/go#44097

Change-Id: Id4a6013f2aceb6b902dff3118b027f6cb99eb3c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/289772
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-02-10 01:33:22 +00:00
Rob Findley 1bc371e21e gopls/doc: add argument documentation for commands
Update our docgen to include documentation for commands. This is done in
an ad-hoc manner. We'll probably need to iterate on this as we go.

For golang/go#40438

Change-Id: I0a6922aa2f5e7dc4c8a43e0f843ddb54971cbe44
Reviewed-on: https://go-review.googlesource.com/c/tools/+/290190
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-02-09 22:09:55 +00:00
Rob Findley 8aef11fa67 internal/lsp: switch to the new command API
Fully switch to the new generated command API, and remove the old
dynamic command configuration.

This involved several steps:
 + Switch the command dispatch in internal/lsp/command.go to go through
   the command package. This means that all commands must now use the new
   signature.
 + Update commandHandler to use the new command signatures.
 + Fix some errors discovered in the command interface now that we're
   actually using it.
 + Regenerate bindings.
 + Update all code lens and suggested fixes to new the new command
   constructors.
 + Generate values in the command package to hold command names and the
   full set of commands, so that they may be referenced by name.
 + Update any references to command names to use the command package.
 + Delete command metadata from the source package. Rename command.go to
   fix.go.
 + Update lsp tests to execute commands directly rather than use an
   internal API. This involved a bit of hackery to collect the edits.
 + Update document generation to use command metadata. Documenting the
   arguments is left to a later CL.
 + Various small fixes related to the above.

This change is intended to be invisible to users. We have changed the
command signatures, but have not (previously) committed to backwards
compatibility for commands. Notably, the gopls.test and gopls.gc_details
signatures are preserved, as these are the two cases where we are aware
of LSP clients calling them directly, not from a code lens or
diagnostic.

For golang/go#40438

Change-Id: Ie1b92c95d6ce7e2fc25fc029d1f85b942f40e851
Reviewed-on: https://go-review.googlesource.com/c/tools/+/290111
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2021-02-09 22:09:28 +00:00
Rob Findley 5ab06b02d6 internal/lsp/source: sort commands alphabetically
For stability and to ease navigation, sort commands alphabetically.

This will simplify the diff in later CLs, where command discovery is
refactored.

Change-Id: I346cbc2162b1b4dbac16572a653c4169b93cc0f3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/290390
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-02-08 16:45:41 +00:00
Heschi Kreinick f1f686b0d0 internal/lsp: re-enable upgrades for individual dependencies
In CL 271297, I disabled the constantly-running upgrade check, which
removed the upgrade commands for individual dependencies. This seems to
have been a relatively popular feature. Re-introduce it, but requiring
explicit user interaction.

We now run an upgrade check when the user clicks "Check for upgrades".
Those results are stored on the View and used to show diagnostics on
any requires they apply to. Right now we only check the go.mod the user
has open; in multi-module workspaces it might make sense to check all of
them, but I'm not sure.

Fixes golang/go#42969.

Change-Id: I65205dc99a4fa9daafdb83145b0294b6f3be5336
Reviewed-on: https://go-review.googlesource.com/c/tools/+/286474
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-02-01 17:10:16 +00:00
Rebecca Stambler 9ca8607e69 internal/lsp: save all possible keys for analyses, codelenses
The possible keys for analyses and codelenses are too long to enumerate
in settings, and we'd need to create enums for all possible analyzer
and code lens names, which is probably not feasible. Instead, collect
the list of possible values from the analyzers and command settings
generation and add them to enum values.

Also, handle default values by setting them in the enum keys instead of
one big default value. Quite a few hacks to get this right, but maybe
there are other better alternatives we can consider in the future.

Fixes golang/go#42961

Change-Id: I5c096862b5e8fb89fe5d6639b4f46c06492e49c4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280355
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2020-12-30 22:05:20 +00:00
Rebecca Stambler d2d86cca02 internal/lsp: restructure user options (CL 278433 continued)
This CL copies Heschi's structural changes to the options from CL 278433
and makes the necessary adjustments in the JSON and documentation
generation. Nested settings are grouped together and the "status" of a
given setting is also listed. Currently the only possible statuses are
"experimental" and "debug", but I will add "advanced" in a follow-up (to
indicate that a setting is only for advanced users).

The options "set" function still expects flattened settings to avoid
fundamentally changing people's current configurations, so VS Code Go
will just have to make sure to flatten the settings before sending them
to gopls (which should be easy enough).

No names of any settings are changed (Heschi's earlier CL adjusted the
experimental prefixes). As discussed offline, we've decided to prefix
any setting that we expect to delete with "experimental", and so we'll
leave existing setting names as they are.

Updates golang/go#43101

Change-Id: I55cf7ef09ce7b5b1f8af06fcadb4ba2a44ec9b17
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280192
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: Suzy Mueller <suzmue@golang.org>
2020-12-30 21:54:22 +00:00
Rebecca Stambler fbbba25c5f gopls/doc: generate documentation for analyzers
Analyzers are configured in the internal/lsp/source/options.go file as
well as settings, and we can generate documentation for them without
even using reflection. We add documentaton for each analyzer and list
whether or not it is enabled by default.

Change-Id: If0ffcd422f3f4a99ca3645c35197925ea1cc1616
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280352
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: Suzy Mueller <suzmue@golang.org>
2020-12-29 01:23:49 +00:00
Rebecca Stambler 34cd474b99 internal/lsp: use an enum for GC annotations settings
The annotations map should use an enum to indicate expected values. For
now, we reuse the EnumValues to expose the information in the settings.
Later, we'll create a separate EnumKeys field to expose this information
more correctly.

Also, adjust some of the logic that applies the settings because it was
incorrect.

Both gopls/doc/settings.md and internal/lsp/source/api_json.go are
generated files.

Updates golang/go#42961

Change-Id: Ifb032b70caaae73defe9a540df20d098d313e68e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/280354
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-12-28 16:22:55 +00:00
Hana fa10ef0b87 internal/lsp/source: update codelenses example
And regenerate docs and api_json.go

Change-Id: I7504c5257893617adcc0b657b61feb3cdb235061
Reviewed-on: https://go-review.googlesource.com/c/tools/+/278356
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-12-15 19:20:05 +00:00
Heschi Kreinick cc330816fc internal/lsp: support directory inclusion/exclusion filters
Users working in large repositories may want to include only selected
directories in their workspace to avoid memory usage and performance
slowdowns. Add support for inclusion/exclusion filters that control what
directories are searched for workspace packages and modules. Packages
that are excluded by the filter may still be loaded as non-workspace
packages if other things depend on them.

For a description of the option's syntax, see the documentation.

Note that because we don't have any way to communicate the filters to
packages.Load, we still run go list on the unfiltered workspace scope,
then throw away the irrelevant packages. That may cost us, especially in
workspaces with many files.

Comments on the naming welcome. Also, if you know any places I may have
missed applying the filter, please do tell. One thing I thought of is
file watching, but that's covered because allKnownSubdirs works off of
workspace files and those are already filtered.

Possible enhancements:
 - Support glob patterns.
 - Apply filters during the goimports scan.
 - Figure out how to apply the filters to packages.Load. I don't know
 how to do it while still being build system neutral though.

Closes golang/go#42473, assuming none of the enhancements are required.

Change-Id: I9006a7a361dc3bb3c11f78b05ff84981813035a0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/275253
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>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-08 18:36:58 +00:00
Rebecca Stambler 6607ba8a66 internal/lsp/source: default experimentalDiagnosticsDelay to 250ms
We've been aiming to enable diagnostic debouncing by default, and now
that CL 269197 is merged, I think it's time to do that.

I know that the experimental setting had it at 200ms, but the 250ms was
specified in golang/go#42693, so I'm not sure which is preferable.

Also, fix a bug I introduced in CL 269197, which set alwaysAnalyze to
true for diagnoseChangedFiles. This should only be used for testing.

Add a requirement for 1.13 to one test that relies on good overlay
support (loading the file directly produced a different response from
the full workspace load).

Fixes golang/go#42693

Change-Id: I49b764a8d473a66a01ef0f2c6f4cbe2d512fd64e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274445
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-12-04 16:16:41 +00:00
Heschi Kreinick a1a1cbeaa5 gopls/doc: generate JSON too, store as composite literal
Combine the generation of the API json with the generation of the
documentation. This cuts out a step from the generation process, and
allows us to depend on third-party modules. Use litter to print a
composite literal instead of JSON text, which will diff and merge much
better.

The only real drawback is that you have to "go run" from the gopls
module to avoid adding the extra deps to tools.

Sorry about the copy and paste; there's relatively little actual code
change, just a bit in doMain and rewriteAPI.

Change-Id: Iac936d31b7e52651b3b33f27497cfdbd133f1e76
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274373
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>
2020-12-03 20:21:02 +00:00
Heschi Kreinick fa6651ede5 internal/lsp/source: allow opt-out from -mod=readonly, GOPROXY=off
The changes to require more explicit dependency management and network
access are very user-facing, and we may not fully understand their
implications. Allow users to roll them back with options for the moment.
Ideally we'll be able to remove them in a few months after things
stabilize.

Change-Id: I5a5ff7c9f3afa490b9945604109c4e3bd9bd7844
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274532
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>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 19:34:12 +00:00
Heschi Kreinick bd5d160bec internal/lsp: add go get quick fix on failing imports
With -mod=readonly set, we no longer automatically add new requires to
go.mod, even the temporary one. We have the go mod tidy code lens, but
that only works on saved files, even in 1.16 due to golang/go#42491.
Plus we may remove the code lens's network access in the future.

Add a simple quick fix for import errors that runs (the moral equivalent
of) go get on the missing import.

Change-Id: Id5764a37ce7db0dce5370da9d648462aefa2042b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274121
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>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-12-03 19:34:02 +00:00
Heschi Kreinick 9bc6a9788d internal/lsp: set -mod=readonly in most contexts
Go 1.16 will set -mod=readonly to be the default behavior of the go
command. This CL changes gopls' behavior to be more in line with that.

The model we end up with is more explicit about managing the go.mod.
Previously, adding an import for a package in the module cache but not
in scope would succeed, but add a warning with a quick fix. Now, the
import will fail, again with a quick fix, and the project will not
compile until the require is added. It also means that the go.sum needs
to be in sync. Previously, the go command would update the temporary
go.sum if the user's was out of date, and then we would discard those
changes. Now, loads will fail until the go.sum is brought into sync,
either by `go mod tidy` or the new "update go.sum" command.

The go.sum requirements affect many regtests. I added a DumpGoSum
function to the environment, which prints the txtar format go.sum file
that needs to be added to the workspace. We'll need to keep them in
sync, unfortunately. We could update them on the fly, but that would
slow down the regression tests somewhat and potentially mess up the test
setup. So I'm not sure what to do exactly. Perhaps maintain them
out-of-line in a separate file that could be auto-updated? Dunno.

I also had to add go directives to go.mod files to keep old Go versions
happy.

Multi-module workspace mode currently doesn't create a go.sum file at
all and is held back to the old behavior until it does.

Change-Id: Ib31afc17614afac2f5fbdf31c7fc03a90bd13e3a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268597
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>
2020-12-03 19:32:01 +00:00
Rebecca Stambler e7a5458643 internal/lsp: fix misspelling in Codelens option
Deprecate the old "codelens" and replace it with "codelenses".

Change-Id: I667ffc5702270d46ce85f8d25837f37569f7048e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273308
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-11-30 17:56:50 +00:00
Rebecca Stambler b5590deeca internal/lsp: move options to correct sections
Some of our options were listed as experimental, despite being fairly
stable and intended for general use. Others were listed as user options,
when they should really be "deprecated" and moved into the internal
options section (which has no public documentation). Moved these various
options into the correct sections.

Fixes golang/go#42674

Change-Id: I89724521f70707f1feb4ecb8b5ed671e988d09eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271420
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-11-25 23:11:58 +00:00
Rebecca Stambler 208275ba88 internal/lsp: switch the default symbol style to dynamic
Fixes golang/go#41760

Change-Id: Ia9b9e5e1e0e549efc69c623abe9877cfcd008f47
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272748
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-11-24 17:38:11 +00:00
Rob Findley 45586ddbaa internal/lsp: nest the workspace root if there is only one module
If the user opens a parent directory of a single module, we can load
their workspace without using some of the workarounds of experimental
workspace mode, simply by narrowing the workspace to this nested
subdirectory.

Do this by extending findAllModules to support a limit on the number of
modules and files to search.

Updates golang/go#41558
Fixes golang/go#42108

Change-Id: Idba800a0deaeee5137d46f16a30b2012ff902a36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268877
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: Heschi Kreinick <heschi@google.com>
Trust: Robert Findley <rfindley@google.com>
2020-11-23 15:28:13 +00:00
Rebecca Stambler 0557df368a internal/lsp/source: set experimentalPackageCacheKey to true by default
Fixes golang/go#42692

Change-Id: I10ccec29a707391442c23c88d3f26955e103130d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271478
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-11-19 17:46:15 +00:00
Heschi Kreinick 2c115999a7 internal/lsp: use the go command to fix go.mod files
Modifying go.mod files directly leaves go.sum unchanged, and therefore
in need of updates later. Leaving work for the users to clean up isn't
ideal, so it'd be better to use the go command to make modifications.

Unfortunately, the go command has something of a mind of its own. The
most obvious problem is that using go get to add a new require adds a
// indirect comment to that new require, and there's no way to prevent
it. The only thing we can do is add the require first, then use go get
to do nothing but update the go.sum file.

The other inherent problem is that the go command operates on files as
they exist on disk, not the in-memory versions. As discussed, we issue
an error for this case. The alternative would be to work on temporary
files based on the in-memory contents, but that would be much larger
change, so I'd rather not at least right now.

To support Commands for quick fixes, add a new Command field to
source.SuggestedFix, and use it when forming the CodeAction response.

Fixes golang/go#38209.

Change-Id: I0c13ea39199368623e7494e222ba38587323d417
Reviewed-on: https://go-review.googlesource.com/c/tools/+/265981
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-28 22:47:54 +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
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
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
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
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
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
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
Rob Findley 8445f4f065 internal/lsp: add experimental support for multi-phase diagnostics
An experimental new feature is added to run parsing and checking on
modified files immediately, and run analysis and diagnostics for
transitive dependencies only after debouncing. This feature is disabled
by default.

Also, some refactoring is done along the way:
 + Clean up diagnostic functions a bit using a report collection type.
 + Factor out parsing diagnostics in options.go.

Change-Id: I2f14f9e30d79153cb4219207de3d9e77e1f8415b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/255778
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-02 14:12:12 +00:00
Peter Weinbergr c8c0a1c017 internal/lsp/semantic.go: add the skeleton for supporting semantic tokens
This Cl adds all the support for producing semantic tokens other than
generating them. That includes new stubs for LSP, a new option for
the user to choose semantic tokens, and the skeleton for producing
semantic tokens, except that 0 semantic tokens are produced.

vscode 1.49.1 (the current version) does not ask for semantic tokens;
vscode-insiders does.

Change-Id: Iceb8fff974deb9283281319bb5878271c3d3170d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257578
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>
2020-09-30 14:30:06 +00:00
Heschi Kreinick 50ab9675f5 internal/lsp/source: add additional generated docs
Enable documentation for Debugging options, code lenses, and LSP
commands.

See the comment in loadCommands; reading comments off a composite
literal is annoying. If the documentation were available at runtime this
would be much easier, and we should probably switch to that at the first
sign of trouble.

Fixes golang/go#33544.

Change-Id: I503b62aa2fc4a993f5978c449088db54fc79f7de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/257737
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-28 17:29:33 +00:00