1
0
mirror of https://github.com/golang/go synced 2024-09-30 22:38:33 -06:00
Commit Graph

754 Commits

Author SHA1 Message Date
Michael Matloob
e3efbe408c go/analysis: rename reportNodef to ReportRangef
This adds (or makes exported) a convenience function for reporting diagnostics with a
node directly (which is what folks usually want).

Change-Id: Ieb7ef2703f99d3a24ba7e48a779be62a7761cd0c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/180237
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-28 19:16:33 +00:00
Muir Manders
e96d959c47 internal/lsp: downrank untyped completion candidates
In cases like:

type myInt int
const (
  a       = 1
  b myInt = 2
)
var foo myInt = <>

We now prefer "b" over "a" since b's type matches the expected type
exactly.

Change-Id: I675934761cc17f6b303b63b4715b31dd1af7cea1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202737
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-25 17:43:33 +00:00
Francesco Renzi
2b544e3f2d tools/gopls: add cmd support for references
This change adds command line support for references.

Example:

$ gopls references ~/tmp/foo/main.go:8:6
$ gopls references ~/tmp/foo/main.go:#53

Updates golang/go#32875

Change-Id: I9a0cf6ae8ba0a5c3d4ffc829b96fe3b42297c192
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202178
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-25 16:51:12 +00:00
Muir Manders
cf891b754e internal/lsp: disable completion time budget in tests
Now a budget of 0 disables mean unlimited and tests no longer set the
budget. Hopefully the deep completion tests will stop flaking.

Updates golang/go#34617

Change-Id: Icdff5e78dcf1cc3d3fcbf0326716b39b00f0a8c1
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203338
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-25 16:51:05 +00:00
Rebecca Stambler
2077df3685 internal/lsp: remove analyzers from Analyze result
Also, address minor comments that I ignored from Heschi because I am
obnoxious.

Change-Id: I99dcac38578585af2cdd951dd2b9755732ef945f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203281
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-25 02:35:17 +00:00
Rebecca Stambler
3d91e92cde internal/lsp: stop caching diagnostics on the package
Now that we are using the memoize package to cache analysis results, we
can use that cache for suggested fixes.

Change-Id: I42905a6fe575f49d38979d53d58ea8ec59210ae0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203278
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-10-24 22:03:59 +00:00
Rebecca Stambler
e7a0da15e1 internal/lsp: don't cache analysis.Pass on actionHandle
There is no need to cache the pass on the actionHandle, as it does not
need to be reused and does not live outside the exec function.

Change-Id: I1737271383776b35718df3475b4f888232d57ae4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203177
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-24 21:34:16 +00:00
Heschi Kreinick
dc9d807def internal/imports: re-enable TestStdlibNotPrefixed
Vendor mode is fully supported now and I forgot to revert this.

Change-Id: I2a5b69818944e87cfb85e00f0486ffb3754fe6a6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203280
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-24 21:22:50 +00:00
Heschi Kreinick
377bdac4e7 internal/imports: support vendoring in module mode
Previously, goimports half-supported vendor mode -- it searched the
module cache on some code paths and the vendor dir in others. That
seemed to work okay, probably because people happened to have a populated
module cache. In 1.14, it's much more likely that people will work
solely from the vendor directory.

In this CL we bite the bullet and fully support vendor mode. 1.14 makes
this particularly challenging by disabling list -m ... in vendor mode, and
by enabling it automatically under some circumstances. We need to mirror
that behavior, which means knowing whether we're running with 1.14, and
figuring out whether vendoring should be enabled given that. We collect
the information we need with a list -m -f query just on the main module.

If vendor mode is enabled, we throw away all the modules and replace
them with a single pseudo-module rooted at /vendor. Everything basically
works at that point.

Fixes golang/go#34826

Change-Id: Ia4030344d822d5a4a3bbc010912ab98bf2f5f95b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203017
Reviewed-by: Bryan C. Mills <bcmills@google.com>
2019-10-24 21:04:39 +00:00
Heschi Kreinick
c825e86a85 internal/imports: skip TestStdlibNotPrefixed
At tip, $GOROOT/src/go.mod is 1.14, $GOROOT/src/vendor exists, and so
vendor mode is automatically enabled. That causes golang/go#34826.

