1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:18:35 -06:00
Commit Graph

5182 Commits

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

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

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

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

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

Change-Id: If2e4d372d4a45ace5ab5d4e76c460f1dcca0bc2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248418
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-08 16:35:05 +00:00
Rebecca Stambler
242af255f0 internal/lsp/analysis: update fillreturns title
Update the title of the diagnostic to account for the fact that
fillreturns can also use in-scope variables to fill in values.

Change-Id: Ib506af76a4187ef611e96b2602f301432fcbccf0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253278
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-08 15:52:18 +00:00
Rob Findley
9786fa3777 internal/lsp/source: fix go1.12 build (again)
A recent change (silently) broke our go1.12 presubmit, because we don't
yet have a means to surface this breakage.  Coming soon: a 'gopls CI'
custom Gerrit label.

In the meantime, fix the build.

Change-Id: I31f5b7512403fdbd8869652cd4b8e77b084c8534
Reviewed-on: https://go-review.googlesource.com/c/tools/+/253517
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-08 15:34:30 +00:00
Peter Weinbergr
39188db588 internal/lsp: add support for RelatedInformation in diagnostics
The type checker sometimes emits secondary diagnostics. For instance,
if a function is defined twice, then when it sees the second definition
it emits a diagnostic at the second definition and a secondary diagnostic
pointing to the first diagnostic. Presently gopls treats these as two
separate diagnostics. The changed code still produces two diagnostics,
but now the secondary diagnostic is also converted into a
RelatedInformation so the user sees a xpointer to the earlier definition.

Updates https://github.com/golang/go/issues/39062.

Change-Id: Ic421ec91d2b46c28681ab3ec010d5b02c0442e68
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251617
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-04 18:57:47 +00:00
Danish Dua
93eecc3576 internal/lsp: support for package completion in all files
This change adds support for package completion in all files at valid
positions. By parsing expressions from an invalid file, we can check if
the cursor is at a position where package completion would be a valid
suggestion. These are positions above any other statements or
declaration or at prefix of the keyword pacakge above these
statements/declarations. This also introduces imporved end of file
handling in completion.

Change-Id: I2a865d018f58c3a98b69fb4100d186b507d123bd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251618
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-04 14:04:24 +00:00
Rob Findley
af4cc2cd81 gopls/internal/regtest: use gopls hooks and add a test for staticcheck
To match the actual gopls binary, use hooks.Options when creating the
regtest server.

Add a test for staticcheck diagnostics to leverage this.

For golang/go#39384

Change-Id: I52837c2b12bb586a2530343bdfae5172b08df49c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252683
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-03 18:57:44 +00:00
Rob Findley
e2cc5a1191 gopls/integration/regtest: move regtests to the gopls module
Regtests are slow, and make `go test ./internal/lsp/...` slow. Also,
having them in the tools module means they can't use staticcheck,
go-diff, etc.

Move them to the gopls module. This means that they're annoying to work
with unless you open the gopls module, but hopefully that annoyance will
be gone soon when we support multi-module workspaces.

For golang/go#39384

Change-Id: Ib99c994ffdac56d4da13af981ad397a90a7523af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252682
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-03 18:25:45 +00:00
Muhammad Hamza Farrukh
76a6aac657 present: fix newline parsing for go present
Pressing enter on editable go present code adds a new 'pre' html tag
which isn't being handled properly. This fix in play.js adds a newline
to the html is being parsed whenever it sees a 'pre' tag.

Fixes golang/go#41139

Change-Id: I042d13999f4a8518fb282c4c5bfb3a5197215449
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251697
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-09-03 15:36:55 +00:00
Olivier Wulveryck
2364a5e8fd playground/socket: remove the os cleanup from start method of process
The cleaning process happens in the end method of process, after cmd.Wait.
Deleting it early while the cmd is still running is causing issues for
security tools.

Move the assignment of p.path along with its comment to happen earlier,
after the temporary directory is created. It clarifies that the lack of
call to os.RemoveAll is not a mistake.

Fixes golang/go#40902

Change-Id: I0e555c58893c64a0de5880a5e12e6ff2e01b1eec
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249777
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
2020-09-03 00:54:29 +00:00
Rebecca Stambler
cf7880770c internal/lsp: reproduce and fix golang/go#41057
Fix the comment end position for multi-line comments to account for the
closing "*/".

Fixes golang/go#41057

