Граф коммитов

5574 Коммитов

Автор SHA1 Сообщение Дата
Robert Findley bf23c547d2 Revert "internal/lsp/source: simplify workspace symbol package collection"
This reverts commit 852eb6420a.

Reason for revert: accidentally submitted before CL 268539

Change-Id: I0f9bf230bef29cf44e931dbf4574186fdb404359
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274273
Reviewed-by: Heschi Kreinick <heschi@google.com>
Trust: Robert Findley <rfindley@google.com>
2020-12-01 01:28:06 +00:00
Rob Findley 852eb6420a internal/lsp/source: simplify workspace symbol package collection
While evaluating workspace symbols, we avoid duplicate packages per
package path in an effort to save computing time and eliminate duplicate
results. But for simplicity, we later guard to ensure that we don't ever
walk files twice.

We can just rely on this guard to prevent duplication, and walk all
known packages. This ensures we don't miss symbols, at minimal
additional cost, and simplies the code.

Fixes golang/go#42791

Change-Id: I97000dbe29e67bda6071d5119a6edb7c5fa4da80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272686
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-12-01 01:24:05 +00:00
Peter Weinbergr fd5f293690 go/analysis: avoid panic in ifaceassert
Presently ifaceassert.go panics if given asserts whose
types reduce to
[]interface{}.(string)
which is illegal Go. Its tests won't even run on such code, but
gopls will happily invoke it. This CL adds a test for nil.

See golang/go#42857

Change-Id: I2791f4bd0b58559e65e6590822ac8f4123989273
Reviewed-on: https://go-review.googlesource.com/c/tools/+/273766
Reviewed-by: Michael Matloob <matloob@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2020-11-30 22:00:05 +00:00
Jean de Klerk 0e8b1ee181 gopls, internal/lsp: support fillstruct for partially-filled structs
This updates fillstruct to work even when the struct is partially
filled. User supplied fields are preserved but comments are blown away.

Preserving comments appears to be very hard with the current ast
library. One possible option is to do manual string shenanigans, but
after exploring that path it seems like A Bad Idea.

Fixes golang/go#39804

Change-Id: Iec0bb93db05d4d726dfa6c77a8139f53b14bcc77
Reviewed-on: https://go-review.googlesource.com/c/tools/+/262018
Run-TryBot: Jean de Klerk <deklerk@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Trust: Jean de Klerk <deklerk@google.com>
2020-11-30 20:22:45 +00:00
Muir Manders ca1c149215 internal/lsp: offer type converted completion candidates
For example:

    func wantsInt64(int64)            {}
    func wantsDuration(time.Duration) {}

    func _() {
      for i := range []string{} {
        // inserts "i" as "int64(i)"
        wantsInt64(i<>)

        // inserts "i" as "time.Duration(i)"
        wantsDuration(i<>)
      }
    }

Type converted candidates have a significant score penalty so they
should never outrank a directly assignable candidate, other factors
being equal.

To minimize false positive completions, we don't offer converted
candidates if either:
- The candidate is a deep completion into another package. This avoids
  random "float64(somepkg.SomeVar)" popping up when completing a
  float64.
- Don't offer to convert ints to strings since that's not normally
  what the user wants.

After going back and forth I decided not to include the type
conversion in the candidate label. This means you will just see the
candidate "i" in the completion popup instead of "float64(i)". Type
names add a lot of noise to the candidate list.

I also tweaked the untyped constant penalty to interplay better with
the new type conversion penalty. I wanted untyped constants to be
ranked above type conversion candidates since they are directly
assignable, so I reduced untyped constants' penalty. However, to
continue suppressing untyped constants from random other packages, I
applied a similar heuristic to above where we give a bigger penalty if
the untyped constant is a deep completion from another package.

Fixes golang/go#42764.

Updates golang/go#39207 (untyped constant penalty tweak may improve
this situation).

Change-Id: I565114b3a1c9628285d07200b9dfc45c61e5d898
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272286
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
Trust: 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>
2020-11-30 20:04:59 +00:00
Rebecca Stambler c5a73c3035 Revert "internal/lsp: use mode (GOPATH/modules) oriented error messages"
This reverts commit ccae4fb384.