This will be fixed by my upcoming vendoring CL, but for now skip.

Updates golang/go#34826

Change-Id: I5fff51fff54cf83e6369ae76bf3b19cfb7b5ac15
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203257
Run-TryBot: Heschi Kreinick <heschi@google.com>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-24 19:18:02 +00:00
Muir Manders
5228f4b59c internal/lsp: improve completions in *ast.MapType
We now expect a type name when in the key or value of a *ast.MapType.
I also added an extra filter to expect a comparable type for the key.

Change-Id: I647cf4d791b2c0960ad3b12702b91b9bc168599b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197439
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-24 19:03:17 +00:00
Rebecca Stambler
b24f3822ec internal/lsp: fix fallback and error handling logic
We don't need to worry about a package's errors unless it is the
top-level package. Also fix some fallback logic in the type error range
computation.

Change-Id: Ib26b5e25bd70193ea24ec4a197811eedf69b0e2c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202622
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-10-24 17:20:55 +00:00
Muir Manders
79994da4ae internal/lsp: fix VSCode's reordering of completion candidates
When VSCode applies its own fuzzy matching/filtering/ranking logic to
completion candidates, it can end up reordering and even omitting some
of our candidates. It is mainly a problem with deep completions (i.e.
VSCode downranks or completely hides deep completion candidates that
should be ranked at the top).

We now trick VSCode into not reordering our candidates by setting each
candidate's "filterText" to the completion prefix. This makes every
candidate look like an identically perfect match, so VSCode just
maintains the order specified by "sortText".

Note that we don't do this trick if server side fuzzy matching and
deep completions are disabled. In this case unimpeded client side
candidate filtering is necessary.

Change-Id: I677047bca12b9ce05a953016d0d89182f1fe44d6
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202717
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-10-24 16:29:03 +00:00
Nathan Dias
be03d4f470 internal/telemetry/export/ocagent: attach timestamps to metrics
This change attaches start timestamps to timeseries and end
timestamps to the points in each timeseries. Int64Data,
Float64Data, HistogramInt64Data, and HistogramFloat64Data
have also had an EndTime field added to keep track of the last
time the metric was updated.

What works:
* Start and end timestamps will now be attached to timeseries.

What does not work yet:
* MetricDescriptors will not have a unit attached.
* No labels will be attached to timeseries.
* Distributions will not have SumOfSquaredDeviation attached.

Updates golang/go#33819

Change-Id: I692e1676bb1e31de26c1f799b96428fc9a55d6c7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203060
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-10-24 07:31:07 +00:00
Brad Fitzpatrick
7b6f5d95f3 internal/memoize: add a go:nocheckptr annotation to (*Store).get
Fixes golang/go#35125

Change-Id: I08251b94a44fbc2324f6edc883d9d687b45a00b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/203078
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2019-10-24 04:42:40 +00:00
Rebecca Stambler
2b779830f9 internal/lsp: don't associate package with snapshot
This change effectively reverts CL 202039. This CL was a mistake, as it
creates a cycle. Snapshots hold CheckPackageHandles, which in turn hold
pkgs.

Change-Id: I944304cb365f0ef98b5e54ea38edea6cece40453
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202740
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-10-23 20:24:04 +00:00
Muir Manders
c8fcd6ab79 internal/lsp: don't offer empty "Organize Imports" action
If there are no imports that need organizing, don't send the "Organize
Imports" code action.

Change-Id: Id01521edd1524fb3f7372fd787d6c90418740cf3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202825
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-10-23 19:47:20 +00:00
Muir Manders
98e333b8b3 internal/lsp: improve completion for *ast.ArrayTypes
*ast.ArrayTypes are type expressions like "[]foo" or "[2]int". They
show up as standalone types (e.g. "var foo []int") and as part of
composite literals (e.g. "[]int{}"). I made the following
improvements:

- Always expect a type name for array types.
- Add a "type modifier" for array types so completions can be smart
  when we know the expected type. For example:

var foo []int
foo = []i<>

  we know we want a type name, but we also know the expected type is
  "[]int". When evaluating type names such as "int" we turn the type
  into a slice type "[]int" to match against the expected type.
- Tweak the AST fixing to add a phantom selector "_" after a naked
  "[]" so you can complete directly after the right bracket.

