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

3661 Commits

Author SHA1 Message Date
Rebecca Stambler
a857023c21 internal/lsp: use protocol.Range for diagnostics instead of span.Span
This is the first in a series of many changes that will change the API
of the source package to use different types for positions. Using
token.Pos is particularly fragile, since the pos has to refer to the
specific *ast.File from which it was derived.

Change-Id: I70c9b806f7dd45b2e229954ebdcdd86e2cf3bbbb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190340
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-16 17:06:24 +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
Suzy Mueller
d0b4265052 internal/imports: get candidate imports
This exposes the candidate imports that are discovered, even if there is
not a particular reference that requires it to be imported. Currently,
this only produces results for standard library packages.

This is useful for autocompletion on unimported packages.

Change-Id: Iafd883153d451a0ef1dae29b24d4d48530c855f7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189999
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-16 16:26:37 +00:00
Ian Cottrell
5b08f89bfc internal/telemetry: clean up the exporter api
this shuffles things so there a single exporter API rather than an observer
It also removes most of the globals.
per telemetry type.

Change-Id: Iaa82abe2ded1fff9df8e067ed4a55bcbd9d9591f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190405
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-15 23:56:12 +00:00
Rebecca Stambler
2562441715 internal/lsp: propagate hoverKind to completion documentation
Fixes golang/go#33653

Change-Id: Ia45e4f4b7377681619303a6d414d9b9de3143c01
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190400
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-15 23:26:00 +00:00
Rebecca Stambler
3100af0b0e internal/lsp: label context cancellation errors
This change will just make it a bit easier to debug the context
cancellation errors.

Change-Id: I580751ac04e3357031678eb31914828029c96e4b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190412
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-15 23:24:24 +00:00
Ian Cottrell
922a4ee32d internal/telemetry: extract units to their own package
This makes the code read slightly better, and more closely
aligns with the open telemetry code.

Change-Id: I87eaf7d08b802f7862f896f2654456ee6a7681e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190404
Run-TryBot: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-15 21:28:32 +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
Sander van Harmelen
d87e9bbada internal/lsp: limit concurrent file reads
We need to limit the concurrent file reads to prevent `too many open
file` errors. The first attempt to solve this was done in change 189437,
but this change turned out to be incorrect.

So this change reverts the changes made in change 189437 and instead
adds an new semaphore around the `nativeFileHandle.Read` method.

The limit is currently set to half of the lowest open file system limit
of *nix, Windows and MacOS system (their respective limits are 1024, 16384,
and 256).

Change-Id: I27d741e3a3c36eb11bfa7457575f5d5831c06ad7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190417
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-15 21:27:41 +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
Suzy Mueller
ea4142463b internal/imports: merge import declarations
When an import is added to the ast, the import declarations are merged
together into the first import declaration. Since this is a part of
the formatting functionality of goimports, do this during formatting
regardless.

The merging pass was added to astutil.AddNamedImport in order to address
issue golang/go#14075. This joined imports from other blocks into the first
import declaration, so that a single block of imports isn't split across
multiple blocks.

This functionality is more of a formatting change than a fix imports
change, in line with sorting the imports, which occurs even when
FormatOnly. The formatting was only applied when an import was added
(not renamed or deleted). This change makes formatting by goimports
more consistent across runs and is not dependent on the exact fixes
that need to be applied.

Change-Id: Icb90bf694ff35e2d6405a3d477cf82fcd3e697e0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189941
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-14 23:54:02 +00:00
Suzy Mueller
578fe56564 internal/imports: use the resolver to load exports
Have the imports resolvers load the exports for packages. This allows
each resolver to provide its own implementation of loading exports,
beyond reading from the directory.

Change-Id: I813f2ca59271a1698874556e8771243ac008f46f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188759
Run-TryBot: Suzy Mueller <suzmue@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-14 23:51:36 +00:00
Suzy Mueller
4cb0cfd181 internal/imports: test exported functions with nil args
Test the api of the internal imports package to make sure that it does
not crash when given nil as opts or Env.

Change-Id: I0127d550a49f63040efb16c07e8cff8b599bbe3c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190000
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-14 23:42:26 +00:00
Michael Matloob
9fae7b2cd5 go/packages: work around another case where go list doesn't respect -e
When there's an error running the C compiler for cgo, go list will produce
output, but will also complain in stderr, and return a nonzero exit status.
But it sholudn't return a non-zero exit status in that case when run with
-e. Check for and suppress this case.

Fixes golang/go#33462

Change-Id: Idae0970000a0cb134386f5e66d2b63b348ec8576
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190339
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-14 22:11:13 +00:00
Rebecca Stambler
f60b6e7d83 go/packages: add test case for golang/go#33462
Updates golang/go#33462