Change-Id: I5dd3886a81d274514e78f47ac2e7194fd9cceb06
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252457
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-02 22:40:51 +00:00
Heschi Kreinick
36b1a880d5 internal/lsp/cache: use the right snapshot in ModUpgrade
Cache computations need to use the passed in snapshot.

Fixes golang/go#41056.

Change-Id: I09501f3fc6abccedcf33482c9ee4d58146fbe716
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252437
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-09-02 17:11:20 +00:00
Rebecca Stambler
5d67d6c6f5 internal/lsp: clean up some of the mod code lens code
Refactor the checks for code lenses being enabled out of the source
package so that the mod code lenses can also make use of them.

Also, a few small changes to the titles of the `go mod tidy` and `go mod
vendor` code lenses.

Change-Id: I4e79ab08a4e7aea4d4d6de6fd652d0b77d30c811
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252397
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-02 16:06:48 +00:00
Bryan C. Mills
5b9ef244dc go/ssa: implement missing testing.testDeps SetPanicOnExit0 method
A new method was added to testing.testDeps in CL 250977, which causes
the implementation of that (unexported, explicitly-unstable) interface
in go/ssa to no longer satisfy the interface.

This is a quick, short-term fix. Longer term, the go/ssa package
should switch to the supported TestMain API.

Updates golang/go#41186

Change-Id: Ice110ef540e31a0a98085713346126ffeae64d5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252677
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-02 15:16:23 +00:00
Rebecca Stambler
d1954cc86c internal/lsp: run gopls as long as there is one folder with a file URI
Fixes golang/vscode-go#585

Change-Id: Icb4295f1cab5c0fe60c86dd5f911023f70d2dd62
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252123
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-02 01:26:52 +00:00
Rebecca Stambler
c30460096a internal/lsp/regtest: reproduce edge cases when creating new files
This adds tests for golang/go#40690, as well as a case for a bug in
changing package names.

Updates golang/go#40690

Change-Id: I516404e77728024f8bee3da31a88bad1f1917a9b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251017
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-02 00:53:14 +00:00
Rebecca Stambler
bf6e7d25bf internal/span: remove check for nil content
We should instead treat nil content as an empty file.

Change-Id: I45f1d1c9f3382d2ef7f6d9769c808fd871d603e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252122
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-02 00:13:12 +00:00
Danish Dua
cf97e2b30f internal/lsp: add package completion suggestions
This changes add package completions suggestions for new files. Package
suggestions are other packages used in the same directory, test
packages for those packages, the package 'main' and the directory name.

Fixes golang/go#34008

Change-Id: I69922e0cb0787e82eebe505618c3c07aa48859e6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251160
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-01 20:18:13 +00:00
Rob Findley
80e1b0398e internal/lsp/lsprpc: make the LSP forwarder exit error clearer
In cases where the remote panics, make it clearer in the forwarder logs
that the remote has disconnected.

Change-Id: Ic7f9370f615198274696a18adaefe7dc62cac02e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250508
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-09-01 17:31:45 +00:00
Rebecca Stambler
6fbec87eed internal/lsp: use -json for module upgrades
This is better than parsing the default output.
Also, change the start progress message, since it ends up duplicating
the title in the message that the user sees.

Change-Id: I3540d30c7976c6be0722531b2e258341081e0b72
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251920
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-01 17:31:32 +00:00
Mark Dain
6e59e24738 unusedresult.go: Include context.With* functions
This commit includes the four "With" functions from the context package in the
list of unused functions. This will produce the following error:

    ./main.go:9:19: result of context.WithValue call not used

When analyzing this:

```go
func f(ctx context.Context) {
	context.WithValue(ctx, "foo", -6)
}
```

Fixes golang/go#41149

Change-Id: I5456b79396d45d15498070b5184d5de8c257b343
GitHub-Last-Rev: 577c6b380690477280ed6e941f9dee2057af90f3
GitHub-Pull-Request: golang/tools#248
Reviewed-on: https://go-review.googlesource.com/c/tools/+/252057
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-09-01 15:31:17 +00:00
Rebecca Stambler
fd8950f6eb internal/lsp: add a test that reproduces golang/go#37069
Also, add a directory parameter to RunGoCommand. To make sure that the
parameters aren't misused, change args to a []string.

Updates golang/go#40340