I split out the type name related type inference bits into a separate
typeNameInference struct. It had become confusing and complicated,
especially now that you can have an expected type and expect a type
name at the same time.

Change-Id: I00878532187ee5366ab8d681346532e36fa58e5f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197438
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-23 16:34:50 +00:00
Rebecca Stambler
0bbdf54eff internal/lsp: modify approach to watching changed files
This change modifies the invalidContent function to take a file change
type. This allows us to eliminate the separate invalidateMetadata
function. The logic of watching changed files is then further pushed
into the caching layer.

Updates golang/go#34218

Change-Id: Id31b3931c45ec408b6e7b4a362e00f9091ba4f70
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201221
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-22 21:33:45 +00:00
Muir Manders
8f1b74eef3 internal/lsp: fix label completion in range and type switch stmts
Fix label detection to know about *ast.RangeStmt
and *ast.TypeSwitchStmt.

Change-Id: I4061e165884f7064fe486249fe3664d572b7b628
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202621
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-22 21:33:09 +00:00
Muir Manders
83d82311fd internal/lsp: fix fuzzy matcher inconsistency
Originally the fuzzy matcher required a match in the final candidate
segment. For example, to match the candidate "foo.bar", the input had
to have at least one character that matched "bar". I previously
removed this requirement as it is too restrictive for deep completions
to be useful.

However, there was still some lingering final-segment favoritism in
the matching algorithm. In particular, there were penalties for not
matching the final segment's first character and for not matching the
final segment's word initial characters. However, these penalties only
made sense when we also required a final segment match. Consider this
example:

User input: "U"

Candidate "ErrUnexpectedEOF" - with only a single segment, we got big
penalties for not matching the leading "E" (since it is the final
segment).

Candidate "ErrUnexpectedEOF.Error" - "ErrUnexpectedEOF" is no longer
the final segment, so we didn't get penalties. And we didn't get
penalties for the final segment "Error" because we finished matching
after the first "U". As a result, this candidate slips through with a
higher score.

Fix by simplifying the skip penalty. Now we only penalize for skipping
the first character of the first or final segment (and the penalty is
lower). For deep completions, the first and final segment are both
"important" segments, so I think it makes sense to focus on both of
them. We don't want to penalize all segment starts because that makes
it harder to match deeper candidates where you often "ignore"
intermediate segments.

I had to adjust a few scores in the tests, but I don't think the
impact will be too big other than fixing the bug.

Fixes golang/go#35062.

Change-Id: Id17a5c80bf0f80ce252fe990ccfbd51c1bac1c72
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202638
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-22 21:05:28 +00:00
Muir Manders
a12cc76b85 internal/lsp: trim down the fuzzy matcher library
Remove the input type option. Now everything behaves as "symbol".

We don't use the "text" or "filename" input types, and I don't foresee
us using them. Removing them simplifies the code a bit, but simplifies
the tests a lot. It was tedious to make changes to the matcher logic
because you had to fret over test failure details that didn't actually
matter because we didn't use that functionality.

Change-Id: I651debde9e63ee283d7bc3ad718d22f4b9a127c0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202637
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-22 20:51:43 +00:00
Sebastian Chlopecki
25e800de08 internal/lsp: add some keyword completions
For *ast.Ident completion requests, this checks the parent node to
see if the token begins a statement and then based on the path adds
possible keyword completion candidates. The test lists some cases where
this approach cannot provide completion candidates.

The biggest thing missing is keywords for file level declarations

Updates golang/go#34009

Change-Id: I9d9c0c1eb88e362613feca66d0eea6b88705b9b0
Reviewed-on: https://go-review.googlesource.com/c/tools/+/196664
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-22 20:49:18 +00:00
Rebecca Stambler
0bb5a05de8 internal/lsp: use the AST to get correct ranges
Fixes golang/go#29150

Change-Id: I0cb8be25f7f40f7f8becedf2e0002c58620c72da
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202542
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-22 16:21:03 +00:00
Ian Cottrell
774d2ec196 internal/lsp: cancel early
This change allows us to hanel cancel messages as they go into the queue, and
cancel messages that are ahead of them in the queue but not being processed yet.
This should reduce the amount of redundant work that we do when we are handling
a cancel storm.

