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

26 Commits

Author SHA1 Message Date
Alan Donovan
7fdb908ead cmd/guru: fix tests now that go1.9 go/types returns fake packages
The go1.9 type checker now returns fake packages in addition to an
error if the package was not found at all.  This changes the behavior
of guru in a release-specific way, requiring the test to be split into
a common part and a go1.9-specific part.

In hindsight, perhaps it would have been better to place the
expectation in a comment alongside the query so that they can be
easily enabled or disabled together.  (The downside of that design is
that you can't batch-update all the expectations to match the actual
behavior.)

Change-Id: I58054adec428fbab7fe3c57097aefc827f89a46e
Reviewed-on: https://go-review.googlesource.com/37865
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-03-08 23:16:52 +00:00
David R. Jenni
8ffd8eda92 x/tools/cmd/guru: fix golden files for what query
CL golang.org/cl/37349 broke the tests, because the
golden files were not updated appropriately.

Change-Id: I9a2a56d1ca74b8bc77935aff26ed6297fbacf232
Reviewed-on: https://go-review.googlesource.com/37770
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Run-TryBot: Dominik Honnef <dominik@honnef.co>
2017-03-04 20:46:07 +00:00
David R. Jenni
718875e4f9 x/tools: simplify and format code
Semi-mechanical changes using gofmt -s
and honnef.co/go/tools/cmd/gosimple.

Change-Id: I41bcf4bea5b16c4776b7cf6534b76aa59b3c022d
Reviewed-on: https://go-review.googlesource.com/37447
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-02-28 14:15:42 +00:00
Alan Donovan
6e7ee5a9ec x/tools: support Go 1.9 type aliases
For #18130.

Change-Id: Ice695602619dbbf851af970e790f07ff2ac2c141
Reviewed-on: https://go-review.googlesource.com/36623
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-02-13 21:46:59 +00:00
Rebecca Stambler
e64f1a4c63 cmd/guru: add workaround to handle inconsistency between go/types and gc
Add identical workaround from gorename to guru. Only affects queries
that typecheck the code first.

Fixes golang/go#16530

Change-Id: I718cfceb8d26868eea9128c8873b164333c50f53
Reviewed-on: https://go-review.googlesource.com/33359
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-11-23 20:09:00 +00:00
Alan Donovan
0e041570eb cmd/guru: revert support for Go 1.8 aliases
Change-Id: I8ba368d5036be47b6d64e3576f366eb0301d2d5b
Reviewed-on: https://go-review.googlesource.com/32831
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-04 21:18:07 +00:00
Alan Donovan
d15da3015c cmd/guru: describe Go 1.8 aliases
Also:
- always display the value of a constant expr, whether query expr is a
  definition, a reference, or an alias.
- eliminate some go1.5 portability code.
- remove go1.8 fork of referrers; no changes are necessary
  since I decided not to treat aliases specially.
- add tests.

Tested with Go 1.6, Go 1.7, and tip (Go 1.8).

Change-Id: I94624cff82f4d8c0dcbf12d11c8ce16e8168a7fe
Reviewed-on: https://go-review.googlesource.com/32730
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-11-03 21:55:02 +00:00
David R. Jenni
6e2a0ce36e cmd/guru: show correct definition for embedded type.
Fixes golang/go#16263.

Change-Id: I081a12306ac5415d2223e3509a29a1b47700e1ff
Reviewed-on: https://go-review.googlesource.com/27001
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-08-24 12:03:13 +00:00
Alan Donovan
ef6b6ebf3b cmd/guru: what: include imported package names in sameids
+ Test.

Change-Id: Ib7ef99786f5b60bb3e56ced9588d2ba5725576e1
Reviewed-on: https://go-review.googlesource.com/24949
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-07-15 18:55:24 +00:00
Alan Donovan
0d2bde8553 go/ast/astutil: describe fewer CallExprs as "conversions"
Only unary CallExprs with no ellipsis, f(x), are ambiguous.

Change-Id: If4f17445ab0725dee916992db133eac5536133a7
Reviewed-on: https://go-review.googlesource.com/24552
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-06-30 18:40:56 +00:00
Alan Donovan
14480f21a0 cmd/guru: for determinism, sort referrers output in test
Previously we were sorting only JSON objects, but we must do the same
for plain output too to avoid sporadic failures.