Reason for revert: Accidentally submitted too early

Change-Id: I5193554ee78560b1398f571afce56c66b00b7d63
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274118
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-30 18:45:08 +00:00
Rebecca Stambler ccae4fb384 internal/lsp: use mode (GOPATH/modules) oriented error messages
We can offer better error messages to users in GOPATH mode. The Go
command has clear error messages indicating where it's looking for
its dependencies, so we can borrow these messages too.

The error message will look like this:
https://user-images.githubusercontent.com/5856771/100292862-bde8bb00-2f4f-11eb-9920-d945ee2c7e87.png

Change-Id: I888b33804eec7f38c329ae2e4343b82fcc22f1df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272166
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 18:27:53 +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 2e53cd6703 internal/lsp: explicitly watch all known directories
VS Code's file watching API doesn't send notifications about directory
deletions unless you register for them explicitly (see
https://github.com/microsoft/vscode/issues/109754). Rather than watch
every file in the workspace, keep track of every relevant directory and
register file watchers for it.

This CL moves the snapshot's WorkspaceDirectories function to the
session and changes it to a KnownDirectories function. It returns all of
the directories and subdirectories known the session at a given moment.
Top-level directories are marked as such so that their *.{go,mod,sum}
contents can be watched, while subdirectories are just watched by path
so we can be notified of deletions.

Fixes golang/go#42348

Change-Id: Ic6d02dba55b5de89370522ea5d3cf1d198927997
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271438
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>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-11-25 22:00:14 +00:00
Pontus Leitzler 299f270db4 go/analysis/passes/fieldalignment: add fieldalignment analyser
This change adds Matthew Dempskys maligned analyser as fieldalignment,
modified to provide suggested fixes as well. The pass detect structs
that would take less memory if their fields were sorted.

It is also added to gopls as an opt-in analyser.

Change-Id: I549215807d2fb7244ea4f58739bab98b0dea9c0e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270217
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Pontus Leitzler <leitzler@gmail.com>
2020-11-24 20:20:34 +00:00
Rebecca Stambler d890b968b6 internal/lsp: extract filenames from go command errors
Update the logic that extracts positions from error messages to handle
optional column numbers, and then use that function when extracting
go command errors. This will be useful in parsing go list errors.

Change-Id: Ie68de1439f002c30f785c0c121c5cec4f2fea727
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272095
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 18:15:41 +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
Rebecca Stambler 325b08a518 internal/lsp: rewrite the workspace symbol marker tests
The workspace symbol tests are not really resilient to changes and
did not generate/use golden files consistently. This made it really
tricky to switch the workspace symbols defaults.

To improve the workflow, consolidate the different kinds of tests into
one function, generate and use golden files, and require that all of the
workspace symbol queries appear in one file only. Also converted the
brittle workspace symbol regtest to a marker test.

Update golang/go#41760

Change-Id: I41ccd3ae58ae08fea717c7d8e9a2a10330e8c14f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271626
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-11-24 17:38:01 +00:00
Rebecca Stambler ed677e9dcd internal/lsp/tests: factor normalization logic out of cmd tests
Some features (notably, workspace symbols) produce results with file
paths outside of the command-line package. This logic can be useful for
all tests, so factor it out into the shared testing package.

Change-Id: I2e00ebc0174079660c2f07562c50fd9377088475
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272210
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-11-24 16:59:54 +00:00
Rob Findley a30985897b internal/lsp: track diagnostics by reporting source
Our handling of diagnostics has gotten complicated and has recently been
a source of bugs. Heschi and I took a step back and refactored the
diagnostic pass, starting with a new data structure for tracking
diagnostics.

The LSP server now holds a map of URI to collection of diagnostic
reports, which is used to track diagnostics as they are computed by
multiple sources. Additionally, this collection holds a hash of the
last published diagnostic set.

This new information allows us to implement an algorithm for
incrementally updating diagnostics on the server: diagnostics reports
are stored as they are computed for a snapshot, and then published in
(possibly multiple) passes, with the last pass for a snapshot being
marked as 'final'.  In non-final passes, 'publishReports' publishes any
diagnostics that have already been computed for the snapshot, but does
nothing with URIs for which no diagnostics have been computed. In final
passes all diagnostics are reported, with empty diagnostics being
published for any URIs with no diagnostic reports. Any URIs for which no
diagnostic reports were computed are pruned from the diagnostic set. In
all cases, tracking the hash of published diagnostics prevents us from
duplicate publication.

This enables some simplifications of the existing diagnostic logic.
Computing new diagnostics and tracking send diagnostics is now handled
by the same algorithm, avoiding some bookkeeping. It is also no longer
necessary to explicitly clear diagnostics for deletions. This fixes some
previously broken edge cases, for example when packages go out of scope
due to go.mod or gopls.mod changes.

Fixes golang/go#42198

Change-Id: Id0d8d0f7a60f6ffa8c33f0ae41763461f61dab7b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/269677
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-11-24 15:22:09 +00:00
Peter Weinbergr a9663296b1 internal/lsp: revise some semantic token details
There was a bug and inconsistency in how const identifiers were
categorized when being used. The new code always makes them readonly
variables.

The predeclared identifiers (true, false, nil, iota) were treated
inconsistently. The new code makes them all readonly variables.

Under rare conditions the output from gopls semtok was not syntactic
Go code because is would put a /* comment immediately after an
operator /, thereby generating a spurious line comment.

Fixes golang/go#42715

Change-Id: I5b1ccfaf607d6baa58c132e460c5617db6634a72
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272208
Trust: Peter Weinberger <pjw@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-11-24 12:36:21 +00:00
Rob Findley 2c860bdd6e internal/lsp: fix some incorrect spelling
Fix misspellings caught by github.com/client9/misspell/cmd/misspell.

Change-Id: I6e9cb858429bf0724453829693c36a99c481e88f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272689
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-11-24 11:59:21 +00:00
Rob Findley 911501bfb5 gopls/internal/regtest: skip regtests for openbsd-amd64-64 on TryBots
This build is suddenly timing out with high frequency. This requires
investigation, but for now we must get builds passing again.

For golang/go#42789

Change-Id: I51dc5eab227cfb77cd3021438f1b161b21f69caf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272687
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Robert Findley <rfindley@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-24 00:57:43 +00:00
Rebecca Stambler 4aa1a224cd internal/lsp: fix title for vendor suggested fix
Noticed that the message in VS Code is empty.

Change-Id: I5e0c6723be0fc376e2e01a3016127a0385a02866
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272206
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>
2020-11-23 23:22:13 +00:00
Heschi Kreinick a83918f9ef internal/lsp: only show command errors once
We both showing errors as a popup and returning them to the client,
which would then most likely show them as a popup. Don't return errors
back to the client.

Change-Id: I8486534e19399d514752900025d6db8db85d5086
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272090
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-11-23 22:54:48 +00:00
Rebecca Stambler b5535b156a gopls/internal/regtest: convert circular import tests to regtests
These tests require special cases and are difficult to understand in the
marker format. They are much simpler as regression tests.

Fixes golang/go#40332

Change-Id: I791b9092d0f3d08aa5415eced427850626f8eb2a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272207
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>
2020-11-23 21:59:33 +00:00
Heschi Kreinick db3e1ec26d internal/lsp: use pointers to source.Error, and not to ErrorList
We should be consistent about whether we pass around Error or *Error.
*Error was somewhat more common, and its Error method has a pointer
receiver, so I picked *Error.

ErrorList, on the other hand, is usually dereferenced when used, and
slice headers are small enough to pass around casually. So switch that
over to a non-pointer and change its Error method to a value receiver.

Change-Id: I19e70201ed1d6ef36d217db21c9101bb810bcf0c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272092
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-11-23 19:09:50 +00:00
Heschi Kreinick a9763abba0 internal/lsp: refactor code action go command calls
Change-Id: I211e8f97d7d121f5c0acd845eadb00ec73d89c2c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272091
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-11-23 18:27:55 +00:00
Muir Manders 5bad45943a internal/lsp: fix godef for embedded type aliases
In

    type myAlias = someType
    type _ struct {
      myAlias
    }

Previously running "definition" on the "myAlias" field would take you
to the definition of "someType" instead of "myAlias". This is because
we were using the field's (*types.Var).Type() which has already
forgotten it is an alias. Fix by instead looking up the field name
ident in types.Info.Uses which yields the *types.TypeName (for the
type alias).

Fixes golang/go#42254.

Change-Id: Idbbd0c49ba6f701f52568b3ab1143d8e24037c69
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272186
Run-TryBot: Muir Manders <muir@mnd.rs>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Muir Manders <muir@mnd.rs>
Trust: Rebecca Stambler <rstambler@golang.org>
Trust: Robert Findley <rfindley@google.com>
2020-11-23 15:59:28 +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 780cb80bd7 internal/lsp: fix go.mod parse error parsing to show diagnostics
This change adds support for showing go.mod parse errors as diagnostics.
There was previously a bug in parsing these error messages, and the
diagnostic reports were also not being published if the IWL failed.

Change-Id: I56197b91c49fb68e35d8886175435d5c38bfb8c2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/272089
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-21 01:02:11 +00:00
Rebecca Stambler 20be4ac4bd internal/lsp: remove workspace packages as needed
This change adds tracking for package name changes, which we can use to
determine if a workspace package ID may have changed or been removed.

It's a little bit tricky for something like a test variant, because you
want to invalidate the ID only if the test variant only files have
changed package names. I figured it would be ok (speed-wise) to call
guessPackageIDsForURI on the other files since this should be a pretty
rare case.

Fixes golang/go#40690

Change-Id: Ib3f7eed526eb5bb455e17c362632ec7ac0ecd1cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268157
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-11-20 15:53:55 +00:00
Rebecca Stambler 6d15148156 internal/lsp/cache: only invalidate metadata for go.mod files on save
Throwing away all of the metadata in the package means it will be
expensive to reload, so it makes sense to keep it around until a go.mod
file has been saved, indicating that the user is more likely to be done
typing. Otherwise, we will be triggering full package metadata reloads
on every keystroke.

Fixes golang/go#42529

Change-Id: Ibc4f4bc8937f8f7176da79e9fefe166468578993
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271299
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>
2020-11-20 03:23:37 +00:00
Rebecca Stambler a7380940e0 internal/lsp: pass a parsed module to go mod tidy
This allows us to show parsing errors as part of module diagnostics.

Change-Id: I558b95c145135482fdfceef8a5c68c62a6d32721
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271630
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-20 02:54:08 +00:00
Rebecca Stambler c0d5e89189 internal/lsp/fake: hold the mutex for all of SaveBufferWithoutActions
This addresses the race seen in
https://storage.googleapis.com/go-build-log/5ba1c3f2/windows-386-2008_2bf3acc7.log.

Paraphrased from Rob in chat:

The race is triggered because of the additional asynchronous handling of
file changes added to sync non-dirty files on disk changes. The buffer
is marked as non-dirty, THEN the on-disk change is processed, sending a
didChange, THEN the didSave is sent (https://golang.org/cl/267577).

Also, don't send didChange for formatting if nothing has changed.

Change-Id: Ibc6a55d35dee99c04dadf5470c2d68ca937f849b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271578
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 19:12:46 +00:00
Rebecca Stambler be796f87a6 gopls/internal/regtest: handle flake in TestCRLF
Make the test a little more stable by making sure diagnostics complete
before organizing imports in these tests.

Change-Id: Id23341569207878554902887498632d6f1ce56cf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271628
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-11-19 19:02:02 +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
Michaël Lévesque-Dion 4783bc9beb Handle BareInits option in ssa.BuilderMode
Fixes golang/go#42614

Change-Id: I9546804af627cc97e7aebafc66ba3e8928d1c049
GitHub-Last-Rev: 05f5aa85b5
GitHub-Pull-Request: golang/tools#257
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270177
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Peter Weinberger <pjw@google.com>
2020-11-19 13:27:11 +00:00
Rebecca Stambler 25dc3e1ccc internal/lsp: handle deletion of a directory on disk
The current DidModifyFiles logic does not handle the possibility of a
directory URI in a didChangeWatchedFiles request. For creation and
changes, this is fine because only file URIs matter in those cases, but
for deletion, the deletion of a directory signifies the deletion of all
of the files in it.

Add handling for directories by looking up all of the known files in a
given directory. We then create file modifications for all of those
files, instead of the directory.

Fixes golang/go#38422

Change-Id: I26d7b93285367fe116fd1cb3e8ec13a276f9e517
Reviewed-on: https://go-review.googlesource.com/c/tools/+/266138
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-11-19 05:40:27 +00:00
Heschi Kreinick 4d9c4f8a78 internal/lsp/mod: speed up and simplify go.mod code lenses
The tidy and upgrade code lenses first run the go command they
represent, then show the lens if there are changes to be made. While
this makes for a cleaner user experience, it also means that we're
running a go command that hits the network in a synchronous code lens
call. That's risky if the user is on a slow network connection.

Removing the call does represent a change, possibly a regression, in UX.
However, we already felt that the presentation of the upgrade option on
each dependency line was too noisy. Therefore the only remaining benefit
is that the lenses only appear when they have something to do. We've
decided that's not sufficient justification. Remove the calls.

We may recreate them as diagnostics in the future, so I've left
ModUpgrade around. (ModTidy is still used by diagnostics.)

Change-Id: I16c5eaebd1a50e5358c2addde9c1bb3f1182aac2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271297
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-11-18 21:56:54 +00:00
Rebecca Stambler 1727ee11c4 internal/lsp/cache: fix a staticcheck warning by handling error
Change-Id: Ic8d1e7a046d60eb98007e355f3bef2537072a473
Reviewed-on: https://go-review.googlesource.com/c/tools/+/271298
Trust: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-18 21:47:00 +00:00
Heschi Kreinick 6ed8ff9ad9 internal/lsp: support unimported completions in multi-module mode
Refactor to use goCommandInvocation to get the evironment for
goimports. That takes care of most of the work; all that's left is to
track the go.mod hash so we know when to clear the cache.

Fixes golang/go#41836.

Change-Id: I614dacad04adfb879ead55e3b8640e57816534cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270877
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-11-18 17:45:08 +00:00
Rebecca Stambler 598b068a91 internal/lsp: fix end positions for multi-line comments with CRLF lines
The previous work-around assumed that the end of the comment would be
off by one line, when in reality, it is off by the offset of the number
of \r in the comment, which may result in the comment end position being
off by multiple lines. Work around this by scanning for the end of the
comment position using text/scanner.

Fixes golang/go#42646

Change-Id: Icc33e889546f324c6b65b55a98dea587f84c8f01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270879
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-18 03:03:13 +00:00
Rebecca Stambler bd56c0adb3 internal/lsp: use a marker test for struct field ranking test
Change-Id: I70faef2c789a3cc7b4dee8c7dd5dcac0e06d7568
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270880
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-18 00:33:11 +00:00
Chiawen Chen 74a3905de1 internal/lsp: order struct fields completions by definition
Previously struct fields completions are ordered alphabetically.
Now it is ordered by its order in definition.

Fixes golang/go#42626

Change-Id: I8c404205b97fa9f1a5a66a95a84033b6f0f48eae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270777
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: Robert Findley <rfindley@google.com>
2020-11-17 23:31:01 +00:00
Rob Findley f544f6cb68 gopls/internal/regtest: eliminate log duplication
The regtest runner currently logs every framed connection, which results
in duplicate RPC tracing (one from the client perspective, one from the
server perspective).

This is unnecessarily noisy. Just log the first connection (currently
from the client perspective).

Change-Id: I4164cde8263e4267e4e45369bd54176c782c4707
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270357
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: Heschi Kreinick <heschi@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
2020-11-17 22:57:35 +00:00
Rebecca Stambler 9036a0f9af Revert "internal/lsp: explicitly watch all known directories"
This reverts commit 3c3a81204b.

Reason for revert: OpenBSD trybots are failing

Change-Id: I39f52ef07a667ed1457d2ae53863af15134eb78e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270798
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>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-11-17 15:25:13 +00:00
Rebecca Stambler 3c3a81204b internal/lsp: explicitly watch all known directories
VS Code's file watching API doesn't send notifications about directory
deletions unless you register for them explicitly (see
https://github.com/microsoft/vscode/issues/109754). Rather than watch
every file in the workspace, keep track of every relevant directory and
register file watchers for it.

This CL moves the snapshot's WorkspaceDirectories function to the
session and changes it to a KnownDirectories function. It returns all of
the directories and subdirectories known the session at a given moment.
Top-level directories are marked as such so that their *.{go,mod,sum}
contents can be watched, while subdirectories are just watched by path
so we can be notified of deletions.

Fixes golang/go#42348

Change-Id: If80a26cf6af5a2c2f7d87bb57b9ef5cb3dcf04ac
Reviewed-on: https://go-review.googlesource.com/c/tools/+/267120
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-17 02:10:29 +00:00
Rebecca Stambler 74f2986df7 internal/lsp: show critical error pop-ups as progress reports
We've been looking for a way to show unintrusive error status reports to
users--try using progress reports as a way of populating a status bar.
This avoids the problem of annoying the user with constant pop-ups.

Whenever an error is returns from (*snapshot).WorkspacePackages, we
start a progress report with the error message. If the error goes away
on the next call to diagnostics, or the error message changes, we will
either remove or update the progress report.

Screencast: https://drive.google.com/file/d/1tG9pc_tPsLoqkQHiJqdY8b06TzTkPVae/view?usp=sharing&resourcekey=0-CEG_LhGHYiFp9S37ut_kgw

Updates golang/go#42250

Change-Id: I8a529a911883092bc08af32246719d883dc5f5a2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/268677
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-17 01:39:53 +00:00
Michael Matloob 1d699438d2 go/packages: handle variation an an error message
go/packages has a special case for cmd/go errors that result from
errors running the 'pkg-config' tool. When modules are missing from
the module cache cmd/go can download modules, and log a message for
each downloaded module, so add a special case to the special case
to check for that message.

Also remove a usage of the x/xerrors package now that it's been folded
into the stdlib for a while.

Fixes golang/go#36770

Change-Id: If1cf8c5d83ac84a51b8bafc4930a0869674d216a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/261502
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-16 18:20:00 +00:00
Rebecca Stambler 6f6c72aec4 internal/lsp: fix capability registration for semantic tokens
Fixes golang/go#42148

Change-Id: Icd063d70cc9b822a4bfb69f2d47ac06f19c18131
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270359
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>
Trust: Rebecca Stambler <rstambler@golang.org>
2020-11-16 18:11:12 +00:00
Heschi Kreinick d68bbb5467 internal/gocommand: improve debug string
The current debug string looks like `go [go list foo]` because I forgot
that argv[0] is a thing. Remove the duplication, and quote things only
when necessary.

Change-Id: Ib751a39435e5a3453833539307d12c9715cc1cad
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270037
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
2020-11-16 17:23:50 +00:00
Heschi Kreinick 247bdb27d1 go/packages: start with empty environment
go/packages is documented as starting with an empty environment if
Config.Env is populated. Fixing all uses of gocommand.Invocation was a
daunting task, so add a mode flag to it instead and set it just in
go/packages.

Clean up packagesdriver.GetSizes, which seems to be completely unused?

Fixes golang/go#42590.

Change-Id: Idac2e1a4798b4a2f5e7c8aa0a1a089a6bd3630ba
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270038
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-11-16 17:23:36 +00:00
Peter Weinbergr 1a2739ce1b internal/lsp: get debug pages limping along again
Changes to the cache data structure broke the templates displaying
information in the debug server. This CL makes small changes to
get the pages working again. it adds  a link to the command line
on the Info page.

More work is needed. For instance, only the memory page refreshes
automatically; options could be displayed; information
about diagnostics could be displayed, as could be information
about modules, and no doubt there's more.

I'm working on a test to typecheck the templates.

Fixes golang/go#41343

Change-Id: I98538a8673de1a9589d09660eab47ad04eb2cc14
Reviewed-on: https://go-review.googlesource.com/c/tools/+/270099
Run-TryBot: Peter Weinberger <pjw@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Peter Weinberger <pjw@google.com>
2020-11-16 16:55:47 +00:00