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

20 Commits

Author SHA1 Message Date
Rebecca Stambler
8110780cfa internal/lsp: add correct handling for circular imports
This change brings back handling for circular imports, which was removed
because I originally thought that go/packages would handle that.
However, since we are type-checking from source, we still end up having
to deal with that.

Additionally, we propagate the errors of type-checking to the
diagnostics so that the user can actually see some of the problems.

Change-Id: I0139bcaae461f1bcaf95706532bc5026f2430101
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166882
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-15 16:49:21 +00:00
Ian Cottrell
dbad8e90c9 internal/lsp: convert to the new location library
This rationalises all the position handling and conversion code out.
Fixes golang/go#29149

Change-Id: I2814f3e8ba769924bc70f35df9e5bf4d97d064de
Reviewed-on: https://go-review.googlesource.com/c/tools/+/166884
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-03-13 19:34:21 +00:00
Rebecca Stambler
7b79afddac internal/lsp: add a source.Package interface
This change adds a Package interface to the source package, which allows
us to reduce the information cached per-package (we don't use any of the
unnecessary fields in a *go/packages.Package).

This change also adds an analysis cache for each package, which is used
to cache the results of analyses to avoid recomputation.

Change-Id: I56c6b5ed51126c27f46731c87ac4eeacc63cb81a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165750
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-12 16:49:27 +00:00
Rebecca Stambler
00c44ba9c1 internal/lsp: add cache for type information
This change adds an additional cache for type information, which here is
just a *packages.Package for each package. The metadata cache maintains
the import graph, which allows us to easily determine when a package X
(and therefore any other package that imports X) should be invalidated.

Additionally, rather than performing content changes as they happen, we
queue up content changes and apply them the next time that any type
information is requested.

Updates golang/go#30309

Change-Id: Iaf569f641f84ce69b0c0d5bdabbaa85635eeb8bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/165438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-03-08 17:45:44 +00:00
Ian Cottrell
69a2705782 internal/lsp: remove error return values from interface "field" accessors
we don't really use them, only generate them in cases where the failure is way more fundamental, and then also fail
to remember them for the next call to the same accessor. Better to not have them.

Change-Id: I0e8abeda688f5cc2a932ed95a80d89225c399f93
Reviewed-on: https://go-review.googlesource.com/c/162399
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-02-13 21:58:50 +00:00
Rebecca Stambler
3744606dbb internal/lsp: type-check packages from source
This change moves gopls from type-checking packages using the
go/packages API to type-checking from source. This is the first step in
adding caching to gopls.

Change-Id: I2a7dcfd8c9c0bfc6c35c86eadcdc6f9ce53d9be7
Reviewed-on: https://go-review.googlesource.com/c/161497
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-08 22:27:37 +00:00
Rebecca Stambler
021ffbf1e9 internal/lsp: do not return nil identifiers without errors
Change-Id: I9ffc37dc07f46536a44f7173277d0374fdda1fb8
Reviewed-on: https://go-review.googlesource.com/c/160698
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-04 17:30:59 +00:00
Rebecca Stambler
51e363b66d internal/lsp: implement diff for computing text edits
Rather than replacing the whole file on gofmt or goimports, use the Myers
diff algorithm to compute diffs for a file. We send those back as text
edits.

Change-Id: I4f8cce5b27d51eae1911049ea002558a84cdf1bf
Reviewed-on: https://go-review.googlesource.com/c/158579
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-02-01 23:18:25 +00:00
Ian Cottrell
cc6a436ffe internal/lsp: refactor definition and hover to share functionality
The source package now exposes an Identifier method that returns information
about an identifier, which can be used to implement Definition, TypeDefinition
and Hover, as well as other command line functions in a later cl.

Change-Id: I03629c2c940215b4e2c86ee45bee8a18b79ee0e1
Reviewed-on: https://go-review.googlesource.com/c/159337
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-01-24 21:53:03 +00:00
Rebecca Stambler
bf090417da internal/lsp: fix a few nil pointer exceptions in definition
Jumping to the definition of a builtin function or basic kind would
cause a nil pointer because these have no position.

Change-Id: I043a61a148757b127ff1123c8429ce23858bd13a
Reviewed-on: https://go-review.googlesource.com/c/157597
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-01-14 22:23:45 +00:00
Rebecca Stambler
d00ac6d273 internal/lsp: remove unnecessary packagestest.RangePosition type
Some cleanup of lsp_test.