Change-Id: Ib5ce606a401a18c29c904b570ec9339f067a3961
Reviewed-on: https://go-review.googlesource.com/c/tools/+/245818
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-09-01 15:23:12 +00:00
Rebecca Stambler
5a2aa26beb all: update dependencies in tools and gopls modules
Change-Id: I6fe2ad991f509e9d13e4aee3042a58953680a779
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251820
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-31 20:39:04 +00:00
Rebecca Stambler
5deb263172 internal/lsp/cache: don't invalidate metadata for new invalid imports
Our metadata reloading model makes typing out import paths manually
very slow. We can avoid some of the slowness by not invalidating
metadata when a new import path is obviously invalid.

Updates golang/go#35877

Change-Id: Ifcf9ebaac0b146a2098ef8d411fa85fefa7ba6ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251086
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Danish Dua <danishdua@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-08-28 16:18:49 +00:00
Rob Findley
6c983e6784 internal/lsp/fuzzy: fix return value on no match
The fuzzy matcher doc string says that it returns 0 on no match, but
this is in fact not true: it returns -1 on no match.

0 makes more sense, so fix the implementation rather than the docstring.

Change-Id: I997a6b5dcb1d7c25cc73b2c236d24647f9326c80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248417
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-28 15:37:48 +00:00
Danish Dua
97019fc2e6 internal/lsp/source: remove dead code from completion
This code seems to be duplicate of L509-L522 in this CL. It doesn't
affect the results of completion in any way since we already return
early from where we can.

Change-Id: I30ee1c94e58860f86d773d46cb1e527b2e646ef4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251261
Run-TryBot: Danish Dua <danishdua@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-28 01:33:09 +00:00
Rob Findley
3c805d2368 internal/lsp/source: add some downranking for workspace symbols
Downrank symbols in packages outside of the workspace.

For golang/go#40548

Change-Id: Ie83f42f844e57aae5fc397d105f33858d6e44d0f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/248383
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 19:11:38 +00:00
Robert Findley
88346e9948 internal/lsp: refactor workspace Symbol method
This is based on Paul Jolly's CL 228760, updated to use the new cache
API, support the symbolStyle configuration option, and lift up the
concept of symbol score for later improvement.

From that CL:

There are a number of issues with the current implementation:

* test variant packages are not handled correctly, meaning duplicate
  symbols are returned
* fuzzy results are not ordered by score

We refactor the implementation of workspace symbol to use a
symbolCollector that carries context during the walk for symbols. As
part of resolving the test variant issue, we first determine a list of
packages to walk.

(*symbolCollector).collectPackages gathers the packages we are going to
inspect for symbols. This pre-step is required in order to filter out
any "duplicate" *types.Package. The duplicates arise for packages that
have test variants.  For example, if package mod.com/p has test files,
then we will visit two packages that have the PkgPath() mod.com/p: the
first is the actual package mod.com/p, the second is a special version
that includes the non-XTest _test.go files. If we were to walk both of
of these packages, then we would get duplicate matching symbols and we
would waste effort. Therefore where test variants exist we walk those
(because they include any symbols defined in non-XTest _test.go files).

One further complication is that even after this filtering, packages
between views might not be "identical" because they can be built using
different build constraints (via the "env" config option). Therefore on
a per view basis we first build up a map of PkgPath() -> *types.Package
preferring the test variants if they exist. Then we merge the results
between views, de-duping by *types.Package.

Finally, when we come to walk these packages and start gathering
symbols, we ignore any files we have already seen (due to different
*types.Package for the same import path as a result of different build
constraints), keeping track of those symbols via symbolCollector.

Then we walk that list of packages in much the same way as before.

For golang/go#40548

Co-authored-by: Paul Jolly <paul@myitcv.io>
Change-Id: I8af5bdedbd4a6c3631a213d73a735aea556a13ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247818
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 18:13:30 +00:00
Danish Dua
84ab570110 internal/lsp: add completion suggestions for import statements
This change adds completion within import blocks. Completions are suggested by directory depth of import so end user isn't shown a large list of possible imports at once. As an example, searching import for prefix "golang" would suggest "golang.org/" and then subdirectories under that (ex: "golang.org/x/"") on successive completion request and so on until a complete package path is selected.

Change-Id: I962d32f2b7eef2c6b2ce8dc8a326ea34c726aa36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250301
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 18:03:53 +00:00
Rob Findley
06cc1d0a36 internal/lsp/regtest: add benchmarks for IWL and completion
Add additional benchmarks following the pattern of symbol benchmarks.
One for initial workspace load, and another for completion.