Change-Id: I66e0ff1a87eab1958eed87a30e0e09b47a62d43c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190177
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-14 21:40:36 +00:00
Michael Matloob
5b18234b3a go/packages: set -mod=readonly when processing overlays in module mode
To prevent us from adding additional module dependencies to modules, especially
if the file is in a different module. Sometimes adding additional dependencies
would be the right behavior, but sometimes we run go list to determine
information about files in other modules, and modifying modules outside the one
the user is operating in is bad  behavior.

Fixes golang/go#32499

Change-Id: I2a12e0a64dc6cd34fa98931cbacc30707e5ba494
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190179
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-14 17:19:36 +00:00
Dominik Honnef
597f577694 go/packages: handle more errors that 'go list' prints to stderr
This change adds special handling for two more errors that 'go list'
prints to stderr:

1. when trying to construct an ad-hoc package from files in multiple
   directories
2. the "unexpected directory layout" error (#24854)

Change-Id: Icbd14bcc02c2ca9676dc0449e155ff817da038cb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190077
Run-TryBot: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-14 16:41:31 +00:00
Rebecca Stambler
60bb3025ec internal/lsp: fix race condition in caching
This change fixes a race condition in the metadata caching logic.
Also, some minor fixes to comments and invalidation logic (it's not
necessary to invalidate ASTs when a package is invalidated).

Change-Id: I927bf6fbc661a86ef0ba99b29a9ed979cd1eb95d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190317
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-14 16:34:44 +00:00
Muir Manders
2adf828841 internal/lsp: add fuzzy completion matching
Make use of the existing fuzzy matcher to perform server side fuzzy
completion matching. Previously the server did exact prefix matching
for completion candidates and left fancy filtering to the
client. Having the server do fuzzy matching has two main benefits:

- Deep completions now update as you type. The completion candidates
  returned to the client are marked "incomplete", causing the client
  to refresh the candidates after every keystroke. This lets the
  server pick the most relevant set of deep completion candidates.
- All editors get fuzzy matching for free. VSCode has fuzzy matching
  out of the box, but some editors either don't provide it, or it can
  be difficult to set up.

I modified the fuzzy matcher to allow matches where the input doesn't
match the final segment of the candidate. For example, previously "ab"
would not match "abc.def" because the "b" in "ab" did not match the
final segment "def". I can see how this is useful when the text
matching happens in a vacuum and candidate's final segment is the most
specific part. But, in our case, we have various other methods to
order candidates, so we don't want to exclude them just because the
final segment doesn't match. For example, if we know our candidate
needs to be type "context.Context" and "foo.ctx" is of the right type,
we want to suggest "foo.ctx" as soon as the user starts inputting
"foo", even though "foo" doesn't match "ctx" at all.

Note that fuzzy matching is behind the "useDeepCompletions" config
flag for the time being.

Change-Id: Ic7674f0cf885af770c30daef472f2e3c5ac4db78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190099
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-14 16:13:50 +00:00
Rebecca Stambler
9dba7caff8 internal/lsp: show generated warning on didChange, not didOpen
Change-Id: I1c7346ab5265ed56d7142318b94028095e51f695
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190017
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-13 21:47:29 +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
Muir Manders
41f3357785 internal/lsp: don't deep complete struct field names
When it is certain we are completing a struct field name, we don't
want deep completions. The only possible completions are the remaining
field names.

I also silenced the log spam in tests by disabling the go/packages
logger and the lsp logger.

Fixes golang/go#33614

Change-Id: Icec8d92112b1674fa7a6a21145ab710d054919b4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190097
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-13 21:38:55 +00:00
Michael Matloob
97f12d7376 go/analysis: add a "-fix" flag to checker to apply suggested fixes
Fix will rewrite all the files in place given that there were no
overlapping or invalid suggested fixes. It's intended to be used
with analyses that generate refactorings.

Change-Id: I7ef3c872b58fdd4913fc34b725188e1846969849
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189997
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-13 14:23:22 +00:00
Ian Cottrell
528a2984e2 internal/lsp: fix data race in cmd tests
fixes golang/go#33392

Change-Id: I442bf8c04d793e06631a1a9d6c905cb2dcd284b8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189944
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-13 03:47:49 +00:00
Rebecca Stambler
afc3694995 go/packages: add a test case for golang/go#32499
Updates golang/go#32499

Change-Id: Ib9daf7c0dc8c6052f84230e54e181ab60166349b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/190037
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-12 23:30:24 +00:00
Suzy Mueller
2ad8dc80bc internal/imports: return initialized options
Whent the pointer is nil, changing its value does not fix the returned
options. Return the new pointer so it can be used.

Change-Id: Ie17fe5c47b48b4a77ffb17b974a5c90e3b44df5e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189998
Run-TryBot: Suzy Mueller <suzmue@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-12 22:09:39 +00:00
Rebecca Stambler
1e8b33d652 internal/lsp: ignore files that begin with underscores
Fixes golang/go#33540

Change-Id: I5b55c23ac8ff54db94387ed6b70ba39c61ba6108
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189940
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-08-12 22:06:16 +00:00
Rebecca Stambler
89a01ca1a8 internal/lsp: support an experimental structured hover format
Updates golang/go#33352

Change-Id: Ibf18e2529c9ba8c94c66942ea6f2c27f047ed285
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189977
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 21:55:50 +00:00
Rebecca Stambler
0d62d4405e internal/lsp: change ordering of hover depending on hoverKind
This change configures the ordering of documentation on hover. If the
user has requested full documentation, the signature appears at the top,
to avoid the user having to scroll. Otherwise, the signature appears at
the bottom, to minimize the distance between the triggering identifier
and the signature.

Updates golang/go#33352

Change-Id: I017baaabd0ee0c31cb13cb6abdda296782929823
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189943
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 21:11:28 +00:00
Suzy Mueller
4147ede4f8 internal/imports: fix setting default options
This fixes a nil pointer bug that occurs when opt is nil.

If nil is provide as opt to the internal/imports package, use the
default options settings.

Also check separately that Env is non-nil, as this would also cause
a crash.

Change-Id: I9a43b219b31ba80b7cb8111437f211cb72f1ca18
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189939
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-08-12 19:12:14 +00:00
Rebecca Stambler
f07d81a593 internal/lsp: fix documentation for completion items
This change fixes documentation for completion items by using cached
package and AST information to derive the documentation. We also add
testing for documentation in completion items.

Change-Id: I911fb80f5cef88640fc06a9fe474e5da403657e3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189237
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-12 17:13:29 +00:00
Jean de Klerk
6d4652c779 digraph: add transpose
Change-Id: Idd6299fd7397840000139ce4fbea43a95ee76b1e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/186797
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-09 14:56:39 +00:00
Jean de Klerk
a4e10e6d0e digraph: refactor somepath to print an adjacency list
Refactors somepath to print an adjacency list from "from" to "to", instead of
just the nodes. This allows other tools like modgraphviz to print the subgraph.

This is a breaking change. The previous behavior returned vertices; now it
returns edges. If you relied on the previous behavior, use:

    my-application | digraph somepath <from> <to> | digraph nodes

Change-Id: Id5e77e19eea79849ec6f25018f627c8dc4e2a831
Reviewed-on: https://go-review.googlesource.com/c/tools/+/184338
Run-TryBot: Alan Donovan <adonovan@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
2019-08-09 14:56:25 +00:00
Michael Matloob
e713427fea go/analysis: remove +experimental build tag from suggested fixes
We're still leaving open the possibility of changing this API,
but things have baked for a bit so I feel comfortable removing the
build tag.

Also add some documentation.

Change-Id: I3beb666b58177553fc406dc9670d569d5928fedd
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189460
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-08 19:51:39 +00:00
Michael Matloob
a804cf87ae go/packages: handle ad-hoc overlays with sources outside modules
If a user runs a file= query for a source that doesn't exist,
and they are outside of a module, fill in the GoSources for the
empty package that go list returns, so the overlay can be applied.

Also add a hack for the case where go list can't determine the compiler
(gc or gccgo) a user is using because
    go list -f "{{context.Compiler}}" -- unsafe
doesn't work. If go list complains that a user is outside a module,
we'll give ourselves flexibility to guess things because there's
no right answer. So we'll guess that the compiler is gc.

Fixes golang/go#33482

Change-Id: I6a8aa0c617c4d803558389fb4272854245f59c5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189322
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-08 19:06:35 +00:00
Sander van Harmelen
128824a23e internal/lsp: prevent too much open files issues
On MacOS the default open file limit is 256 files per process. For big
projects this could cause issues when reading all files (more or less)
at the same time.

By moving up the `parseLimit` so the reading of the file is only done
when it is allowed to start parsing the file, we stay well below the 256
files per process (as the `parseLimit` is currently set to 20).

Since `parseLimit` is actually only used to limit IO access, let's also
rename the const to `parseLimit`.

Change-Id: Ie8744030875d84d0d6095ee4ec2d9d553911bed1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189437
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-08-08 17:29:24 +00:00
Sander van Harmelen
b346f7fd45 x/tools/cmd/gopls: prevent nil pointer dereferences
The `files` slice is used twice. First it's used to get all results from `ph.Parse`, and then it's reused to filter all `nil` values (which may have been returned by the `ph.Parse` method).

After the loop to "filter" out all the `nil` values, we also need to strip the remaining values.

I also changed the ordering so that we first check the errors and
only then perform this loop. That way the code will return earlier
when the context was canceled.

Partially fixes #33531 by prevention the panic reported in that issue.

Change-Id: I09478e765adcd0384ec4745921eb5c5aea405ef2
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189397
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-07 22:35:07 +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
cae9aa5434 internal/lsp: show "do not edit" message when user opens generated file
This is probably a better approach than showing an extra diagnostic,
since a user cannot dismiss a diagnostic.

Fixes golang/go#33397

Change-Id: I92b9a00f51a463673993793abfd4cfb99ce69a91
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188766
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-07 16:44:42 +00:00
Rebecca Stambler
88ddfcebc7 go/packages: add a test for ad-hoc packages in overlays
Updates golang/go#33482

Change-Id: Ib24a0b955694455ddf1fc31011d57a7d797519ae
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-08-06 21:53:03 +00:00
Michael Matloob
9fb8e5c879 internal/lsp/testdata: delete nodisk/newdisk_exists.go
It should work now that go packages accepts go1.13's new go list
behavior.

Updates golang/go#33157

Change-Id: I1780210b414bc0556e10e10c8c775fbfd2922b2e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189038
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-06 20:59:09 +00:00
Michael Matloob
6743d4095d go/packages: rewrite Go 1.11's no such directory err to look like 1.13's
Then the rest of go/packages can process the go list output as usual.

Fixes golang/go#33491

Change-Id: I1bd46154ce75d67dc3e18454a067bcc084526c5d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189160
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-06 19:49:50 +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
249e2b9b6d internal/lsp/cmd: handle errors when adding a file
Change-Id: Iaed5c92fe777e5b9b588614b5c1696851e3f6c93
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188597
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-06 19:33:29 +00:00
Rebecca Stambler
73d708539c internal/lsp/cmd: remove unused isRace global variable in cmd
Change-Id: I9a71df9012fe7477b9e28b8665806d2ecc18f659
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188359
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-08-06 19:31:56 +00:00
Rebecca Stambler
1dcc99b65a internal/lsp: do not show errors for code actions on go.mod files
This change keys the supported code actions map by file kind, so that we
can extend it more easily for go.mod files.

Change-Id: Ic28f91bd517700cf070281b1c4d4ded14a702790
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189039
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-06 19:11:59 +00:00
Rebecca Stambler
982211fce4 internal/lsp: support single-line hover for LSP clients like Vim
Fixes golang/go#32561

Change-Id: I4399be3cfe745b85a23a82a183277e290ef2a3d8
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188981
Reviewed-by: Ian Cottrell <iancottrell@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-08-06 19:08:13 +00:00
Michael Matloob
35ef2682e5 go/analysis: change AllObjectFacts and AllPackageFacts to filter facts
Facts are intended to be private to an analysis. Even though it's hard
to guarantee with the information we have that facts won't leak to the
wrong analysis, we can filter some analyses that couldn't possibly have
come from the same analysis. AllObjectFacts and AllPackageFacts will
now filter facts if their type isn't specified in an analysis's FactTypes.

Change-Id: I2794437a5810e08fe6a9652b3569c5e3c17e159f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/189037
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
2019-08-06 14:34:15 +00:00
Michael Matloob
c5a2fd39b7 go/packages: handle case when go list returns absolute ImportPath
go list -e, when given an absolute path, will find the package contained at
that directory. But when no package exists there, it will return a fake package
with an error and the ImportPath set to the absolute path provided to go list.
This change modifies the go list driver to convert that absolute path to what
its package path would be if it's contained in a known module or GOPATH entry.
This will allow the package to be properly "reclaimed" when overlays are
processed.

Fixes golang/go#33157

Change-Id: I5ac032879884f52edbe45e00ed3949d84a71715e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188764
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-08-05 22:20:50 +00:00
Emmanuel T Odeke
e1fc249b66 internal/lsp/telemetry/ocagent: add convertAnnotation tests
* Adds tests for 'convertAnnotation'.
* Ensures that converting an empty string "" to
a truncatable string returns nil, to save bandwidth. However,
in the future, we should perhaps allow empty strings to
be serialized if say "emptyAllowed" is set.
* Caught the case where convertAttribute hadn't type
switched on "int"
* Provides 40.5% test coverage for ocagent.go

More tests for the other functions shall follow in later CLs.

Updates CL 186679

Change-Id: Ie9b46b0b320339ed79cd136fff536ccfcfbeb9e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/188877
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-08-05 19:50:47 +00:00