Change-Id: Id1a58991407d75b68d65bacf96350a4dd69d4d2b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200766
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-22 07:49:31 +00:00
Heschi Kreinick
7178990c25 internal/imports: cache module information
To avoid proposing unusable completions, such as those in modules that
need a replace statement to be usable, we need to know what module a
directory is in. That involves walking up the directory tree to find a
go.mod file, which is expensive to do over and over. Really, we just
need to check if the directory we're in has a go.mod file, then use the
parent dir's results.

Add module information to the cache and use it when figuring out what
module a dir is in.

Change-Id: Ia74ba9b37d73fca5e6786a94c73c8fd71b591645
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202541
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-21 22:41:28 +00:00
Rebecca Stambler
3057e18543 internal/lsp: move error range computations into cache package
A continuation of CL 202298, only for analysis errors.

Change-Id: I957d52cef31938ef66be73463e92695a5b56869c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202540
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-21 22:12:58 +00:00
Heschi Kreinick
d2fffb4b84 internal/imports: cache things outside the mod cache
Since a user's module cache is generally going to be much bigger than
their main module, one would expect that caching just information about
the module cache would be sufficient. It turns out that's not correct.
When we discover something in the module cache, we have to make sure
that a different version of it isn't already in scope. Doing that can
require information about the main module or replace targets, so that
needs to be cached too.

Concretely, when I'm working in x/tools, if a scan discovers a version
of x/tools in the module cache, it should usually ignore that version.
But that might not be true in more complicated cases, especially those
involving nested modules whose boundaries change.

So, cache everything except GOROOT. Since the new data is mutable,
we store it separately from the module cache data so that it can be
discarded easily between runs.

Change-Id: I47364f6c0270fee03af8898fec6c85d1b9c8d780
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202045
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-21 20:45:41 +00:00
Heschi Kreinick
eb46839a96 internal/imports: return non-stdlib candidates from GetAllCandidates
Scan most sources, including GOPATH, the module cache, the main module,
and replace targets as appropriate. Use the cached stdlib instead of
scanning GOROOT.

We heavily cache the contents of the module cache, so performance is
decent. But we have to look at all the modules not in the module cache
too to get the right versions of modules (see
(*ModuleResolver).canonicalize), which currently isn't cached at all,
even just for a single run. That ends up being pretty expensive.

The implementation changes are relatively small; add package name
loading to scan(), cache that result, and allow callers to control what
directories are scanned so that it can skip GOROOT.

I also cleared out most of the stdlib from the unimported completion
test and added a simple external completion to it for safety's sake.

Change-Id: Id50fd4703b1126be35a000fe90719e19c3ab84bf
Reviewed-on: https://go-review.googlesource.com/c/tools/+/199178
Run-TryBot: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-21 20:45:15 +00:00
Rebecca Stambler
a0af95a55c internal/lsp: return spanForRange function to fix build
This function was removed in CL 202298, but used in CL 200597.
Analysis diagnostics should be converted to the source.Error type in the
analysis runner as a complete fix, but this is fine for now.

Change-Id: Ie5f3f566719073d7df6ab4646f855c9f9ce22ad7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202539
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Dominik Honnef <dominik@honnef.co>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-21 19:54:44 +00:00
Dominik Honnef
ce0314c87e go/analysis, internal/lsp: add support for related information
This CL adds support for "related information", which allows
associating additional source positions and messages with a
diagnostic.

Change-Id: Ifc0634f68c9f3724b6508dc6331c62c819a24f78
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200597
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-21 19:00:55 +00:00
Rebecca Stambler
747b8b11d4 internal/lsp: refactor error handling code in type-checking
This change adds a source.Error type which is used to collect the error
information that comes out of the loading, parsing, and type checking
stages. We also add specific sources per-error, rather than having them
all be labeled as "LSP".

This change will enable follow-ups that do a better job of extracting
error ranges.

Change-Id: I3fbb5e42d66aa2c5bb1b2f41d1eadfc45f3a749b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202298
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-21 18:57:46 +00:00
Rebecca Stambler
ed542cd5b2 internal/lsp: turn off go/packages debug logging
Change-Id: I810cff76e6920156f959643f0d16d10b595d9708
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202043
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-10-18 21:25:57 +00:00
Rebecca Stambler
a1005cf9b2 internal/lsp: fix race in checkPackageHandles
We were caching the package before setting the handle, so a
checkPackageHandle might be in use before it was fully created.

