Documentation
¶
Overview ¶
Package gsd documentation extracts source code documentation from Go Doc and Go AST.
Index ¶
- Constants
- func FormatSelections(w io.Writer, text []byte, lw LinkWriter, links Selection, sw SegmentWriter, ...)
- func FormatText(w io.Writer, text []byte, line int, goSource bool, pattern string, ...)
- func IsExported(name string) bool
- func LinkifyText(w io.Writer, text []byte, n ast.Node)
- func TypeFields(t *Type) (fields []*ast.Field)
- type Corpus
- func (c *Corpus) DocumentHandler(w http.ResponseWriter, req *http.Request)
- func (c *Corpus) Export() (err error)
- func (c *Corpus) IndentFilter(nodes interface{}) (result interface{})
- func (c *Corpus) InitVersionInfo()
- func (c *Corpus) ParsePackages() error
- func (c *Corpus) StaticHandler(w http.ResponseWriter, req *http.Request)
- func (c *Corpus) Watch(address string) (err error)
- type Field
- type FieldsPage
- type Func
- type LinkWriter
- type Module
- type ModuleError
- type Package
- type PackagePublic
- type Packages
- type Page
- type PageType
- type Segment
- type SegmentWriter
- type Selection
- type SpotInfo
- type SpotKind
- type Type
- Bugs
Constants ¶
const Version = "0.0.1"
Version info
Variables ¶
This section is empty.
Functions ¶
func FormatSelections ¶
func FormatSelections(w io.Writer, text []byte, lw LinkWriter, links Selection, sw SegmentWriter, selections ...Selection)
FormatSelections takes a text and writes it to w using link and segment writers lw and sw as follows: lw is invoked for consecutive segment starts and ends as specified through the links selection, and sw is invoked for consecutive segments of text overlapped by the same selections as specified by selections. The link writer lw may be nil, in which case the links Selection is ignored.
func FormatText ¶
func FormatText(w io.Writer, text []byte, line int, goSource bool, pattern string, selection Selection)
FormatText HTML-escapes text and writes it to w. Consecutive text segments are wrapped in HTML spans (with tags as defined by startTags and endTag) as follows:
- if line >= 0, line number (ln) spans are inserted before each line, starting with the value of line
- if the text is Go source, comments get the "comment" span class
- each occurrence of the regular expression pattern gets the "highlight" span class
- text segments covered by selection get the "selection" span class
Comments, highlights, and selections may overlap arbitrarily; the respective HTML span classes are specified in the startTags variable.
func LinkifyText ¶
LinkifyText HTML-escapes source text and writes it to w. Identifiers that are in a "use" position (i.e., that are not being declared), are wrapped with HTML links pointing to the respective declaration, if possible. Comments are formatted the same way as with FormatText.
Types ¶
type Corpus ¶
type Corpus struct {
Path string
// Packages is all packages cache
Packages map[string]*Package
// Tree is packages tree struct
// - a
// - a-a
// - b
//
Tree Packages
EnablePrivateIndent bool
// contains filtered or unexported fields
}
A Corpus holds all the package documentation
func (*Corpus) DocumentHandler ¶
func (c *Corpus) DocumentHandler(w http.ResponseWriter, req *http.Request)
DocumentHandler serve documents The "/" pattern matches everything, so we need to check that we're at the root here.
func (*Corpus) IndentFilter ¶
func (c *Corpus) IndentFilter(nodes interface{}) (result interface{})
IndentFilter indent filter
func (*Corpus) InitVersionInfo ¶
func (c *Corpus) InitVersionInfo()
InitVersionInfo parses the $GOROOT/api/go*.txt API definition files to discover which API features were added in which Go releases.
func (*Corpus) StaticHandler ¶
func (c *Corpus) StaticHandler(w http.ResponseWriter, req *http.Request)
StaticHandler serve static assets
type FieldsPage ¶
FieldsPage fields page type
type Func ¶
type Func struct {
// doc.Func
Doc string
Name string
Decl *ast.FuncDecl
// methods
// (for functions, these fields have the respective zero value)
Recv string // actual receiver "T" or "*T"
Orig string // original receiver "T" or "*T"
Level int // embedding level; 0 means not embedded
Examples []*doc.Example
// interface type
Field *ast.Field
FuncType *ast.FuncType
// ast.FuncType fields
Params *ast.FieldList // (incoming) parameters; non-nil
Results *ast.FieldList // (outgoing) results; or nil
}
Func type
func NewFuncWithDoc ¶
NewFuncWithDoc return func with doc.Func
type LinkWriter ¶
A LinkWriter writes some start or end "tag" to w for the text offset offs. It is called by FormatSelections at the start or end of each link segment.
type Module ¶
type Module struct {
Path string `json:",omitempty"` // module path
Version string `json:",omitempty"` // module version
Versions []string `json:",omitempty"` // available module versions
Replace *Module `json:",omitempty"` // replaced by this module
Time *time.Time `json:",omitempty"` // time version was created
Update *Module `json:",omitempty"` // available update (with -u)
Main bool `json:",omitempty"` // is this the main module?
Indirect bool `json:",omitempty"` // module is only indirectly needed by main module
Dir string `json:",omitempty"` // directory holding local copy of files, if any
GoMod string `json:",omitempty"` // path to go.mod file describing module, if any
GoVersion string `json:",omitempty"` // go version used in module
Error *ModuleError `json:",omitempty"` // error loading module
}
Module go mod info type
type ModuleError ¶
type ModuleError struct {
Err string // error text
}
ModuleError go mod error type
type Package ¶
type Package struct {
Dir string // !important: directory containing package sources
ImportPath string // !important: import path of package in dir
ImportComment string // path in import comment on package statement
Name string // package name
Doc string // package documentation string
Module *Module // info about package's module, if any
Stale bool // would 'go install' do anything for this package?
StaleReason string // why is Stale true?
// declarations
Imports []string // import paths used by this package
Filenames []string // all files
Notes map[string][]*doc.Note // nil if no package Notes, or contains Buts, etc...
Consts []*doc.Value
Types []*Type
Vars []*doc.Value
Funcs []*Func
// Examples is a sorted list of examples associated with
// the package. Examples are extracted from _test.go files provided to NewFromFiles.
Examples []*doc.Example // nil if no example code
ParentImportPath string // parent package ImportPath
Parent *Package `json:"-"` // parent package, important: json must ignore, prevent cycle parsing
SubPackages []*Package // subpackages
Dirname string // directory containing the package
Err error // error or nil
// package info
FSet *token.FileSet // nil if no package documentation
DocPackage *doc.Package // nil if no package documentation
PAst map[string]*ast.File // nil if no AST with package exports
IsMain bool // true for package main
}
Package type
type PackagePublic ¶
type PackagePublic struct {
Dir string `json:",omitempty"` // directory containing package sources
ImportPath string `json:",omitempty"` // import path of package in dir
ImportComment string `json:",omitempty"` // path in import comment on package statement
Name string `json:",omitempty"` // package name
Doc string `json:",omitempty"` // package documentation string
Target string `json:",omitempty"` // installed target for this package (may be executable)
Shlib string `json:",omitempty"` // the shared library that contains this package (only set when -linkshared)
Root string `json:",omitempty"` // Go root, Go path dir, or module root dir containing this package
ConflictDir string `json:",omitempty"` // Dir is hidden by this other directory
ForTest string `json:",omitempty"` // package is only for use in named test
Export string `json:",omitempty"` // file containing export data (set by go list -export)
Module *Module `json:",omitempty"` // info about package's module, if any
Match []string `json:",omitempty"` // command-line patterns matching this package
Goroot bool `json:",omitempty"` // is this package found in the Go root?
Standard bool `json:",omitempty"` // is this package part of the standard Go library?
DepOnly bool `json:",omitempty"` // package is only as a dependency, not explicitly listed
BinaryOnly bool `json:",omitempty"` // package cannot be recompiled
Incomplete bool `json:",omitempty"` // was there an error loading this package or dependencies?
// Stale and StaleReason remain here *only* for the list command.
// They are only initialized in preparation for list execution.
// The regular build determines staleness on the fly during action execution.
Stale bool `json:",omitempty"` // would 'go install' do anything for this package?
StaleReason string `json:",omitempty"` // why is Stale true?
// Dependency information
Imports []string `json:",omitempty"` // import paths used by this package
ImportMap map[string]string `json:",omitempty"` // map from source import to ImportPath (identity entries omitted)
Deps []string `json:",omitempty"` // all (recursively) imported dependencies
// Test information
// If you add to this list you MUST add to p.AllFiles (below) too.
// Otherwise file name security lists will not apply to any new additions.
TestGoFiles []string `json:",omitempty"` // _test.go files in package
TestImports []string `json:",omitempty"` // imports from TestGoFiles
XTestGoFiles []string `json:",omitempty"` // _test.go files outside package
XTestImports []string `json:",omitempty"` // imports from XTestGoFiles
}
A PackagePublic describes a single package found in a directory. go/libexec/src/cmd/go/internal/load/pkg.go
type Page ¶
type Page struct {
Corpus *Corpus
Package *Package
Type *Type
Func *Func
PageType PageType
LayoutHTML *template.Template
SidebarHTML *template.Template
PackageHTML *template.Template
TypeHTML *template.Template
FuncHTML *template.Template
FieldsHTML *template.Template
ExampleHTML *template.Template
Title string
// TabWidth optionally specifies the tab width.
TabWidth int
ShowPlayground bool
DeclLinks bool
Sidebar []byte // Sidebar content
Body []byte // Main content
// contains filtered or unexported fields
}
Page generates output from a corpus.
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
A Segment describes a text segment [start, end). The zero value of a Segment is a ready-to-use empty segment.
type SegmentWriter ¶
A SegmentWriter formats a text according to selections and writes it to w. The selections parameter is a bit set indicating which selections provided to FormatSelections overlap with the text segment: If the n'th bit is set in selections, the n'th selection provided to FormatSelections is overlapping with the text.
type Selection ¶
type Selection func() Segment
A Selection is an "iterator" function returning a text segment. Repeated calls to a selection return consecutive, non-overlapping, non-empty segments, followed by an infinite sequence of empty segments. The first empty segment marks the end of the selection.
func RangeSelection ¶
RangeSelection computes the Selection for a text range described by the argument str; the range description must match the selRx regular expression.
type SpotInfo ¶
type SpotInfo uint32
A SpotInfo value describes a particular identifier spot in a given file; It encodes three values: the SpotKind (declaration or use), a line or snippet index "lori", and whether it's a line or index.
The following encoding is used:
bits 32 4 1 0 value [lori|kind|isIndex]
type SpotKind ¶
type SpotKind uint32
SpotKind describes whether an identifier is declared (and what kind of declaration) or used.
type Type ¶
type Type struct {
// doc.Type
Doc string
Name string
Decl *ast.GenDecl
// associated declarations
Consts []*doc.Value // sorted list of constants of (mostly) this type
Vars []*doc.Value // sorted list of variables of (mostly) this type
Funcs []*Func // sorted list of functions returning this type
Methods []*Func // sorted list of methods (including embedded ones) of this type
// Examples is a sorted list of examples associated with
// this type. Examples are extracted from _test.go files
// provided to NewFromFiles.
Examples []*doc.Example
Fields *ast.FieldList
}
Type type
func NewTypeWithDoc ¶
NewTypeWithDoc return type with doc.Type
Notes ¶
Bugs ¶
test bug info.