Documentation ¶
Overview ¶
Package lang provides constructs for defining golang language constructs and extracting information from them for documentation purposes.
Index ¶
- func PackageSymbols(pkg *doc.Package) map[string]Symbol
- type Block
- type BlockKind
- type Config
- type ConfigOption
- type Doc
- type Example
- func (ex *Example) Code() (string, error)
- func (ex *Example) Doc() *Doc
- func (ex *Example) HasOutput() bool
- func (ex *Example) Level() int
- func (ex *Example) Location() Location
- func (ex *Example) Name() string
- func (ex *Example) Output() string
- func (ex *Example) Summary() string
- func (ex *Example) Title() string
- type File
- type Func
- func (fn *Func) Anchor() string
- func (fn *Func) Doc() *Doc
- func (fn *Func) Examples() (examples []*Example)
- func (fn *Func) Level() int
- func (fn *Func) Location() Location
- func (fn *Func) Name() string
- func (fn *Func) Receiver() string
- func (fn *Func) Signature() (string, error)
- func (fn *Func) Summary() string
- func (fn *Func) Title() string
- type Item
- type ItemKind
- type List
- type Location
- type Package
- func (pkg *Package) Consts() (consts []*Value)
- func (pkg *Package) Dir() string
- func (pkg *Package) Dirname() string
- func (pkg *Package) Doc() *Doc
- func (pkg *Package) Examples() (examples []*Example)
- func (pkg *Package) Funcs() (funcs []*Func)
- func (pkg *Package) Import() string
- func (pkg *Package) ImportPath() string
- func (pkg *Package) Level() int
- func (pkg *Package) Name() string
- func (pkg *Package) Summary() string
- func (pkg *Package) Types() (types []*Type)
- func (pkg *Package) Vars() (vars []*Value)
- type PackageOption
- type PackageOptions
- type Position
- type Repo
- type Span
- type SpanKind
- type Symbol
- type SymbolKind
- type Type
- func (typ *Type) Anchor() string
- func (typ *Type) Consts() []*Value
- func (typ *Type) Decl() (string, error)
- func (typ *Type) Doc() *Doc
- func (typ *Type) Examples() (examples []*Example)
- func (typ *Type) Funcs() []*Func
- func (typ *Type) Level() int
- func (typ *Type) Location() Location
- func (typ *Type) Methods() []*Func
- func (typ *Type) Name() string
- func (typ *Type) Summary() string
- func (typ *Type) Title() string
- func (typ *Type) Vars() []*Value
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block defines a single block element (e.g. paragraph, code block) in the documentation for a symbol or package.
func NewBlock ¶
NewBlock creates a new block element of the provided kind and with the given text spans and a flag indicating whether this block is part of an inline element.
func NewListBlock ¶
NewListBlock creates a new list block element and with the given list definition and a flag indicating whether this block is part of an inline element.
func ParseBlocks ¶
ParseBlocks produces a set of blocks from the corresponding comment blocks. It also takes a flag indicating whether the blocks are part of an inline element such as a list item.
func (*Block) Inline ¶
Inline indicates whether the block is part of an inline element, such as a list item.
func (*Block) Kind ¶
Kind provides the kind of data that this block's text should be interpreted as.
func (*Block) Level ¶
Level provides the default level that a block of kind HeaderBlock will render at in the output. The level is not used for other block types.
func (*Block) List ¶
List provides the list contents for a list block. Only relevant for blocks of type ListBlock.
type BlockKind ¶
type BlockKind string
BlockKind identifies the type of block element represented by the corresponding Block.
const ( // ParagraphBlock defines a block that represents a paragraph of text. ParagraphBlock BlockKind = "paragraph" // CodeBlock defines a block that represents a section of code. CodeBlock BlockKind = "code" // HeaderBlock defines a block that represents a section header. HeaderBlock BlockKind = "header" // ListBlock defines a block that represents an ordered or unordered list. ListBlock BlockKind = "list" )
type Config ¶
type Config struct { FileSet *token.FileSet Files []*ast.File Level int Repo *Repo PkgDir string WorkDir string Symbols map[string]Symbol Pkg *doc.Package Log logger.Logger FileFilter *string OverrideImport *string }
Config defines contextual information used to resolve documentation for a construct.
func NewConfig ¶
func NewConfig(log logger.Logger, workDir string, pkgDir string, opts ...ConfigOption) (*Config, error)
NewConfig generates a Config for the provided package directory. It will resolve the filepath and attempt to determine the repository containing the directory. If no repository is found, the Repo field will be set to nil. An error is returned if the provided directory is invalid.
type ConfigOption ¶
ConfigOption modifies the Config generated by NewConfig.
func ConfigWithFileFilter ¶
func ConfigWithFileFilter(fileFilter *string) ConfigOption
func ConfigWithOverrideImport ¶
func ConfigWithOverrideImport(importPath *string) ConfigOption
func ConfigWithRepoOverrides ¶
func ConfigWithRepoOverrides(overrides *Repo) ConfigOption
ConfigWithRepoOverrides defines a set of manual overrides for the repository information to be used in place of automatic repository detection.
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc provides access to the documentation comment contents for a package or symbol in a structured form.
func NewDoc ¶
NewDoc initializes a Doc struct from the provided raw documentation text and with headers rendered by default at the heading level provided. Documentation is separated into block level elements using the standard rules from golang's documentation conventions.
type Example ¶
type Example struct {
// contains filtered or unexported fields
}
Example holds a single documentation example for a package or symbol.
func NewExample ¶
NewExample creates a new example from the example function's name, its documentation example and the files holding code related to the example.
func (*Example) Doc ¶
Doc provides the structured contents of the documentation comment for the example.
func (*Example) Level ¶
Level provides the default level that headers for the example should be rendered.
func (*Example) Location ¶
Location returns a representation of the node's location in a file within a repository.
func (*Example) Name ¶
Name provides a pretty-printed name for the specific example, if one was provided.
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func holds documentation information for a single func declaration within a package or type.
func NewFunc ¶
NewFunc creates a new Func from the corresponding documentation construct from the standard library, the related token.FileSet for the package and the list of examples for the package.
func (*Func) Doc ¶
Doc provides the structured contents of the documentation comment for the function.
func (*Func) Examples ¶
Examples provides the list of examples from the list given on initialization that pertain to the function.
func (*Func) Level ¶
Level provides the default level at which headers for the func should be rendered in the final documentation.
func (*Func) Location ¶
Location returns a representation of the node's location in a file within a repository.
func (*Func) Receiver ¶
Receiver provides the type of the receiver for the function, or empty string if there is no receiver type.
func (*Func) Signature ¶
Signature provides the raw text representation of the code for the function's signature.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item defines a single item in a list in the documentation for a symbol or package.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List defines a list block element in the documentation for a symbol or package.
func (*List) BlankBetween ¶
BlankBetween returns true if there should be a blank line between list items.
type Location ¶
Location holds information for identifying a position within a file and repository, if present.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package holds documentation information for a package and all of the symbols contained within it.
func NewPackage ¶
NewPackage creates a representation of a package's documentation from the raw documentation constructs provided by the standard library. This is only recommended for advanced scenarios. Most consumers will find it easier to use NewPackageFromBuild instead.
func NewPackageFromBuild ¶
func NewPackageFromBuild(log logger.Logger, pkg *build.Package, opts ...PackageOption) (*Package, error)
NewPackageFromBuild creates a representation of a package's documentation from the build metadata for that package. It can be configured using the provided options.
func (*Package) Dirname ¶
Dirname provides the name of the leaf directory in which the package is located.
func (*Package) Doc ¶
Doc provides the structured contents of the documentation comment for the package.
func (*Package) Examples ¶
Examples provides the package-level examples that have been defined. This does not include examples that are associated with symbols contained within the package.
func (*Package) Import ¶
Import provides the raw text for the import declaration that is used to import code from the package. If your package's documentation is generated from a local path and does not use Go Modules, this will typically print `import "."`.
func (*Package) ImportPath ¶
ImportPath provides the identifier used for the package when installing or importing the package. If your package's documentation is generated from a local path and does not use Go Modules, this will typically print `.`.
func (*Package) Level ¶
Level provides the default level that headers for the package's root documentation should be rendered.
func (*Package) Name ¶
Name provides the name of the package as it would be seen from another package importing it.
func (*Package) Summary ¶
Summary provides the one-sentence summary of the package's documentation comment.
type PackageOption ¶
type PackageOption func(opts *PackageOptions) error
PackageOption configures one or more options for the package.
func PackageWithFileFilter ¶
func PackageWithFileFilter(file string) PackageOption
PackageWithFileFilter can be used along with the NewPackageFromBuild function to specify that only symbols from a specific file should be included in the documentation for the package.
func PackageWithOverrideImport ¶
func PackageWithOverrideImport(importPath string) PackageOption
func PackageWithRepositoryOverrides ¶
func PackageWithRepositoryOverrides(repo *Repo) PackageOption
PackageWithRepositoryOverrides can be used along with the NewPackageFromBuild function to define manual overrides to the automatic repository detection logic.
func PackageWithUnexportedIncluded ¶
func PackageWithUnexportedIncluded() PackageOption
PackageWithUnexportedIncluded can be used along with the NewPackageFromBuild function to specify that all symbols, including unexported ones, should be included in the documentation for the package.
type PackageOptions ¶
type PackageOptions struct {
// contains filtered or unexported fields
}
PackageOptions holds options related to the configuration of the package and its documentation on creation.
type Span ¶
type Span struct {
// contains filtered or unexported fields
}
Span defines a single text span in a block for documentation of a symbol or package.
func ParseSpans ¶
ParseSpans turns a set of *comment.Text entries into a slice of spans.
type SpanKind ¶
type SpanKind string
SpanKind identifies the type of span element represented by the corresponding Span.
const ( // TextSpan defines a span that represents plain text. TextSpan SpanKind = "text" // RawTextSpan defines a span that represents plain text that should be // displayed as-is. RawTextSpan SpanKind = "rawText" // LinkSpan defines a span that represents a link. LinkSpan SpanKind = "link" // AutolinkSpan defines a span that represents text which is itself a link. AutolinkSpan SpanKind = "autolink" )
type Symbol ¶
type Symbol struct { // Receiver holds the receiver for a method or field. Receiver string // Name holds the name of the symbol itself. Name string // Kind identifies the category of the symbol. Kind SymbolKind // Parent holds the linkable parent symbol which contains this one. Parent *Symbol }
Symbol provides identity information for a symbol in a package.
type SymbolKind ¶
type SymbolKind int
SymbolKind identifies the type of symbol.
const ( TypeSymbolKind SymbolKind = iota 1 FuncSymbolKind ConstSymbolKind VarSymbolKind MethodSymbolKind FieldSymbolKind )
The list of valid symbol kinds.
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type holds documentation information for a type declaration.
func NewType ¶
NewType creates a Type from the raw documentation representation of the type, the token.FileSet for the package's files and the full list of examples from the containing package.
func (*Type) Decl ¶
Decl provides the raw text representation of the code for the type's declaration.
func (*Type) Examples ¶
Examples lists the examples pertaining to the type from the set provided on initialization.
func (*Type) Funcs ¶
Funcs lists the funcs related to the type. This only includes functions which return an instance of the type or its pointer.
func (*Type) Location ¶
Location returns a representation of the node's location in a file within a repository.
func (*Type) Summary ¶
Summary provides the one-sentence summary of the type's documentation comment.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value holds documentation for a var or const declaration within a package.
func NewValue ¶
NewValue creates a new Value from the raw const or var documentation and the token.FileSet of files for the containing package.
func (*Value) Decl ¶
Decl provides the raw text representation of the code for declaring the const or var.
func (*Value) Doc ¶
Doc provides the structured contents of the documentation comment for the example.
func (*Value) Level ¶
Level provides the default level that headers for the value should be rendered.