Tested 20 times.

Change-Id: Ic60363b720c2afc91b57864bc93e298f83e85b99
Reviewed-on: https://go-review.googlesource.com/22555
Reviewed-by: Robert Griesemer <gri@golang.org>
2016-04-28 19:07:35 +00:00
Alan Donovan
50ff896a1c cmd/guru: definition: opt: avoid type checker for qualified identifiers
For a 'definition' query on X in p.X, use special logic to load and
parse package p and find the declaration of package member X, without
using the type checker.  Such queries now typically take under
10ms (faster than godef).

The logic assumes that import "something/p" defines the name p.  If this
assumption is false, p.X could be a selection of a field or method X on
a member p of the same package, defined in another file.
So don't write code like that.

Added missing test of 'definitions'.
JSON tests now sanitize absolute $GOPATH filenames in the output.

Fixes issue #15458

Change-Id: I21e75fcc9372aaedd56851cace444aef205c7a97
Reviewed-on: https://go-review.googlesource.com/22526
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-04-28 17:00:30 +00:00
Alan Donovan
0f5f9fcf9a cmd/guru: implements: if selected expr is a value, use its type
...as the basis of the query, instead of reporting an error.

+ test

Change-Id: Ie5defa98cd8dfc8e200e296c2aa02c88893cf9ac
Reviewed-on: https://go-review.googlesource.com/22117
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-04-28 14:33:14 +00:00
Alan Donovan
2da0720e4f cmd/guru: support streaming plain and -json output
Visible changes:
- "referrers" queries now emit a stream of results,
  so they start appearing quickly even in large queries.
  We no longer report the total number of matches.
- packageReferrers now also uses AfterTypeCheck hook and streaming.
- XML support has been dropped.
- The -format flag has been replaced by -json.

JSON protocol changes:
- The enclosing Result struct has been removed.
- Likewise the 'mode' field (since the caller knows it already)
- "freevars" and "referrers" now emit a stream of objects
  In the case of referrers, the first object has a different from the rest.
- The "referrers" results include the text of the matching line
  (parity with -json=false)

Implementation details:
- the concurrency-safe q.Output function can be called
  many times, each with a queryResult to print.
- fset is no longer saved in Query (cleaner)
- queryResult methods renamed PrintPlain, JSON

Change-Id: I41a4e3f57f266fcf043ece4045bca82c6f6a356f
Reviewed-on: https://go-review.googlesource.com/21397
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-04-11 19:51:55 +00:00
Alan Donovan
35cacb533e cmd/guru: change "Method set:" to less formal "Methods:"
Change-Id: I7a43f3e9ed7e88f4f8f09d4d112c81aa037b7d8d
Reviewed-on: https://go-review.googlesource.com/21111
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-03-28 14:29:15 +00:00
Dominik Honnef
47218d24f2 cmd/guru: whicherrs: don't crash on dead code
Change-Id: I5e80613ec27a4edb45516ff1ff3a88d5f9cb3a67
Reviewed-on: https://go-review.googlesource.com/21130
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-03-25 16:35:34 +00:00
Alan Donovan
d2abdd5413 cmd/guru: fix nil deref when position is not in Go source
+ test

Fixes issue golang/go#14684

Change-Id: I56023bf36c307d02c71b4ddf08aee9c229fc66c1
Reviewed-on: https://go-review.googlesource.com/20247
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-03-07 15:53:42 +00:00
Alan Donovan
2336c53cf0 cmd/guru: compute referrers as packages are type checked
This CL makes little observable difference to the behavior but paves the
way for streaming 'referrers' and (later) 'implements' queries which
scan the entire workspace, but print each result as soon as it is found.

The go/loader package now exposes a hook, AfterTypeCheck, that lets
clients inspect each package as soon as it is type-checked, and also
modify it, for instance to release unneeded data structures.

A 'referrers' query applied to an exported object must scan the entire
workspace.  It uses this hook so to gather uses of the query object in
streaming fashion.  However, for now, it still accumulates the results
and prints them all at the end, though I propose to change that in a
follow-up.

