Compare:
http://swtch.com/junk/regexp0.html [old]
http://swtch.com/junk/regexp.html [new]
Especially for packages with large APIs, this makes the
overview more promiment, so that it can give the appropriate
context for reading the API list. This should help significantly
in packages with large APIs, like net, so that the first thing users
see is not a jumble of functions but an introduction to the package.
R=adg, gri, r, kevlar, dsymonds, rogpeppe
CC=golang-dev
https://golang.org/cl/5573068
Separating Method from Func made the code only more complicated
without adding much to the useability/readability of the API.
Reverted to where it was, but leaving the new method-specific
fields Orig and Level.
Former clients (godoc) of doc.Method only used the Func fields;
and because Func was embedded, no changes are needed with respect
to the removal of Method.
Changed type of Func.Recv from ast.Expr to string. This was a
long-standing TODO. Also implemented Func.Orig field (another TODO).
No further go/doc API changes are expected for Go 1.
R=rsc, r, r
CC=golang-dev
https://golang.org/cl/5577043
Also, disable server-side generation of TOC for commands as they would
only ever show Overview. The JS does a better job (for now).
Fixes#2732.
R=gri, dsymonds
CC=golang-dev
https://golang.org/cl/5558046
- the main changes are removing the Doc suffix
from the exported types, so instead of
doc.TypeDoc one will have doc.Type, etc.
- All exported types now have a Name (or Names) field.
For Values, the Names field lists all declared variables
or constants.
- Methods have additional information about where they are
coming from.
- There's a mode field instead of a bool to
control the package's operation, which makes
it easier to extend w/o API changes.
Except for the partially implemented new Method type,
this is based on existing code. A clean rewrite is in
progress based on this new API.
R=rsc, kevlar
CC=golang-dev
https://golang.org/cl/5528060
Example:
PACKAGE
package utf8
import "unicode/utf8"
Package utf8 implements functions and constants to support text
encoded in UTF-8. This package calls a Unicode character a rune for
brevity.
CONSTANTS
const (
RuneError = unicode.ReplacementChar // the "error" Rune or "replacement character".
RuneSelf = 0x80 // characters below Runeself are represented as themselves in a single byte.
UTFMax = 4 // maximum number of bytes of a UTF-8 encoded Unicode character.
)
Numbers fundamental to the encoding.
FUNCTIONS
func DecodeLastRune(p []byte) (r rune, size int)
DecodeLastRune unpacks the last UTF-8 encoding in p and returns the
rune and its width in bytes.
func DecodeLastRuneInString(s string) (r rune, size int)
DecodeLastRuneInString is like DecodeLastRune but its input is a
string.
func DecodeRune(p []byte) (r rune, size int)
DecodeRune unpacks the first UTF-8 encoding in p and returns the rune
and its width in bytes.
func DecodeRuneInString(s string) (r rune, size int)
DecodeRuneInString is like DecodeRune but its input is a string.
func EncodeRune(p []byte, r rune) int
EncodeRune writes into p (which must be large enough) the UTF-8
encoding of the rune. It returns the number of bytes written.
func FullRune(p []byte) bool
FullRune reports whether the bytes in p begin with a full UTF-8
encoding of a rune. An invalid encoding is considered a full Rune
since it will convert as a width-1 error rune.
func FullRuneInString(s string) bool
FullRuneInString is like FullRune but its input is a string.
func RuneCount(p []byte) int
RuneCount returns the number of runes in p. Erroneous and short
encodings are treated as single runes of width 1 byte.
func RuneCountInString(s string) (n int)
RuneCountInString is like RuneCount but its input is a string.
func RuneLen(r rune) int
RuneLen returns the number of bytes required to encode the rune.
func RuneStart(b byte) bool
RuneStart reports whether the byte could be the first byte of an
encoded rune. Second and subsequent bytes always have the top two
bits set to 10.
func Valid(p []byte) bool
Valid reports whether p consists entirely of valid UTF-8-encoded
runes.
func ValidString(s string) bool
ValidString reports whether s consists entirely of valid UTF-8-encoded
runes.
TYPES
type String struct {
// contains filtered or unexported fields
}
String wraps a regular string with a small structure that provides
more efficient indexing by code point index, as opposed to byte index.
Scanning incrementally forwards or backwards is O(1) per index
operation (although not as fast a range clause going forwards).
Random access is O(N) in the length of the string, but the overhead is
less than always scanning from the beginning. If the string is ASCII,
random access is O(1). Unlike the built-in string type, String has
internal mutable state and is not thread-safe.
func NewString(contents string) *String
NewString returns a new UTF-8 string with the provided contents.
func (s *String) At(i int) rune
At returns the rune with index i in the String. The sequence of runes
is the same as iterating over the contents with a "for range" clause.
func (s *String) Init(contents string) *String
Init initializes an existing String to hold the provided contents.
It returns a pointer to the initialized String.
func (s *String) IsASCII() bool
IsASCII returns a boolean indicating whether the String contains only
ASCII bytes.
func (s *String) RuneCount() int
RuneCount returns the number of runes (Unicode code points) in the
String.
func (s *String) Slice(i, j int) string
Slice returns the string sliced at rune positions [i:j].
func (s *String) String() string
String returns the contents of the String. This method also means the
String is directly printable by fmt.Print.
Fixes#2479.
R=golang-dev, dsymonds, mattn.jp, r, gri, r
CC=golang-dev
https://golang.org/cl/5472051
This feature should make it easier to look at very large
directory trees.
- a new mode (URL: /pkg/?m=flat) shows directory listings w/o
indentation and entries with full path (html and text mode)
- in text mode, hierarchical (non-flat) directory listings are
now presented with indentation (/pkg/?m=text)
- in html mode, hierarchical (non-flat) directory listings are
presented with slightly less indentation
- there is an internal hook for programmatic control of the
display mode (for specialized versions of godoc).
R=bradfitz
CC=golang-dev, rsc
https://golang.org/cl/5410043
1. Generate TOC for package pages using template,
instead of using JavaScript magic. This makes the
pages generated by godoc -html easier to export
to other systems.
2. Make TOC one column. It's hard to do two columns
portably without invoking JavaScript.
3. Since the TOC is only one column, show full type
signatures for functions and methods. Many times
that's all you need to see anyway.
4. Name the section after the TOC "Overview".
Naming it something is important, to set it off
from the TOC and so that there's a quick link to
it in the TOC.
For now, some illustrative examples:
http://swtch.com:6060/pkg/io/http://swtch.com:6060/pkg/strings/http://swtch.com:6060/pkg/tabwriter/http://swtch.com:6060/pkg/unicode/Fixes#1982.
R=gri, bradfitz, r
CC=golang-dev
https://golang.org/cl/5303044
This CL introduces the go.Example type and go.Examples functions that
are used to represent and extract code samples from Go source.
They should be of the form:
// Output of this function.
func ExampleFoo() {
fmt.Println("Output of this function.")
}
It also modifies godoc to read example code from _test.go files,
and include them in the HTML output with JavaScript-driven toggles.
It also implements testing of example functions with gotest.
The stdout/stderr is compared against the output comment on the
function.
This CL includes examples for the sort.Ints function and the
sort.SortInts type. After patching this CL in and re-building go/doc
and godoc, try
godoc -http=localhost:6060
and visit http://localhost:6060/pkg/sort/
R=gri, r, rsc
CC=golang-dev
https://golang.org/cl/5137041
Also: fix layout of textual search results and
fix a field reference in the respective template.
Fixes#1987.
R=rsc, r
CC=golang-dev
https://golang.org/cl/4962061
- KindRuns don't need to repeat SpotKind,
it is stored in each Spot
- removed extra indirection from FileRuns
to KindRuns
- slight reduction of written index size
(~500KB)
R=rsc
CC=golang-dev
https://golang.org/cl/4969052
Use naming convention for template variables
to indicate "escaped-ness" for easier reviewing.
(per suggestion from bradfitz)
R=bradfitz
CC=golang-dev
https://golang.org/cl/4914041
Since the posLink_url also adds a non-URL attribute, the quoting and URL-escaping
must happen inside posLink_url (otherwise the non-URL attribute becomes part or the
URL portion of the tag.
R=r
CC=golang-dev
https://golang.org/cl/4888041
- rename template funcs for better consistency and
sort them into groups of related functionality
- try to be more consistent with html vs url escaping
R=r
CC=golang-dev
https://golang.org/cl/4887041
- simplified pipelines
- simplified templates by using template variables
- converted most old-style formatters into new-style funcs
- fixed some escaping bugs (use of url escaping where it was missing)
R=r, dsymonds
CC=golang-dev
https://golang.org/cl/4868044
- first step; rough conversion of all template files
- there is plenty of opportunity for cleanups/simplifications (next CLs)
- html and text output as before
R=r, dsymonds
CC=golang-dev
https://golang.org/cl/4852048
Uses placeholder attribute instead of changing the value of search
field on browsers that support it. On other browsers, the fake
placeholder text is restored when the empty box loses focus.
R=golang-dev, gri
CC=golang-dev
https://golang.org/cl/4441041
Neither gofmt nor godoc are making use of a Styler (for
token-specific formatting) anymore. Stylers interacted in complicated
ways with HTML-escaping which was why the printer needed an HTML mode
in the first place.
godoc now uses a more powerful and general text formatting
function that does HTML escaping, text selection, and can
handle token-specific formatting if so desired (currently
used only for comments).
As a consequence, cleaned up uses of go/printer in godoc;
simplified the various write utility functions, and also
removed the need for the "html" template format (in favor of
html-esc which now does the same and is used more pervasively).
Applied gofmt -w src misc to verify no changes occured,
and tested godoc manually.
There should be no visible changes except that (type) code
snippets presented for godoc package documentation now
uses the same formatting as for general source code and
thus comments get the comment-specific color here as well
(not the case at the moment).
(TODO: godoc needs a good automatic test suite).
R=rsc
CC=golang-dev
https://golang.org/cl/4152042
- added flag -maxresults (default: 10000) to limit the max.
number of full text results shown
- removed flag -fulltext; use -maxresults=0 to disable fulltext
index
- better indication on result page if not all results are shown
(... after line list)
R=rsc, gri1
CC=golang-dev
https://golang.org/cl/4049042
Regular expressions may now be used in conjuction with full text
search. Godoc will show the first 10000 occurences in the source
code and highlight the respective text segments.
- added new flag -testDir to specify a small directory for testing
(fast index creation; default = "")
- use new FormatText function to format text and Go source
code in HTML, supporting multiple kinds of text selections
simulatenously); this replaces the uses of go/printer
Stylers
- for now removed currently unused mechanism for identifier-
specific JS popups (will come back in some form once we
have type or other useful information)
- various typo fixes and minor cleanups throughout
Missing:
- indexing of non-.go files
R=r, r2
CC=golang-dev, rsc
https://golang.org/cl/3699041
changeset: 6839:545c9926d61a
user: Robert Griesemer <gri@golang.org>
date: Mon Dec 06 14:23:18 2010 -0800
summary: go/ast: use token.Pos instead of token.Position; adjust all dependent code
broke 'godoc -src fmt', one of the example uses of godoc. It gives a stack backtrace essentially
caused by dereferencing a NULL pointer (in C terms). This change fixes the particular issue, but
the code probably should be made more robust.
Fixes#3818044.
R=gri
CC=golang-dev
https://golang.org/cl/3818044
- improved search result page
- clicking on files shows highlighted search phrase
(.go files loose their godoc-specific formatting and
highlighting in this mode - a better solution is in
the works)
- support for textual results
- fixed bug with non-URL escaped URL parameter (Query)
R=rsc, adg
CC=golang-dev
https://golang.org/cl/3585041
To enable use -fulltext flag; e.g.: godoc -v -fulltext -http=:7777
Enabling the fulltext index will use significantly more memory as
the text of all source code, the respective suffixarray, and the
file set data structure is kept in memory. At the moment there is
about 6Mb of source code (~1400 files) indexed under GOROOT.
Source code + suffix array together consume 5*(size of source) or
about 30Mb. The file set data structure consumes about 4b/src line.
By default only up to 5000 results are shown for now.
The presentation of the results needs tuning. In particular,
if a string is found, clicking on the respective file does not
highlight them, yet.
At the moment, only Go source files are indexed. Eventually,
the full text index should encompass other files as well.
R=rsc, adg
CC=golang-dev
https://golang.org/cl/3182043
Specifically:
* lib/godoc:
- provide file set (FSet) argument to formatters where needed
* src/cmd:
- cgo, ebnflint, godoc, gofmt, goinstall: provide file set (fset) where needed
- godoc: remove local binary search with sort.Search (change by rsc),
extract file set for formatters
* src/pkg:
- exp/eval: remove embedded token.Position fields from nodes and replace
with named token.Pos fields; add corresponding Pos() accessor methods
- go/token: added file.Line(), changed signature of File.Position()
* test/fixedbugs/:
- bug206.go: change test to not rely on token.Pos details
* added various extra comments
* Runs all.bash
* gofmt formats all of src, misc w/o changes
* godoc runs
* performance:
- The new version of godoc consumes about the same space after indexing
has completed, but indexing is half the speed. Significant space savings
are expected from smaller ASTs, but since they are thrown away after a
file has been indexed, this is not visible anymore. The slower indexing
time is due to the much more expensive computation of line information.
However, with the new compressed position information, indexing can be
rewritten and simplified. Furthermore, computing the line info can be
done more efficiently.
New godoc, immediately after indexing completed (best of three runs):
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
44381 godoc 0.0% 0:38.00 4 19 149 145M 184K 148M 176M
2010/12/03 17:58:35 index updated (39.231s, 18505 unique words, 386387 spots)
2010/12/03 17:58:35 bytes=90858456 footprint=199182584
2010/12/03 17:58:36 bytes=47858568 footprint=167295224
Old godoc, immediately after indexing completed (best of three runs):
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
23167 godoc 0.0% 0:22.02 4 17 132 129M 184K 132M 173M
2010/12/03 14:51:32 index updated (24.892s, 18765 unique words, 393830 spots)
2010/12/03 14:51:32 bytes=66404528 footprint=163907832
2010/12/03 14:51:32 bytes=46282224 footprint=163907832
The different numbers for unique words/spots stem from the fact the the
two workspaces are not exactly identical. The new godoc maintains a large
file set data structure during indexing which (probably) is the reason
for the larger heap (90858456 vs 66404528) before garbage collection.
R=rsc, r
CC=golang-dev
https://golang.org/cl/3050041
The front page remains fixed-width.
All other pages should look good in windows >=500px wide.
Includes additional styles for search result highlighting,
code comments, and general CSS clean-ups.
Tested with Chrome 6, Firefox 3.6, IE 7, and IE 8.
R=gri, r
CC=golang-dev
https://golang.org/cl/2229041
- change ast.Ident back to contain the name and adjust all dependent code
- identifier object information will be added again through an optional
typechecker phase (in the works).
- remove tracking of scopes in parser - it's easier to do this in a separate
phase (in the works)
- in godoc, generate popup info table directly instead of through a formatter
for simpler data flow (at the expense of a little bit more code)
Runs all tests.
As a result of this change, the currently shown popup information
(const, var, type, func, followed by identifier name) will not be
shown anymore temporarily.
R=rsc
CC=golang-dev
https://golang.org/cl/1994041
This is a stop-gap change to give more current information visibility
before a more thorough reorganization.
R=r, rsc, gri
CC=golang-dev
https://golang.org/cl/1902042