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

27 Commits

Author SHA1 Message Date
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
Rebecca Stambler
04840ef8f3 internal/lsp: switch to using protocol positions for document symbols
Change-Id: I8e550b753328b8e536bff3bb61b4ff4486fcd4f9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/193722
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:11:17 +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
Suzy Mueller
c4a336ef6a internal/lsp: support renaming of import spec
This change allows renamings of the name of an import spec.
Since there is not always explicit identifier available to select and
rename, allow renaming packages from positions within the import spec.

Change-Id: I0a8aaa92c26e1795ddb9c31a1165b2f2ee89aa34
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191165
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-23 17:09:09 +00:00
Suzy Mueller
fc82fb2afd internal/lsp: return error when renaming within an import spec
Since renaming an identifier within an import spec is not yet supported,
return an error when this is encountered. These idents from the import
spec have a nil declaration object.

Import paths that contain '.' or '/' are caught by the valid identifier check
avoiding the crash, but import paths such as "fmt" are not as fmt is a
valid identifier. This change checks if i.decl.obj is nil and returns an error
if it is to avoid the crash.

Fixes golang/go#33768

Change-Id: I4e757b42bedffd648fc821590e4a383826200dc3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/191163
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-22 00:03:11 +00:00
Ian Cottrell
85edb9ef32 internal/lsp: abstract the diff library so it can be substituted
this moves the actual diff algorithm into a different package and then provides hooks so it can be easily replaced with an alternate algorithm.

Change-Id: Ia0359f58878493599ea0e0fda8920f21100e16f1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190898
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-20 03:37:07 +00:00
Suzy Mueller
d5940c88eb internal/lsp: return rename errors for one package only
Rename checks all of the packages that may be affected for conflicts. An
error in any of them leads to renaming error. Returning errors from
multiple packages may be confusing (for example, when there is a test
variant of a package and the same error appears twice). This change
stops after an error is found and returns that error instead of
continuing to search.

Change-Id: Ifba1feddbf8829d3aad30309154d578967e05a36
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190416
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-16 17:04:40 +00:00
Ian Cottrell
156eb2ae29 internal/lsp: split the telemetry library out
This is a straight move of some code with no changes.
It splits the part of the telemetry code that will become a standalone library from the bit that belongs in the lsp.

Change-Id: Icedb6bf1f3711da9251450531729984df6df7787
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190403
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-15 21:28:02 +00:00
Suzy Mueller
9065c182e3 internal/lsp: fix bug renaming local vars with test files present
This fix adds all packages to the renamer packages map.

Renaming performs checks on each package to make sure there are no
conflicts. If there are multiple packages, each package needs to be
checked. The packages were being incorrectly added to the map and were
all being put under a single key.

Fixes golang/go#33664

Change-Id: I68466ce34ac49b700ce6d14ce0b53e2795926fa9
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190399
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-15 14:43:58 +00:00
Rebecca Stambler
62ee03427e internal/lsp: use memoize package to cache source.Packages
This change eliminates the need for the package cache map, and instead
stores package type information in the store. We still have to maintain
invalidation logic because the key is not computed correctly.

Change-Id: I1c2a7502b99491ef0ff68d68c9f439503d531ff1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-13 21:41:43 +00:00
Jan Steinke
be5259f298 internal/lsp: use x/xerrors to create new errors
This relates to https://github.com/golang/go/issues/31374 and should switch all instances within `gopls` to use `x/errors` instead of `fmt` to create new errors.

Change-Id: I18339b75d12418d852e0dcc2ba0ed6c2970783b3
GitHub-Last-Rev: f4a55d9b79e7458ef1f1e06cb5eabbabd884f321
GitHub-Pull-Request: golang/tools#108
Reviewed-on: https://go-review.googlesource.com/c/tools/+/179880
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-06 19:46:56 +00:00
Rebecca Stambler
b667c4c58e internal/lsp: cache the *ast.File and *token.File on the package
This change removes the need for the ast and token fields on the *goFile
object. We switch to using source.ParseGoHandles on the package, which
means that we can easily access both the AST and token via the package,
which is already cached.

Change-Id: I5f78bbe09362f4d95eb15556617bdbd809a7a55d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185878
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-07-16 19:44:59 +00:00
Suzy Mueller
a0f5e6c5c2 internal/lsp: sort rename results
We recommend that gopls integrators apply the []TextEdit responses in
reverse order to get a correct resulting document. This strategy works
when the response is already sorted. Have gopls return sorted []TextEdit
for each file.

Fixes golang/go#33123