Code details:
- The referrers logic had a 2-iteration loop to load first the query
  package and then if necessary the enlarged program.  The second
  iteration has now been unrolled and split into globalReferrers.
- Queries for package names (whether in a package declaration or
  a qualified identifier) have been split off into packageReferrers.
  It now loads all direct importers of the query package,
  which catches some references that were missing before.
  (It used to inspect only the forward dependencies of the query
  package.)

Also:
- Referrers.Pos (the position of query identifier) was removed from the
  JSON output.  It's a nuisance to compute now, and it's already
  absent from the plain output.
  (In a follow-up, I plan to simplify the information content of the
  JSON output exactly what is currently printed in the plain output.)

Change-Id: Ia5677636dc7b0fe4461a5d393107665757fb9a97
Reviewed-on: https://go-review.googlesource.com/19794
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-03-04 21:13:08 +00:00
Alan Donovan
3dafbd1ba4 go/types/typeutil: make IntuitiveMethodSet(*C) nonempty for concrete types C
This fixes a bug in guru describe.

Also, add a test of IntuitiveMethodSet.

Change-Id: Ied3780807afd88e664fdb186619499670529fe33
Reviewed-on: https://go-review.googlesource.com/20166
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
2016-03-03 19:43:35 +00:00
Alan Donovan
6f233b96df cmd/guru: fix nil dereference in describe
+ test

Fixes issue golang/go#14579

Change-Id: I6fd56f10c170027f06917935ccbc28490d413d8a
Reviewed-on: https://go-review.googlesource.com/20100
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-03-01 22:59:02 +00:00
Alan Donovan
2327a65811 cmd/guru: fix tests
A consequence of CL 19747 was that ad hoc packages of a single filename
are no longer valid -scope arguments, which broke most of the tests.

This CL fixes the tests by extracting the import path from the filename.
The test output now includes the import path, not the package
name, of each of these packages, so the output was updated too.

Also, the -scope argument caused the main package to be imported twice,
once as main.go and once under its import path, causing duplicate
'implements' results.

I'm not sure how I failed to notice this.

Change-Id: I6fb3ae3e1497f0eb8cf88f453660b9e2fd9718d8
Reviewed-on: https://go-review.googlesource.com/19886
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-25 22:51:33 +00:00
Alan Donovan
ee8cb08bfe cmd/guru: what: report identifiers equivalent to the selected one
This information is useful for editor UIs that highlight all
uses of the local variable under the cursor.

Change-Id: I718d648d407468509e6d12f932ae6cdef368830a
Reviewed-on: https://go-review.googlesource.com/19512
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-20 21:18:35 +00:00
Alan Donovan
93ea01aea0 cmd/guru: describe: show methods and fields of an expression
Previously you had to describe a type to get this information,
which required two queries, and the need for this query is
extremely common.

Change-Id: I1d1d5b45fead60ca8719ddc302eee47d9f10a375
Reviewed-on: https://go-review.googlesource.com/19501
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-15 03:46:17 +00:00
Alan Donovan
8da9f8bbd7 cmd/guru: describe: show selectable fields when describing a type
Also, qualify field and method types relative to the defining package,
not the query package.

Change-Id: If65d2a4c2fd60e51d0d34e44000954e95106972e
Reviewed-on: https://go-review.googlesource.com/19495
Reviewed-by: Michael Matloob <matloob@golang.org>
2016-02-12 23:35:49 +00:00
Alan Donovan
789265387f cmd/guru: freevars: reenable test of labels (and improve output)
Change-Id: Icb7747d0856a4be2de52e143b793b52a725d297c
Reviewed-on: https://go-review.googlesource.com/19437
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-02-12 03:59:51 +00:00
Alan Donovan
7347379304 cmd/guru: rename oracle to guru, copying it to a single package
See plans at:
https://docs.google.com/document/d/1UErU12vR7jTedYvKHVNRzGPmXqdMASZ6PfE7B-p6sIg/edit#heading=h.t5rbcuy7di7j

Change-Id: I369747e0ce8cd42a2975eb0f651a2e5fba47cf9e
Reviewed-on: https://go-review.googlesource.com/19475
Reviewed-by: Alan Donovan <adonovan@google.com>
2016-02-12 03:38:58 +00:00