Change-Id: Ic98e7c351cbed5e4caa87098e95ad04d4f54f8df
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202040
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-18 19:24:35 +00:00
Rebecca Stambler
0bbdbb2ef6 internal/lsp: associate package with its snapshot
A package really should always be associated with its snapshot rather
than its view. This eliminates some extra parameters in a few utility
functions.

Change-Id: I60f9b7286e0072d3268602f6bd32052a3d2e5559
Reviewed-on: https://go-review.googlesource.com/c/tools/+/202039
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-18 19:08:19 +00:00
Ariel Mashraki
1f7a813c0d tools/internal/imports: fix data race in packageInfo
Before this commit, when running imports.Process concurrently, the program
panics with a fatal error due to concurrent map iterations and map writes.

This CL fixes this by adding a copy of the map to the packageInfo structure.

Fixed #34895

Change-Id: If009e6108813f86495c7e20e69739186b8b236d7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200865
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
2019-10-18 18:31:53 +00:00
Muir Manders
920acffc3e internal/lsp: fix bad *ast.ArrayTypes for completion
Currently array and slice literals don't work very well for
completion. When go/parser is not expecting a type, it often turns
array types (e.g. "[]int") into *ast.BadExpr, which messes up
completion because we can't figure out the prefix from *ast.BadExpr,
and *ast.BadExprs don't get type checked.

This change addresses the first problem of not being able to figure
out the prefix. If we see an *ast.BadExpr, we now blindly try to
reparse it as a composite literal by adding on "{}". If we end up with
an *ast.CompositeLit with an *ast.ArrayType "Type", we swap
the *ast.BadExpr for the *ast.ArrayType. This approach is dumb but
simple, and fixes lexical completions in array types.

Change-Id: Ifa42e646bcbf2a30170d73e6dd11982384d40b43
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197437
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-17 20:53:01 +00:00
Rebecca Stambler
de666e9706 internal/lsp: add a test to make sure we handle bad imports
There was a regression where gopls would not type-check any package with
a bad import. This change fixes the regression and adds a test to make
sure it doesn't happen again.

Change-Id: I3acf0917d46e9444c20135559f057f0ecd20e15b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201539
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-17 20:52:05 +00:00
Nathan Dias
e4d7c6f25b internal/telemetry/export/ocagent: convert Histogram metrics
This change adds support for converting HistogramFloat64Data and
HistogramInt64Data to *wire.Metric. Timestamps are not attached
as they are not yet available.

What works:
* convertMetric will now convert HistogramInt64Data and
HistogramFloat64Data to *wire.Metric.

What does not work yet:
* StartTime and EndTime will not be attached to timeseries and
points.
* MetricDescriptors will not have a unit attached.
* No labels will be attached to timeseries.
* Distributions will not have SumOfSquaredDeviation attached.

Updates golang/go#33819

Change-Id: Iee52ab751542ee1ade07ef32120de853b41fd27b
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200538
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2019-10-17 16:38:57 +00:00
Rebecca Stambler
a3bc800455 go/expect: support markers in comments in go/packagestest
This is specifically necessary to test CL 197879.

Change-Id: I2b4bbdd322d52097fc1444242d3e26a3d8ea75e7
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201520
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-17 15:15:54 +00:00
Muir Manders
0abb09c987 internal/lsp: search for deep completions across function calls
We now continue deep completion search across function calls. The
function must take no arguments and return a single argument. For
example, when completing "fo<>" you might get candidates such as
"foo.bar().baz()".

Previously we would stop searching for deep completions when we hit a
function call. For example, we would stop at "foo.bar()", never
finding "foo.bar().baz()". At the time I was worried about the search
scope growing too large, but now that we dynamically limit the search
scope there isn't much left to worry about.

Change-Id: I48772c154400662876682503c1f58ef6e3dca688
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201222
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
2019-10-17 03:50:25 +00:00
Muir Manders
02335f11d5 internal/lsp: don't qualify literal candidates in *ast.SelectorExpr
Previously we unconditionally qualified literal candidate types with
their package. For example:

var buf *bytes.Buffer
buf = &bytes.Bu<>

would complete to:

buf = &bytes.bytes.Buffer{}