Change-Id: Ib570881c9623695d2ae3194fa8a97b0a681a3250
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186258
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-15 22:13:26 +00:00
Ian Cottrell
75aaabac35 internal/lsp: reduce trace package to minimal StartSpan for now
also change the return type to be and end function and not an incomplete span

Change-Id: Icd99d93ac98a0f8088f33e905cf1ee3fe410c024
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185349
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-11 17:25:55 +00:00
Suzy Mueller
7b25e351ac internal/lsp: rename identifiers in test packages
Support renaming of identifiers in test packages. The packages for
all of the references must be checked and the changes need to be
deduped, since both a package and its test package contain some of the
same files.

Fixes golang/go#32974

Change-Id: Ie51e19716faae77ce7e5254eeb3956faa42c2a09
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185277
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 21:17:00 +00:00
Suzy Mueller
07655f7ec7 internal/lsp: return an error when renaming a builtin
Return an error when attempting to rename a builtin identifier.

Fixes golang/go#32992

Change-Id: I7fb0f9cc9499e5afdfb14805c49c820e4da3b601
Reviewed-on: https://go-review.googlesource.com/c/tools/+/185246
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-09 18:23:51 +00:00
Ian Cottrell
4457e4cfd4 internal/lsp: add some trace spans to important functions
This uses the new opencensus compatability layer to add telementry to some of
the functions in the lsp, in order to allow us to understand their costs and
call patterns.

Change-Id: I7df820cd4eace7a4840ac6397d5df402369bf0a7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183419
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-03 19:14:57 +00:00
Suzy Mueller
f80f67146e internal/lsp: support renaming import specs
Support the renaming of the imported name of a package within a file.
This case needs to be special cased because the ident may be added or
removed.

Change-Id: I333bc2b2ca5ce81c4a2afb8b10035f525dfad464
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184199
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-07-02 14:51:11 +00:00
Suzy Mueller
6cfa55603c internal/lsp: check ident exists for comment rename
The identifier in a reference is used to check for a doc comment.
Implicits do not have an ident, so do not use that to look for a doc
comment.

Also set the context.Context for the renamer.

Change-Id: I085d9e6c11d919222592dcb6fb30982eeb0fc7cd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184042
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-06-28 17:52:03 +00:00
Edward Muller
1a55b1581c internal/lsp/source: move the common path to the left
As per the following guidance: "Try to keep the normal code path at a minimal indentation"

I know this is normally applied to error handling, but the same logic about improving readability applies here too.

Change-Id: Ib20dae9975e94b40fb6ff7049782375b18ef59ba

Change-Id: Ib20dae9975e94b40fb6ff7049782375b18ef59ba
GitHub-Last-Rev: 97919272de76ec15845556e032985c5969a277fa
GitHub-Pull-Request: golang/tools#125
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183698
Reviewed-by: Suzy Mueller <suzmue@golang.org>
Run-TryBot: Suzy Mueller <suzmue@golang.org>
2019-06-27 17:56:40 +00:00
Edward Muller
d1f656545b internal/lsp/source: don't panic compiling regex
This package is basically a library (even though it's internal) and
it's generally considered a bad practice for libraries to panic, so
don't.

Change-Id: I37d9d73ae48ececc6b31436f1076e1f85213f129

Change-Id: I37d9d73ae48ececc6b31436f1076e1f85213f129
GitHub-Last-Rev: 453b538e53e48889171d31829af3304409f9a8bc
GitHub-Pull-Request: golang/tools#124
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183680
Reviewed-by: Suzy Mueller <suzmue@golang.org>
2019-06-26 18:09:17 +00:00
Rebecca Stambler
3cbd95df51 internal/lsp: support a file belonging to multiple packages
This change adds supports for a package belonging to multiple files.
It requires additional packages.Loads for all of the packages to which a
file belongs (for example, if a non-test file also belongs to a package's
test variant).

For now, we re-run go/packages.Load for each file we open, regardless of
whether or not we already know about it.

This solves the issue of packages randomly belonging to a test or not.
Follow-up work needs to be done to support multiple packages in
references, rename, and diagnostics.

Fixes golang/go#32791
Fixes golang/go#30100

Change-Id: I0a5870a05825fc16cc46d405ef50c775094b0fbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183628
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-06-26 17:56:19 +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
70d37148ca internal/lsp: update doc comments on rename
Replace doc comment text for the declaration of an identifier with the
new name.

This implementation is taken from golang.org/x/tools/refactor/rename.

Change-Id: Id1b80fad456646a46c8ae2caa4e8febf05aaf798
Reviewed-on: https://go-review.googlesource.com/c/tools/+/183261
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-06-24 18:02:13 +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