Change-Id: Iba826b188cb81dffabb1b08287dc7b76250dc54c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250802
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 17:51:12 +00:00
Peter Weinbergr
021d7c6f1e lsp/general.go: change error messages to give more context
The origin and meaning of error messages in IDEs is sometimes obscure.
For instance "unexpected config annotations\nSource: Go (extension)" in vscode has an ambiguous Source, and it's not clear what config annotations
are being referred to. This CL would change the first part of that
message to "unexpected gopls setting 'annotations', making clear that
the message is from gopls (and not the Go extension shim), and that the
suspect value is 'annotations' itself.

Change-Id: Ia79534859fe101e6fbbd660bf426e2c1ac619b7f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251078
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 16:34:09 +00:00
Rebecca Stambler
debfaf60dc internal/lsp, go/packages: work-around invalid files in GOPATH mode
This change adds a test for this case (empty test file in GOPATH mode)
to go/packages. It is skipped for now, as the go/packages work-around is
too brittle to justify adding. Instead, we suppress gopls-generated
error messages in pop-ups--users should only see error messages if they
come from go/packages.

Fixes golang/go#40825

Change-Id: I0e2af53578d65739ebae582075498d997fc019d7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250949
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-08-27 16:29:21 +00:00
Russ Cox
97606e3207 godoc: fix panic in Presentation.ServeFile
The redirect to drop index.html must be done using r.URL.Path,
not relpath, because those might differ. Cutting len("index.html")
bytes off a string that doesn't end in index.html is incorrect.

While we're here, silence an annoying log print during go test.

For golang/go#40665.

Change-Id: I36553b041f53eab9c42da6b77184e90800a97e92
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251080
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2020-08-27 16:23:30 +00:00
Rebecca Stambler
989ebae23e internal/lsp/source: do not allow extraction of an import spec
Fixes golang/go#40635

Change-Id: Iab8ca37d251a95334c19f32873f9ba9cc1bdd2f4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/251018
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-08-27 16:06:11 +00:00
Rob Findley
df83f4e7c1 internal/lsp: fix builds and tests for go1.12+
Seems we've drifted a bit from go1.12 support, mostly due to error
wrapping.

Fix this, as well as some assorted other failures.

I haven't tested 1.12 interactively.

For golang/go#39146

Change-Id: Id347ead2a13e89b76d2ae0047750e6b6b49911eb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250941
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 14:30:46 +00:00
Rob Findley
17fd2f27a9 internal/lsp/regtest: add a workspace symbols benchmark
It's pretty easy to add an LSP benchmark using the regtests, provided we
run the benchmark ourselves from inside the runner. Do this for
workspace symbols to start, though we should add several of these.

Also fix some error messages when setting options.

Change-Id: Iab134018edec8837e90a0a926ec2e73addf95bb3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250798
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-27 01:05:19 +00:00
Rebecca Stambler
b85e56c1dc internal/lsp/source: sort references and implementations results
We should make sure to return deterministic results for these requests.

Fixes golang/go#40904

Change-Id: If10489e3eca0e1b6a5e449de851d332f2d91ceb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250737
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-26 22:01:59 +00:00
Danish Dua
bc8aaaa29e internal/lsp: ignore period ('.') triggered completions in comments
Period triggered completions don't provide any use in comments and in
worst case can be nuisance. LSP provides a completion context which
provides more info about what triggered a completion and hence we can
use this to ignore period triggererd completions. This will also provide
us options to deal with retriggered completions etc. better in the
future.

Change-Id: I8449aee0fe3cf5f9acf315865ac854d5c894d044
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250337
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-26 04:07:57 +00:00
Rebecca Stambler
f57a28cb8c internal/lsp/source: use space character in markdown formatting
Use space characters instead of the HTML "&nbsp;" character. VS Code and
other clients treat this character differently from a space, so it
results in different formatting. See
https://github.com/golang/go/issues/40947#issuecomment-680497904 for an
image with the difference.

Fixes golang/go#40947

Change-Id: Ia78cb3ba82dcca8303d1b5a0a6d359a3eaca837c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250697
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-26 03:44:07 +00:00
Rebecca Stambler
28d6951fb6 internal/lsp/mod: handle nil pointer exception for empty go.mod files
Fixes golang/go#41005

