1
0
mirror of https://github.com/golang/go synced 2024-10-01 09:48:32 -06:00
Commit Graph

17 Commits

Author SHA1 Message Date
Rohan Challa
ad473c03aa internal/lsp: add handling for go.mod files in internal/lsp functions
When we are processing a go.mod file, we are calling go/packages.load
when we should not be. It will always return 0 packages since it is
not a .go file. This CL adds branching inside each internal/lsp protocol
function and also adds a check in snapshot.PackageHandles for the file type
and returns an error. This will prevent `go list` from running on go.mod files for now.

Updates golang/go#31999

Change-Id: Ic6d0e9b7c81e1f404342b98e10b9c5387adde2ee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210757
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rohan Challa <rohan@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-12-11 23:24:34 +00:00
Muir Manders
a27fdba277 internal/lsp: check all package variants in find-implementations
We previously only searched for implementations of the object we found
in the "widest" package variant. We instead need to search all
variants because each variant is type checked separately, and
implementations can be located in packages associated with different
variants.

For example, say you have:

-- foo/foo.go --
package foo
type Foo int
type Fooer interface { Foo() Foo }

-- foo/foo_test.go --
package foo
func TestFoo(t *testing.T) {}

-- bar/bar.go --
package bar
import "foo"
type impl struct {}
func (impl) Foo() foo.Foo { return 0 }

When you run find-implementations on the Fooer interface, we
previously would start from the (widest) foo.test's Fooer named
type. Unfortunately bar imports foo, not foo.test, so bar.impl
does not implement foo.test.Fooer. The specific reason is that
bar.impl.Foo returns foo.Foo, whereas foo.test.Fooer.Foo returns
foo.test.Foo, which are distinct *types.Named objects.

Starting our search instead from foo.Fooer resolves this issue.
However, we also need to search from foo.test.Fooer so we match any
implementations in foo_test.go.

Change-Id: I0b0039c98925410751c8f643c8ebd185340e409f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/210459
Run-TryBot: Muir Manders <muir@mnd.rs>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-12-11 21:44:05 +00:00
Rebecca Stambler
35ba81b9fb internal/lsp: reorganize and refactor code
This change cleans up internal/lsp/source/view.go to have a more logical
ordering and deletes the view.CheckPackageHandle function. Now, the only
way to get a CheckPackageHandle is through a snapshot (so all of the
corresponding edits).

Also, renamed fuzzy tests to fuzzymatch. Noticed this weird error when
debugging - I had golang.org/x/tools/internal/lsp/fuzzy in my module
cache and it conflicted with the test version.

Change-Id: Ib87836796a8e76e6b6ed1306c2a93e9a5db91cce
Reviewed-on: https://go-review.googlesource.com/c/tools/+/208099
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-11-21 02:33:28 +00:00
Rebecca Stambler
80313e1ba7 internal/lsp: fix panic in bestView
Rather than panicking when we have not created any views for the packages,
we should show a reasonable error to the user. This change propagates the
errors to the user.

Updates golang/go#35599

Change-Id: I49789d8ce18e154f111bc3584488f468a129e30c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/207344
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-11-16 21:44:31 +00:00
Rebecca Stambler
e33b02e766 internal/lsp: use versioned URIs in rename and code actions
This change adds support for returning versions along with file URIs, so
that the client can know when to apply changes. The version is not yet
propagated along to the internal/lsp/cache package, so this change will
have no effect (VS Code ignores a version of 0 and still applies the
changes).

A few minor changes made in the rename code (to remove the view
parameter). Some minor staticcheck fixes.

Updates golang/go#35243

Change-Id: Icc26bd9d9e5703c699f555424b94034c97b01d6f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/206882
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-11-13 05:52:40 +00:00
Rebecca Stambler
57610eddc9 internal/lsp: rework snapshots and cache FileHandles per-snapshot
This change does not complete the work to handle snapshots correctly,
but it does implement the behavior of re-building the snapshot on each
file invalidation.

