If godoc didn't come up quickly enough, we would leave it running and
then try to start another one on the same port.
The new one would fail to start, being unable to bind to the address,
causing cascading failures.
Also increase the timeout to 10 minutes.
Change-Id: I7008a39f649021ea213902d557f26bf78567026d
Reviewed-on: https://go-review.googlesource.com/20420
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
The error message is attempting to display the line of text, but was
incorrectly using m (which is always nil) instead of line.
Change-Id: Id09f488b3b7b0e8c3c2cb6e8f0a8d635861c77ac
Reviewed-on: https://go-review.googlesource.com/19330
Reviewed-by: Ian Lance Taylor <iant@golang.org>
The BuilderModeFlag function does not work with flag packages (such as
Google's) that define their own FlagSet. This change exposes a type
that satisifies flag.Value insted of a function. That type
is *BuilderMode; there's no need for a separate wrapper type.
Change-Id: I8095b80de499e3c52a29a5c1996d1b1fe3799358
Reviewed-on: https://go-review.googlesource.com/20330
Reviewed-by: Michael Matloob <matloob@golang.org>
Line numbers match line numbers from the included file,
not the lines in the segment selected by the
.code or .play START/STOP regexps.
Fixesgolang/go#5248
Change-Id: I374e7b665e98db5032446ae49e6fae00d9d2b975
Reviewed-on: https://go-review.googlesource.com/20311
Reviewed-by: Andrew Gerrand <adg@golang.org>
Fix by removing jQuery usage from slides.js as jquery.js is only
available when play.js is included.
Fixesgolang/go#9878
Change-Id: I5793350105b138d7b7645f11d814e1d2f573a73e
Reviewed-on: https://go-review.googlesource.com/20288
Reviewed-by: Andrew Gerrand <adg@golang.org>
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>
+ test
Change-Id: I8db03e19ebb4cf3888f259457aaa3c931da23f24
Reviewed-on: https://go-review.googlesource.com/20109
Reviewed-by: Robert Griesemer <gri@golang.org>
Use time.After to avoid the finnicky antics of
correctly resetting a time.Timer.
Fixesgolang/go#13749
Change-Id: I3f1ed17a31d981996e2bb7a8155c3ba0ec723c7d
Reviewed-on: https://go-review.googlesource.com/19942
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
DeleteNamedImport deletes the import with a given
name and path from a parsed file, if present.
imports uses this function to delete named imports.
Fixesgolang/go#8149.
Change-Id: I84539d5627191c45f06db2d008507aee4d3b1eb2
Reviewed-on: https://go-review.googlesource.com/19951
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
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>
This will be used by the guru command's -scope argument.
+ test
Change-Id: I5bf38b544809e4518e2c22a73ec3349a5d2c09fc
Reviewed-on: https://go-review.googlesource.com/19746
Reviewed-by: Michael Matloob <matloob@golang.org>
This fixes the following usability issues:
- when go-guru is called twice in a row and the output from the second invocation
is bigger then this output is not fully visible
- output window could be re-used by other packages (such as helm) that are not
usable with the shrank window
Change-Id: I86d522006d29e945a71b96c9d13a1a39572bdb3b
Reviewed-on: https://go-review.googlesource.com/19780
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Alan Donovan <adonovan@google.com>
Major modes should use the C-c prefix followed by C-something. We'll
stick with C-o (oracle) since C-g is taken by go-jump-xxx (and in any
case C-g should be reserved for keyboard-quit.)
Change-Id: I18f41d7cbd5bf83aa53909554501e7f76543f033
Reviewed-on: https://go-review.googlesource.com/19510
Reviewed-by: Michael Matloob <matloob@golang.org>
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>
Editor modes that invoke the goimports command on temporary copies
of actual source files will need to invoke goimports -srcdir now to say
where the real source directory is. Otherwise goimports will not consider
vendored or internal packages when looking for new imports.
In lieu of a test for cmd/goimports (because it has no tests),
a command transcript:
$ cd /tmp
$ cat x.go
package p
var _ = hpack.HuffmanDecode
$
$ GOPATH= goimports < x.go
package p
var _ = hpack.HuffmanDecode
$ GOPATH= goimports x.go
package p
var _ = hpack.HuffmanDecode
$
But with the new flag:
$ GOPATH= goimports -srcdir $GOROOT/src/math < x.go
package p
import "golang.org/x/net/http2/hpack"
var _ = hpack.HuffmanDecode
$ GOPATH= goimports -srcdir $GOROOT/src/math x.go
package p
import "golang.org/x/net/http2/hpack"
var _ = hpack.HuffmanDecode
$
The tests in this CL and the above transcript assume that
$GOROOT/src/vendor/golang.org/x/net/http2/hpack exists.
It did in 40a26c9, but it does not today.
It will again soon (once Go 1.7 opens).
For golang/go#12278 (original request).
Change-Id: I27b136041f54edcde4bf474215b48ebb0417f34d
Reviewed-on: https://go-review.googlesource.com/17728
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Before, "bundle -help" printed only one not particularly useful line:
Usage of bundle:
and "bundle" printed a bit more but not a standard usage message:
bundle: Usage: bundle package dest prefix
Arguments:
package is the import path of the package to concatenate.
dest is the import path of the package in which the resulting file will reside.
prefix is the string to attach to all renamed identifiers.
And most of that output belonged in (but was missing from) the doc comment,
which leaned heavily on the reader inferring usage from one example.
While fixing all this, I ended up dropping "dest" and "prefix" as required
arguments: perfectly good defaults can be inferred in the common case
where the bundle is intended for the current directory. The defaults can be
overridden with the new -dst and -prefix option.
I corrected a TODO about not assuming the package name could be
derived from the destination import path. Like -dst and -prefix, the
default package name can be inferred from the current directory,
but there is also a new -pkg option to override the default if needed.
I added a -o option to specify the destination output file (standard output
is still the default output). One benefit of -o is that it makes the bundle
commands self-contained in the sense of not needing a shell.
That in turn makes them suitable for use with "go generate", so when -o
is specified the bundle output now includes a "//go:generate" comment
for updating the bundle mechanically.
To keep bundle working for net/http's use case, I added a -importmap
option to specify additional import rewrites (net/http needs the http2
import of golang.org/x/net/http2/hpack rewritten to begin with internal/golang.org).
The net effect of all of this is that the first two lines at the top of
net/http/h2_bundle.go will change from:
// Code generated by golang.org/x/tools/cmd/bundle command:
// $ bundle golang.org/x/net/http2 net/http http2
to
// Code generated by golang.org/x/tools/cmd/bundle.
//go:generate bundle -o h2_bundle.go -prefix http2 -import golang.org/x/net/http2/hpack=internal/golang.org/x/net/http2/hpack golang.org/x/net/http2
and net/http's copy of http2 can now be updated by "go generate"
instead of by copying and pasting commands from source code to shell.
For an experiment I am doing with cmd/dist bundling archive/zip,
the header is even shorter and makes a better demonstration of the
power of the defaults:
// Code generated by golang.org/x/tools/cmd/bundle.
//go:generate bundle -o zip.go archive/zip
New usage message, printed by "bundle -help" and "bundle":
Usage: bundle [options] <src>
-dst path
set destination import path (default taken from current directory)
-import map
rewrite import using map, of form old=new (can be repeated)
-o file
write output to file (default standard output)
-pkg name
set destination package name (default taken from current directory)
-prefix p
set bundled identifier prefix to p (default source package name + "_")
See CL for new doc comment.
Following this CL I will send a CL updating the two-line header in net/http/h2_bundle.go
to match the new usage of the bundle, whatever that ends up being.
Change-Id: I83a65b6a500897854027cefdefb8f62f1d4448b4
Reviewed-on: https://go-review.googlesource.com/19428
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
I think this resulted from git automerging.
Change-Id: Icc285601846bd0a2a2bb2316ae4575395744c44b
Reviewed-on: https://go-review.googlesource.com/19511
Reviewed-by: Alan Donovan <adonovan@google.com>
The parser does intra-file resolution. It's only a best-effort but
it's extremely fast, so we try it first and fall back to the loader-based
implementation if it fails.
Also:
- factor definitionResult so it doesn't depend on either go/types.Object
or go/ast.Object.
- guessImportPath: make importPath=="" result an error,
since you can't import the empty string. Simplify importQueryPackage.
- Make fastQueryPos continue in face of minor parse errors.
- describe: eliminate old TODO; suppress log statement.
Change-Id: I30a32487e9fd9d5308b1580ec12220cad2c16299
Reviewed-on: https://go-review.googlesource.com/19507
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
These nodes are common in incomplete programs.
Change-Id: Iff9750050c78762f0cb8bebc7739584c197d661e
Reviewed-on: https://go-review.googlesource.com/19509
Reviewed-by: Michael Matloob <matloob@golang.org>
Don't just display the output buffer or, worse, parse it as JSON.
Change-Id: I1125ff235a5073b07f45f587ef8844b8a12f05ac
Reviewed-on: https://go-review.googlesource.com/19508
Reviewed-by: Michael Matloob <matloob@golang.org>
go-guru--run has been split up to separate running the tool
from turning its output into compilation-mode form.
The definition command uses only the first part,
and parses its output in JSON form.
Added test, factoring the test script.
Change-Id: I4c3e4a51a1346551a3703a5e3137c878d7b2d95f
Reviewed-on: https://go-review.googlesource.com/19499
Reviewed-by: Michael Matloob <matloob@golang.org>
The -modified flag causes guru to read a simple archive file from stdin.
This archive specifies alternative contents for one or more file names.
The build.Context checks this table before delegating to the usual
behavior.
This will not work for files that import "C" since cgo accesses the
file system directly.
Added end-to-end test via Emacs.
Simplify findQueryPos (now: fileOffsetToPos)
Credit: Daniel Morsing, for the prototype of this feature.
Change-Id: I5ae818ed5e8bb81001781893dded2d085e9cf8d6
Reviewed-on: https://go-review.googlesource.com/19498
Reviewed-by: Daniel Morsing <daniel.morsing@gmail.com>
When a file is not found, it's common to return an error that can
be detected with os.IsNotExist helper. It's possible to use
os.PathError type to satisfy that requirement while still providing
the path information in the error.
Add a test that files that are not found return a non-nil error, and
that the error satisfies os.IsNotFound.
Change-Id: I5f1a26b18f2556af822ede73306541e8575ede28
Reviewed-on: https://go-review.googlesource.com/19503
Reviewed-by: Andrew Gerrand <adg@golang.org>
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>
As an optimization, the callers and callstack queries now avoid the
relatively costly pointer analysis in some common cases:
The callers of a function that is never address-taken can be enumerated
directly from the SSA representation.
Similarly, the callstack can be computed initially by ignoring dynamic
call edges; we run the pointer analysis only if no path is found in this
partial callgraph. As a bonus, this also causes the tool to
preferentially report all-static callpaths.
A callers query on fmt.Errorf now completes in 3 seconds instead of 8,
and a callstack query completes in 2 seconds instead of 8.
The new code is covered by the existing tests.
Change-Id: I777ea07a1cdb6cadcc2a94952f553b6b036e7382
Reviewed-on: https://go-review.googlesource.com/19496
Reviewed-by: Michael Matloob <matloob@golang.org>
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>
-pos is now a positional argument; -scope is now a flag.
Tidy up usage message.
Update Vim and Emacs scripts and test
Remove call to GOMAXPROCS.
Use log.{SetPrefix,SetFlags} and Fatalf
Change-Id: I3786ed83aecb17d622b29d2a538a374f813f0adc
Reviewed-on: https://go-review.googlesource.com/19438
Reviewed-by: Michael Matloob <matloob@golang.org>