Change-Id: I1745c5233977d1b5603cfbb334ff087649feaa80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/250657
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-26 01:43:00 +00:00
Danish Dua
e0bf2294bb internal/lsp/source: fix completion on final line of a document
Span treats an end of file as the beginning of the next line, which for a final line ending without a newline is incorrect and leads to completions being ignored. We adjust the ending in case range end is on a different line here.

Change-Id: Ic545dcb221493530b7e39d2be8eba57b69fb6597
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249706
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-08-25 22:56:35 +00:00
Danish Dua
b72e8bb66c internal/lsp: use prefix matcher with comment completion
Since we used to manually set surrounding for comments (instead of using
setSurrounding with an ident), the matched was never initialized and
hence we had to manually do prefix matching. We now initialize matcher
from setSurroundingForComment too.

Change-Id: I8aa735933ebba2fe493182e4245de668997ef7af
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249707
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2020-08-25 21:01:48 +00:00
Pontus Leitzler
b303f430e3 internal/analysisinternal: add anonymous structs & interfaces to
Fillstruct wasn't able to fill structs with fileds that held anonymous
structs or maps with anonymous structs/interfaces.

By adding *types.Struct and *types.Interface support in TypeExpr(),
fillstruct is now works for those as well.

Fixes golang/go#40980

Change-Id: I2a1d6d4db237800197cf14e3ad5067a0e7ab701a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249999
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-25 20:24:27 +00:00
Pontus Leitzler
c024452afb internal/lsp: don't panic if there are no suggested fixes
If an analyzer doesn't return error, and doesn't have any suggested
fixs either gopls panics. Return an empty set of edits instead.

Change-Id: I1cd812fedcbd2ddc01229f48c0cc4467ee3f0105
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249998
Reviewed-by: Robert Findley <rfindley@google.com>
2020-08-23 20:58:32 +00:00
Pontus Leitzler
307de81be3 internal/lsp: do not log failed suggested fix for fillstruct to stderr
Avoid logging to stderr as it will interfere with LSP communication.

Change-Id: Ic9ff4f3555eabb8b0b6503650df7de5ddb76ef98
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249997
Run-TryBot: Pontus Leitzler <leitzler@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2020-08-22 20:38:24 +00:00
Rob Findley
1e23e48ab9 internal/lsp: improvements for command messages
When falling back to messages for progress reporting, don't try to
implement cancellation via ShowMessageCommand dialogs. They are an
imperfect solution, as the dialog stays open even after the command
completed. Also, among the LSP clients that don't support workDone
reporting, I suspect many also don't support ShowMessageCommand (for
example, govim), so the audience for this feature is probably quite
small.

Just remove it, and instead show a (non-cancellable) message. If clients
want cancellation, workDone progress support is the way to provide it.

Also remove a redundant message on go-generate success, and attach logs
when tests fail. Without logs on failure, I find that the test command
is not very useful. I tested a bit with very verbose test output, and
both VS Code and coc.nvim handled it gracefully.

Finally, fix a bug causing benchmarks not to be run.

Change-Id: I05422bcefc857c25cd99e643e614a0bc33870586
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249702
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-08-21 20:07:30 +00:00
Heschi Kreinick
3366bbee47 internal/lsp/regtest: reproduce empty xtest bug
packages.Load returns bad data for an empty xtest in GOPATH mode.

Updates golang/go#40825.

Change-Id: Ibab8dcbeafc22a71a2a4c3be0008b728c13c4c80
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249703
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-21 19:26:10 +00:00
Danish Dua
3509cdc6e9 internal/lsp: add ast fields to comment completion for declarations
* adds support for comment completion inside declarations
* improves scoring for completion results for comments
* adds comment completion support for non-exported symbols
* adds pruning for results that don't match text surrounding cursor
* tests for comment completion

Change-Id: Icb445a469cee3122fe032630bee037c7bdfe2e18
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249639
Run-TryBot: Danish Dua <danishdua@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-08-21 18:29:12 +00:00
Rob Findley
daa6538899 internal/lsp/source: fix panic in formatZeroValue for invalid type
formatZeroValue is currently only used when formatting return values for
statement completion. Per golang/go#40956, it must be possible to hit
this codepath with an invalid type.

In this case, the empty string seems like a reasonable value. Perhaps we
could do better, but fix the panic for now.

Fixes golang/go#40956

Change-Id: I45b559d41001c857cef34aea2a5ac4a9096fe950
Reviewed-on: https://go-review.googlesource.com/c/tools/+/249818
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2020-08-21 17:11:49 +00:00