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

11 Commits

Author SHA1 Message Date
Rob Pike
8401b19e7e cmd/doc: fix handling of paths like ./fmt
An error in string slice offsets caused the loop to run forever if the
first character in the argument was a period.

Fixes #10833.

Change-Id: Iefb6aac5cff8864fe93d08e2600cb07d82c6f6df
Reviewed-on: https://go-review.googlesource.com/10285
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-20 20:53:14 +00:00
Rob Pike
6f7b4e8938 cmd/doc: put blank lines around comment for types, etc.
Better layout.

Fixes #10859.

The issue suggests rearranging so the comment comes out
after the methods. I tried this and it looks good but it is less
useful, since the stuff you're probably looking for - the methods
- are scrolled away by the comment. The most important
information should be last because that leaves it on your
screen after the print if the output is long.

Change-Id: I560f992601ccbe2293c347fa1b1018a3f5346c82
Reviewed-on: https://go-review.googlesource.com/10160
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-18 19:32:14 +00:00
Mikio Hara
37eb1d1964 cmd/doc: fix build
Change-Id: Ic8437a1d2aeb424d6d5ce9e608c1293bba4c7bbc
Reviewed-on: https://go-review.googlesource.com/10093
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-05-15 00:48:46 +00:00
Rob Pike
83c7b60f27 cmd/doc: trim unexported methods from interfaces
Fixes #10856.

Change-Id: I5de65b8dd94eec3451ee0ba9c75698cdd88f5fea
Reviewed-on: https://go-review.googlesource.com/10088
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-05-14 23:23:18 +00:00
Rob Pike
1e26df40fa cmd/doc: print BUGs after package docs
Was otherwise absent unless bound to an exported symbol,
as in the BUG with strings.Title.

Fixes #10781.

Change-Id: I1543137073a9dee9e546bc9d648ca54fc9632dde
Reviewed-on: https://go-review.googlesource.com/9899
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-13 21:07:16 +00:00
Rob Pike
da4fc529d9 cmd/doc: add type-bound vars to global vars list
Already done for constants and funcs, but I didn't realize that some
global vars were also not in the global list. This fixes

	go doc build.Default

Change-Id: I768bde13a400259df3e46dddc9f58c8f0e993c72
Reviewed-on: https://go-review.googlesource.com/9764
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-05-06 22:32:42 +00:00
Rob Pike
9de28cf547 cmd/doc: if no top-level symbols match, look for methods
Improving the usability further.

Before:

$ go doc bytes.Read
doc: symbol Read not present in package bytes installed in "bytes"
$

After:
$ go doc bytes.Read
func (b *Buffer) Read(p []byte) (n int, err error)
    Read reads the next len(p) bytes from the buffer or until the buffer is drained.
    The return value n is the number of bytes read. If the buffer has no data to
    return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (r *Reader) Read(b []byte) (n int, err error)
$

Change-Id: I646511fada138bd09e9b39820da01a5ccef4a90f
Reviewed-on: https://go-review.googlesource.com/9656
Reviewed-by: Russ Cox <rsc@golang.org>
2015-05-06 16:13:47 +00:00
Rob Pike
1ab60c2930 cmd/doc: show the true import path rather than "."
Change-Id: I7b15c027c15eefc2a004eb61491e828a7fbefc54
Reviewed-on: https://go-review.googlesource.com/9513
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-29 23:01:37 +00:00
Rob Pike
06946aad19 cmd/go: better UI for go doc
Print it out much like godoc so there isn't a single block of text.
Print the symbol before its comment and indent the comment so
individual symbols separate visually.

Buffer the output.

Add a -c option to force case-sensitive matching.

Allow two arguments, like godoc, to help disambiguate cases
where path and symbol may be confused.

Improve the documentation printed by go help doc.

Change-Id: If687aad04bbacdf7dbe4bf7636de9fe96f756fd0
Reviewed-on: https://go-review.googlesource.com/9471
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-29 19:12:53 +00:00
Rob Pike
d3bd6b6ae7 cmd/doc: print documentation for all matches in a package, not just the first
Change-Id: Id0d4ac7169f741dfeec7b1e67bdc21e49ae37b9e
Reviewed-on: https://go-review.googlesource.com/9430
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-28 19:42:57 +00:00
Rob Pike
a5de54a870 cmd/go,cmd/doc: add "go doc"
Add the new go doc command to the go command, installed in
the tool directory.

(Still to do: tests)

Fix cmd/dist to remove old "package documentation" code that was
stopping it from including cmd/go/doc.go in the build.

Implement the doc command. Here is the help info from "go help doc":

===
usage: go doc [-u] [package|[package.]symbol[.method]]

Doc accepts at most one argument, indicating either a package, a symbol within a
package, or a method of a symbol.

	go doc
	go doc <pkg>
	go doc <sym>[.<method>]
	go doc [<pkg>].<sym>[.<method>]

Doc interprets the argument to see what it represents, determined by its syntax
and which packages and symbols are present in the source directories of GOROOT and
GOPATH.

The first item in this list that succeeds is the one whose documentation is printed.
For packages, the order of scanning is determined by the file system, however the
GOROOT tree is always scanned before GOPATH.

If there is no package specified or matched, the package in the current directory
is selected, so "go doc" shows the documentation for the current package and
"go doc Foo" shows the documentation for symbol Foo in the current package.

Doc prints the documentation comments associated with the top-level item the
argument identifies (package, type, method) followed by a one-line summary of each
of the first-level items "under" that item (package-level declarations for a
package, methods for a type, etc.)

The package paths must be either a qualified path or a proper suffix of a path
(see examples below). The go tool's usual package mechanism does not apply: package
path elements like . and ...  are not implemented by go doc.

When matching symbols, lower-case letters match either case but upper-case letters
match exactly.

Examples:
	go doc
		Show documentation for current package.
	go doc Foo
		Show documentation for Foo in the current package.
		(Foo starts with a capital letter so it cannot match a package path.)
	go doc json
		Show documentation for the encoding/json package.
	go doc json
		Shorthand for encoding/json assuming only one json package
		is present in the tree.
	go doc json.Number (or go doc json.number)
		Show documentation and method summary for json.Number.
	go doc json.Number.Int64 (or go doc json.number.int64)
		Show documentation for the Int64 method of json.Number.

Flags:
	-u
		Show documentation for unexported as well as exported
		symbols and methods.

===

Still to do:

Tests.
Disambiguation when there is both foo and Foo.
Flag for case-sensitive matching.

Change-Id: I83d409a68688a5445f54297a7e7c745f749b9e66
Reviewed-on: https://go-review.googlesource.com/9227
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-27 23:22:26 +00:00