It also moves to the approach of caching the FileHandles on the snapshot,
rather than in the goFile object, which is now not necessary.

Finally, this change shifts the logic of metadata invalidation into the
content invalidation step, so there is less logic to decide if we should
re-load a package or not.

Change-Id: I18387c385fb070da4db1302bf97035ce6328b5c3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197799
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-01 16:26:22 +00:00
pjw
fef9eaa9e4 x/tools/gopls: convert to the august, 2019 version of the LSP protocol
The latest version of the LSP protocol introduces a number of changes.
It is now possible to indicate partial results and progress. request.ts
had to construct some new types (at the end of tsclient.go and tsserver,go)
to avoid using a struct for a formal parameter type.  Also,
instead of using the same type for many RPCs, most RPCs now have their own
types.

Change-Id: I095a3e872f42a9f851c01ca4e3c6ac6e32446042
Reviewed-on: https://go-review.googlesource.com/c/tools/+/194177
Run-TryBot: Peter Weinberger <pjw@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-08 13:59:31 +00:00
Rebecca Stambler
2ca718005c internal/lsp: use protocol.TextEdits in suggested fixes
Change-Id: I8b454dd8c59839468ecfcb19b7edfa659e386b57
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193957
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-07 02:01:28 +00:00
Rebecca Stambler
8159a2d3d6 internal/lsp: use protocol.Position for textDocument/prepareRename
Change-Id: Ic896321dff17e788d46dae2efc12ecbf2b2f53dd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193723
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-09-06 18:55:03 +00:00
Suzy Mueller
c9403068c1 internal/lsp: add prepare rename support
Prepare rename gets the range of the identifier to rename. Returns an
error when there is no identifier to rename.

Change-Id: I5e5865bc9ff97e6a95ac4f0c48edddcfd0f9ed67
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191170
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-29 20:19:46 +00:00
Rebecca Stambler
42f498d34c internal/lsp: use protocol.Ranges for source.Identifier
Change-Id: I42cb957e3c1676e2ec7e3f50dd5e3613f3dd9555
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191880
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-29 05:14:58 +00:00
Rebecca Stambler
547ecf7b1e internal/lsp: use protocol.Range in completion items
This change switches Completion to use protocol positions instead of
token.Pos.

Change-Id: I012ce03c9316d8363938dd0156f485982b7e04fe
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190600
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-20 20:57:17 +00:00
Rebecca Stambler
6889da9d54 internal/lsp: separate out getMapper function
This is a super minimal change that will simplify the diffs for when I
actually delete the getMapper function.

Change-Id: I16984b344c87b3645fd451668b6ea747c5be12ab
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190557
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-16 20:05:58 +00:00
Rebecca Stambler
8be58fba63 internal/lsp: minor refactoring for source.Identifier
Change-Id: Ia604f59d6229c2086fe63e73466de7489e1cda2d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189321
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-07 20:13:05 +00:00
Rebecca Stambler
252024b829 internal/lsp: separate refactorings out of memoization CL
This change just separates minor changes made along the course of the
memoization CL out into their own change. This will clean up the diffs
in the memoization CL.

Change-Id: I7d59e05ba6472af5f1bf516b1e5b879a5815b9a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183250
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-25 16:04:30 +00:00
Suzy Mueller
1fa568393b internal/lsp: check for conflicts on rename
Before renaming a variable, check the package to make sure that this
renaming would not result in a conflict that could break the program.

All of the implementation is taken from "refactor/rename" with the
dependency on "go/loader" removed.

Change-Id: Ib0782ec8f247a6df1750f2c8213f69186699ce1a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183257
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-20 19:17:50 +00:00
Suzy Mueller
4adf7a708c internal/lsp: add identifier renaming
This change provides support to rename identifiers within a single
package.

The renaming is performed by finding all references to an identifier,
and then creating text edits to replace the existing text with the
new identifier.

Editing an import spec is not supported.

Fixes #27571

Change-Id: I0881b65a1b3c72d7c53d7d6ab1ea386160dc00fb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/182585
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-19 21:54:42 +00:00