Now we don't qualify the type if the cursor position is in the
selector of an *ast.SelectorExpr. We only generate literal candidates
for type names, so if we are in a selector then we can assume it is a
package qualified type (as opposed to an object field).

We also handle the insertion of "&" for literal pointers better. If you are in
the selector of an *ast.SelectorExpr, we prepend the "&" to the beginning of the
expression rather than the selector. For example, you will end up with
"&bytes.Buffer{}" instead of "bytes.&Buffer{}".

Updates golang/go#34872.

Change-Id: I812aa809cd4e649a429853386789f80033412814
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201200
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-16 23:29:27 +00:00
Muir Manders
5bac78f585 internal/lsp: add label completion candidates
Now we offer completion candidates for labels when completing "break",
"continue", and "goto" statements. We are reasonably smart about
filtering unusable labels, except we don't filter "goto" candidates
that jump across variable definitions.

Fixes golang/go#33987.

Change-Id: If296a7579845aba5d86c7050ab195c35d4b147ed
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197417
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-16 23:06:01 +00:00
Rebecca Stambler
f6a1a6ff8e internal/lsp: check if the go/packages context has been canceled
Recently been noticing errors where we don't have full metadata for a
given package. It seems to me that, since we added the context to the
packages.Config, there have been cases where the context is canceled on
the first load, and then we type-check with incomplete data. I'm still
not sure if allowing go/packages to be canceled is the correct approach.

Change-Id: I6767ce763538bd579458c8f8db07f15c9eec7b4a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201518
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Muir Manders <muir@mnd.rs>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-10-16 22:21:47 +00:00
Rebecca Stambler
f0068bd333 internal/lsp: remove misleading check span
This span resulted in misleading information, since it would appear any
time you called the Check function. This function often returns cached
results, so it's not particularly useful.

Change-Id: I26be652a99b906fb2e8703ff9af86fbe2ef5fc5d
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201219
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2019-10-16 19:48:01 +00:00
Pontus Leitzler
6223712555 internal/lsp: fix lsp trace log format for gopls
The -rpc.trace flag in gopls enables logging in "lsp inspector format".
Currently sent responses isn't parsed by the lsp inspector so it fails to
parse gopls logs.

The lsp inspector regexp matcher requires the duration to be prefixed with
"took" instead of "in", e.g. "took <d>ms.".

This change updates gopls to match the log parser in lsp inspector,
see 9aff7a6939/lsp-inspector/src/logParser/rawLogParser.ts (L88)

Change-Id: I3696faf34ba4f0b3d4e205693eaf378941f2f68f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/199517
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2019-10-16 17:14:07 +00:00
Rebecca Stambler
9c6d90b5a7 internal/lsp: use the analyzer's pointer instead of name
Analyzer names are not guaranteed to be unique.

Change-Id: I4d4cc9fa746cbfbea9926f2cae0eb5dfc41027a5
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201217
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-10-15 21:12:01 +00:00
Rebecca Stambler
f936694f27 internal/lsp: add analyses to the snapshot
This change makes sure that actionHandles are cached within the
snapshot, to minimize the cost of re-computing action handles on each
run of go/analysis.

Change-Id: If6191c5224285eb207aebb997787ea551a47fbaa
Reviewed-on: https://go-review.googlesource.com/c/tools/+/201098
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
2019-10-15 15:04:14 +00:00
Rebecca Stambler
b53505e708 internal/lsp: cache analysis using memoize package
This change moves to the approach of caching the analysis using the
memoize package. This means that we will do less work, as we no longer
need to recompute results that are unchanged. The cache key for an
analysis is simply the key of the CheckPackageHandle, along with the
name of the analyzer.

Change-Id: I0e589ccf088ff1de5670401b7207ffa77a254ceb
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200817
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
2019-10-14 17:19:42 +00:00
Peter Weinberger
8de300cfc2 internal/lsp/protocol: handle case of an otherwise empty notification
Some notifications, like exit, have no other arguments, a case the code
was not handling correctly.

Change-Id: Ib5ff536352ba6ad0d09cd80c9d5f0a987abbe500
Reviewed-on: https://go-review.googlesource.com/c/tools/+/200298
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Peter Weinberger <pjw@google.com>
2019-10-12 15:20:04 +00:00