Documentation ¶
Overview ¶
Package indexer implements a Kythe indexer for the Go language.
Usage example: Indexing a Kythe CompilationUnit message.
// Obtain a compilation from some source, e.g., an kzip. var unit *apb.CompilationUnit = ... // Parse the sources and resolve types. pi, err := indexer.Resolve(unit, pack, &indexer.ResolveOptions{ Info: indexer.AllTypeInfo(), }) if err != nil { log.Fatal("Resolving failed: %v", err) } // Type information from http://godoc.org/go/types is now available // from pi.Info, which is a *types.Info record.
Index ¶
- Variables
- func AllTypeInfo() *types.Info
- func XRefTypeInfo() *types.Info
- type EmitOptions
- type Fetcher
- type PackageInfo
- func (pi *PackageInfo) AnchorVName(file *ast.File, start, end int) *spb.VName
- func (pi *PackageInfo) Emit(ctx context.Context, sink Sink, opts *EmitOptions) error
- func (pi *PackageInfo) FileVName(file *ast.File) *spb.VName
- func (pi *PackageInfo) ObjectVName(obj types.Object) *spb.VName
- func (pi *PackageInfo) Signature(obj types.Object) string
- func (pi *PackageInfo) Span(node ast.Node) (file *ast.File, start, end int)
- func (pi *PackageInfo) String() string
- type ResolveOptions
- type Ruleset
- type Sink
Constants ¶
This section is empty.
Variables ¶
var ErrNoSourceFiles = errors.New("no source files in package")
ErrNoSourceFiles is returned from Resolve if it is given a package without any sources files.
Functions ¶
func AllTypeInfo ¶
AllTypeInfo creates a new types.Info value with empty maps for each of the fields that can be filled in by the type-checker.
func XRefTypeInfo ¶ added in v0.0.27
XRefTypeInfo creates a new types.Info value with empty maps for each of the fields needed for cross-reference indexing.
Types ¶
type EmitOptions ¶ added in v0.0.27
type EmitOptions struct { // If true, emit nodes for standard library packages when they are first // encountered. This is helpful if you want to index a package in isolation // where data for the standard library are not available. EmitStandardLibs bool // If true, emit code facts containing MarkedSource messages. EmitMarkedSource bool // If true, emit linkages specified by metadata rules. EmitLinkages bool // If true, emit childof edges for an anchor's semantic scope. EmitAnchorScopes bool // If true, use the enclosing file for top-level callsite scopes. UseFileAsTopLevelScope bool // If set, use this as the base URL for links to godoc. The import path is // appended to the path of this URL to obtain the target URL to link to. DocBase *url.URL // If true, the doc/uri fact is only emitted for go std library packages. OnlyEmitDocURIsForStandardLibs bool // If enabled, all VNames emitted by the indexer are assigned the // compilation unit's corpus. UseCompilationCorpusForAll bool // If set, all stdlib nodes are assigned this corpus. This takes precedence // over UseCompilationCorpusForAll for stdlib nodes. OverrideStdlibCorpus string // EmitRefCallOverIdentifier determines whether ref/call anchors are emitted // over function identifiers (or the legacy behavior of over the entire // callsite). EmitRefCallOverIdentifier bool // FlagConstructors is a set of known flag constructor functions. FlagConstructors *gopb.FlagConstructors // Verbose determines whether verbose logging is enabled. Verbose bool }
EmitOptions control the behaviour of the Emit function. A nil options pointer provides default values.
type Fetcher ¶
A Fetcher retrieves the contents of a file given its path and/or hex-encoded SHA256 digest, at least one of which must be set.
type PackageInfo ¶
type PackageInfo struct { Name string // The (short) name of the package ImportPath string // The nominal import path of the package Package *types.Package // The package for this compilation Dependencies map[string]*types.Package // Packages imported from dependencies VName *spb.VName // The base vname for this package PackageVName map[*types.Package]*spb.VName // Resolved package to vname FileSet *token.FileSet // Location info for the source files Files []*ast.File // The parsed ASTs of the source files SourceText map[*ast.File]string // The text of the source files Rules map[*ast.File]metadata.Rules // Mapping metadata for each source file Vendored map[string]string // Mapping from package to its vendor path Info *types.Info // If non-nil, contains type-checker results Errors []error // All errors reported by the type checker // contains filtered or unexported fields }
PackageInfo records information about the Go packages defined by a compilation unit and its dependencies.
func Resolve ¶
func Resolve(unit *apb.CompilationUnit, f Fetcher, opts *ResolveOptions) (*PackageInfo, error)
Resolve resolves the package information for unit and its dependencies. On success the package corresponding to unit is located via ImportPath in the Packages map of the returned value.
func (*PackageInfo) AnchorVName ¶ added in v0.0.27
AnchorVName returns a VName for the given file and offsets.
func (*PackageInfo) Emit ¶ added in v0.0.27
func (pi *PackageInfo) Emit(ctx context.Context, sink Sink, opts *EmitOptions) error
Emit generates Kythe facts and edges to represent pi, and writes them to sink. In case of errors, processing continues as far as possible before the first error encountered is reported.
func (*PackageInfo) FileVName ¶ added in v0.0.27
func (pi *PackageInfo) FileVName(file *ast.File) *spb.VName
FileVName returns a VName for path relative to the package base.
func (*PackageInfo) ObjectVName ¶ added in v0.0.27
func (pi *PackageInfo) ObjectVName(obj types.Object) *spb.VName
ObjectVName returns a VName for obj relative to that of its package.
func (*PackageInfo) Signature ¶
func (pi *PackageInfo) Signature(obj types.Object) string
Signature returns a signature for obj, suitable for use in a vname.
func (*PackageInfo) Span ¶ added in v0.0.21
Span returns the containing file and 0-based offset range of the given AST node. The range is half-open, including the start position but excluding the end.
If node == nil or lacks a valid start position, Span returns nil -1, -1. If the end position of node is invalid, start == end.
func (*PackageInfo) String ¶
func (pi *PackageInfo) String() string
String renders a human-readable synopsis of the package information.
type ResolveOptions ¶ added in v0.0.27
type ResolveOptions struct { // Passes a value whose non-nil map fields will be filled in by the type // checker during resolution. The value will also be copied to the Info // field of the PackageInfo returned by Resolve. Info *types.Info // If set, this function is called for each required input to check whether // it contains metadata rules. // // Valid return are: // rs, nil -- a valid ruleset // nil, nil -- no ruleset found // _, err -- an error attempting to load a ruleset // CheckRules func(ri *apb.CompilationUnit_FileInput, f Fetcher) (*Ruleset, error) }
ResolveOptions control the behaviour of the Resolve function. A nil options pointer provides default values.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
go_example
Program go_example runs the Kythe Go indexer on a single package consisting of files named on the command line, for use in verifying schema examples.
|
Program go_example runs the Kythe Go indexer on a single package consisting of files named on the command line, for use in verifying schema examples. |
go_indexer
Program go_indexer implements a Kythe indexer for the Go language.
|
Program go_indexer implements a Kythe indexer for the Go language. |