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>
This CL only copies files and updates build tags.
Substantive changes will come in follow-ups.
This is a workaround for git's lack of rename/copy tracking.
Tested with go1.6, go1.7, and tip (go1.8).
Change-Id: Id88a05273fb963586b228d5e5dfacab32133a960
Reviewed-on: https://go-review.googlesource.com/32630
Reviewed-by: Robert Griesemer <gri@golang.org>
Most objects are declared by an identifier, so the end position is
start+len(name). However, this heuristic doesn't work for PkgName
objects because a (non-renaming) import creates an object without an
identifier.
Fixes issue github.com/Microsoft/vscode-go#562
Change-Id: I0eb44ca33a643c910d97abbf700ea4c3cd23bb41
Reviewed-on: https://go-review.googlesource.com/32440
Reviewed-by: Robert Griesemer <gri@golang.org>
Supporting user-defined TestMain functions requires that we generate a
"testmain" package for each testable package, rather than a single one
for the entire program. This entails these API changes:
1. (*ssa.Program).{CreateTestMainPackage,FindTests} both now
accept only a single package. Existing clients that pass them
multiple packages must call them from a loop.
2. (*ssa.Program).FindTests returns an additional result, the the
optional TestMain *ssa.Function. Existing clients may discard it.
Also:
- Test the new logic using the SSA interpreter
- add ssautil.MainPackages helper
- callgraph: allow multiple main packages, and analyze them all
- ssadump -run: allow multiple main/test packages, and run each in a new interpreter
- minor simplifications to some callers (e.g. guru)
Fixesgolang/go#9553
Change-Id: Ia7de9bd27448fb08b8d172ba5cdbcf37a762b7a0
Reviewed-on: https://go-review.googlesource.com/25102
Reviewed-by: Robert Griesemer <gri@golang.org>
This package requires cl-lib.el in package header but it is not loaded
and cl.el functions are used instead of cl-lib functions. Using cl.el
functions causes byte-compile warnings.
Change-Id: I6d9400f9ced6a5cc0592d83da2ab1c1cf34e20b8
Reviewed-on: https://go-review.googlesource.com/27031
Reviewed-by: Alan Donovan <adonovan@google.com>
This allows type-based guru queries to work on arbitrary files at the
root or even outside of a GOPATH workspace (as "go run foo.go" does).
Fixesgolang/go#15797
Change-Id: I2be28f7259448e6398aae84d6ae7e71d8649967a
Reviewed-on: https://go-review.googlesource.com/30451
Reviewed-by: Robert Griesemer <gri@golang.org>
The test expectation includes the text of a UNIX ENOENT message.
Also, make the same change for (deprecated) oracle tool.
Fixesgolang/go#16397
Change-Id: I8c3c6a300ff2366bfeb97cf41d34097c41aab680
Reviewed-on: https://go-review.googlesource.com/24968
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
I was going to add a hook to enable go-guru-hl-identifier-mode
as a side effect of go-mode, but a person I consulted said that
was bad form; instead I merely documented it.
Change-Id: I48b00b71c7ba485b3d632211923509a74281acbe
Reviewed-on: https://go-review.googlesource.com/24834
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
combine-and-quote-strings is buggy. The value of this expression:
(split-string-and-unquote (combine-and-quote-strings '("a" "" "b")))
is ("a" "b"). Consequently, if go-guru-scope is "", the following
"-tags" flag is interpreted as the scope.
Change-Id: I2955ffa2b95914e01d44b52690e810f816076d5c
Reviewed-on: https://go-review.googlesource.com/24746
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Alan Donovan <adonovan@google.com>
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>
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>
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>
...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>
We define a derived mode of compilation-mode, so that various
names say "guru" instead of "compilation", and use the hooks it
provides to apply our postprocessing incrementally instead of
all at the end. It's much faster, and works nicely with the
new streaming referrers query.
Compilation mode requires a shell command, not an execve array,
so go-guru--compile-command joins the arguments with spaces.
go-guru--exec has been specialized for JSON mode,
and renamed to go-guru--json.
go-guru--set-scope-if-empty is now done by each mode, to avoid
the NEED-SCOPE parameter to go-guru--exec.
Change-Id: I692b8b28449b7cc17fd6251a152588f9d8b89ebc
Reviewed-on: https://go-review.googlesource.com/21772
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Alan Donovan <adonovan@google.com>
strings.Split is not your friend.
Change-Id: I829f08f113f3340b2dd865aea47f5759a427f7c4
Reviewed-on: https://go-review.googlesource.com/22116
Reviewed-by: Michael Matloob <matloob@golang.org>
Keep the leftmost element when removing duplicates, so that we report
"function call" instead of "expression statement".
Also split go-guru--enclosing into two functions.
Change-Id: Ie325613e292e36dda9558eda54bc7323fbf0bc6d
Reviewed-on: https://go-review.googlesource.com/22132
Reviewed-by: Alan Donovan <adonovan@google.com>
This extracts the overlay context and archive parsing from guru into
buildutil.
At least one tool (gogetdoc) has a vendored copy of this code already,
and more tools implementing the same functionality will follow.
The new code in buildutil is an almost identical copy of the code in
guru (names aside), except for the following changes:
- Instead of reading into a bytes.Buffer, we read directly into a []byte
of appropriate size
- sameFile first attempts a simple comparison of path.Clean'ed paths.
Change-Id: I97cd978ccc10722e3648e5e10625fa7f1407f202
Reviewed-on: https://go-review.googlesource.com/21805
Reviewed-by: Alan Donovan <adonovan@google.com>
The go-guru-expand-region function uses the "what" query to determine
the enclosing regions. Consecutive calls to go-guru-expand-region will
reuse a cached version of the list.
Change-Id: Ice9ac5540c1b639c6cbdc505866bbab347be1e98
Reviewed-on: https://go-review.googlesource.com/21754
Reviewed-by: Alan Donovan <adonovan@google.com>
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>
We cannot determine the extension of buffers with no file names (not
without throwing an error, anyway.)
Change-Id: I2b10390da738d71b6f95a6f668d3b92b54db29ed
Reviewed-on: https://go-review.googlesource.com/20470
Reviewed-by: Alan Donovan <adonovan@google.com>
That way, running guru on /a/foo.go, followed by /b/bar.go won't leave
the user with a display buffer that still defaults to /a/
Change-Id: I3f9b085c6d206ac2adc269fc2009799c624c371a
Reviewed-on: https://go-review.googlesource.com/20475
Reviewed-by: Alan Donovan <adonovan@google.com>
Now that we have both interactive and non-interactive uses of the guru,
we should separate the command output buffer from the display buffer.
Change-Id: I50082fdc3847c7b12869e204509141e906df3852
Reviewed-on: https://go-review.googlesource.com/20473
Reviewed-by: Alan Donovan <adonovan@google.com>
By using guru's -modified flag and making up a file name, we can run
guru on a buffer that has no file attached to it. This feature will only
be useful for queries that operate on single files, as otherwise our made
up name could cause conflicts.
This will be useful for the "what" query and features using it.
Change-Id: I3d199bc0548245d59ba7b492f57beb9422d7f43d
Reviewed-on: https://go-review.googlesource.com/20431
Reviewed-by: Alan Donovan <adonovan@google.com>
This fixes some print calls with wrong format directives. Additionally,
struct initialisers were changed to use keyed fields, purely to reduce
the amount of noise generated by go vet.
Change-Id: Ib9f6fd8f2dff7ce84826478de0ba83dda9746270
Reviewed-on: https://go-review.googlesource.com/21180
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Implement the "what" query and use it to get all uses of an
identifier (the "sameids" attribute). The user can either manually call
go-guru-hl-identifier, which will highlight all instances of the
identifier under point, or they can enable the
go-guru-hl-identifier-mode minor mode. The minor mode sets up an idle
timer, which will highlight the current identifier after a configurable
timeout. If the user modifies the buffer, or moves point off of an
identifier, we clear the highlight.
Change-Id: Iac870f3bcd17e0002eafcba0b73f07adaa03cd76
Reviewed-on: https://go-review.googlesource.com/20433
Reviewed-by: Alan Donovan <adonovan@google.com>
In go1.5, go/constant (floating-point) numeric values are printed
as fractions. Correct output as necessary so that they always
appear as floating-point numbers to match golden files.
Change-Id: If63a14d8d87bb664bf6272b16345e38e8d638ead
Reviewed-on: https://go-review.googlesource.com/20719
Reviewed-by: Alan Donovan <adonovan@google.com>
Also fix a typo in the tool's help string.
Change-Id: I54a9ed4a5515b137b0fbf1b2391dd6fa84b2d2d8
Reviewed-on: https://go-review.googlesource.com/20474
Reviewed-by: Alan Donovan <adonovan@google.com>
Bind go-guru-whicherrs to `C-C C-o e'
Also remove go-guru-callgraph as callgraph mode is not supported
by guru.
Change-Id: Id233d178629a3cafc00e4f9640191c3d3c673cf1
Reviewed-on: https://go-review.googlesource.com/20310
Reviewed-by: Alan Donovan <adonovan@google.com>
This allows users to swap point and mark to jump between use and
definition in the same buffer, or pop-tag-mark (M-*) to jump back to the
use even between multiple buffers.
This mirrors the behaviour of godef-jump from go-mode.
Also remove an obosolete TODO and fix a typo.
Change-Id: I614090493b565acadf359ebb4c7092f4c673fd56
Reviewed-on: https://go-review.googlesource.com/20303
Reviewed-by: Alan Donovan <adonovan@google.com>
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>
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>
This fixes a bug in which guru reports a "query position beyond end of
file" error when making a query from an unsaved editor buffer at an
offset greater than the length of the file on disk.
Change-Id: I908c024d8dd14baa657b4227e3231fa760443732
Reviewed-on: https://go-review.googlesource.com/20167
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
Make go-guru compatible with package.el prior to uploading this pacakge to
MELPA.
Also add ;;;###autoload magic comments, so that the go-guru-xxx commands can
be used without need to explicitly (require 'go-guru) first.
Change-Id: I21c7f5f354fb7b39877a05c2a9ffecd02ab022f6
Reviewed-on: https://go-review.googlesource.com/19789
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Alan Donovan <adonovan@google.com>
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>