Change-Id: I0cf4eb73f223845374c7f7f4939a461ff676bde8
Reviewed-on: https://go-review.googlesource.com/c/155579
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Libor K <aschrak1978@gmail.com>
2018-12-21 23:52:34 +00:00
Rebecca Stambler
62138107df internal/lsp: fix diagnostics range computation
Diagnostics were failing because of
https://go-review.googlesource.com/c/tools/+/154742, where I was using
the wrong *token.File for the position calculations. This should fix the
problem.

Change-Id: Ic44e7799da56010b5014d56029fb4e0a8a6bb0e8
Reviewed-on: https://go-review.googlesource.com/c/155479
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-21 20:18:27 +00:00
Rebecca Stambler
85a09cd5ed internal/lsp: set file contents through the source.View, not File
Refactor code as a follow-up to
https://go-review.googlesource.com/c/tools/+/154742.
Also, change every instance of "source.URI()" to "fromProtocolURI", so
that we can add a better implementation of that later on (for Windows
support).

Change-Id: Ifa24ffd7e1aebf1f7d05df6f65742769ead0922f
Reviewed-on: https://go-review.googlesource.com/c/154741
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-12-21 19:33:31 +00:00
Rebecca Stambler
f344c7530c internal/lsp: add ranges to some diagnostics messages
Added a View interface to the source package, which allows for reading
of other files (in the same package or in other packages). We were
already reading files in jump to definition (to handle the lack of
column information in export data), but now we can also read files in
diagnostics, which allows us to determine the end of an identifier so
that we can report ranges in diagnostic messages.

Updates golang/go#29150

Change-Id: I7958d860dea8f41f2df88a467b5e2946bba4d1c5
Reviewed-on: https://go-review.googlesource.com/c/154742
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-20 19:13:07 +00:00
Rebecca Stambler
3576414c54 internal/lsp: refactor source package to use an interface
This change separates a cache package out of the
golang.org/x/tools/internal/lsp/source package. The source package now
uses an interface instead a File struct, which will allow it be reused
more easily. The cache package contains the View and File structs now.

Change-Id: Ia2114e9dafc5214c8b21bceba3adae1c36b9799d
Reviewed-on: https://go-review.googlesource.com/c/152798
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-05 22:49:35 +00:00
Rebecca Stambler
62e1d13d53 internal/lsp: add basic support for hover
This change adds a very simple implementation of hovering. It doesn't
show any documentation, just the object string for the given object.

Also, this change sets the prefix for composite literals, making sure we
don't insert duplicate text.

Change-Id: Ib706ec821a9e459a6c61c10f5dd28d1798944fa3
Reviewed-on: https://go-review.googlesource.com/c/152599
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-05 22:25:06 +00:00
Rebecca Stambler
3832e276fb internal/lsp: implement type definitions
Extend definition tests to add typdef test.

Change-Id: Ibad988ae68f91d18f2c6b4739d758a536172fb35
Reviewed-on: https://go-review.googlesource.com/c/152239
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2018-12-04 18:51:09 +00:00
Ian Cottrell
1aef897494 internal/lsp: fix for limitations of export data
It is impossible to reconstruct a line and column correctly from export data, so
we have to attempt to find open and process the file in order to guess what the
original pos was when we have one that originated in export data.
This occurs in any time in go to definition when the target is not in the same
pacakge as the source.

Change-Id: Ib2ee404d4f1c39d8bd7f1fbc2096d8d6cbeed6f8
Reviewed-on: https://go-review.googlesource.com/c/150044
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-19 18:00:18 +00:00
Ian Cottrell
fc2e60c3c3 internal/lsp: make Definition handle embedded fields
This change allows it to jump to the type if you are directly on the
embedded field when you trigger go to definition.

Change-Id: I48825a5a683e69c0714978c76b1d188d40b38c5d
Reviewed-on: https://go-review.googlesource.com/c/149615
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-15 19:04:06 +00:00
Ian Cottrell
15ad1aa0cb internal/lsp: implement go to definition
This enables go to definition for the lsp.
It has one known non working case (where the filenames have $GOROOT in them)

Change-Id: I142c6e04b8691c5076dfcd55592ea710b4b361a4
Reviewed-on: https://go-review.googlesource.com/c/148158
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-11-07 18:43:41 +00:00