Documentation
¶
Index ¶
- Constants
- Variables
- func ExtID(lang, module, name string) string
- func FileID(path string) string
- func ModID(lang, module string) string
- func Outline(src []byte, filename string) (string, bool)
- func SetParseTimeout(d time.Duration)
- func Supported(filename string) bool
- func SupportedSource(src []byte, filename string) bool
- func SymID(path string, start uint32) string
- func Tree(paths []string) string
- type Argument
- type Call
- type DispatchKind
- type Edge
- type File
- type Graph
- func (g *Graph) Affected(seeds []string, opts TraverseOptions) []Path
- func (g *Graph) Callees(id string) []Edge
- func (g *Graph) Callers(id string) []Edge
- func (g *Graph) Def(name string) []Node
- func (g *Graph) In(id string) []Edge
- func (g *Graph) JSON(w io.Writer) error
- func (g *Graph) Node(id string) *Node
- func (g *Graph) Out(id string) []Edge
- func (g *Graph) Path(from, to string, opts TraverseOptions) Path
- func (g *Graph) Text(w io.Writer, ids []string, budget int, allow func(Edge) bool) error
- type Import
- type ImportKind
- type Name
- type Node
- type Options
- type PackageHint
- type Path
- type ReceiverKind
- type Ref
- type ResolutionHints
- type Result
- type Symbol
- type TraverseOptions
Constants ¶
const ( KindFile = "file" KindModule = "module" KindExternal = "external" KindFunc = "func" KindType = "type" KindClass = "class" KindConst = "const" KindVar = "var" )
Node kinds.
const ( RelContains = "contains" RelImports = "imports" RelLoads = "loads" RelCalls = "calls" RelReferences = "references" RelInherits = "inherits" RelEmbeds = "embeds" RelReexports = "reexports" )
Edge relations.
const ( ConfExtracted = "extracted" ConfInferred = "inferred" )
Edge confidence.
const DefaultParseTimeout = time.Second
DefaultParseTimeout caps how long the parser will spend on a single file. Past this point the file is treated as unsupported and falls through as raw content. Pathological inputs (large table-driven test files, generated parser tables) can otherwise dominate runtime.
const SchemaVersion = 2
SchemaVersion is bumped whenever Node, Edge, or Graph change in a way a reader must understand.
const Separator = "⋮----"
Variables ¶
var ToolVersion = "dev"
ToolVersion is stamped into every emitted graph.
Functions ¶
func Outline ¶
Outline reduces source to a structural skeleton: declarations, signatures and comments are kept, function bodies are dropped. Returns the outline and true if the file's language is supported, otherwise "", false.
func SetParseTimeout ¶
SetParseTimeout overrides the per-file parse timeout. Must be called before the first Outline or Pack call; later calls are ignored once a language pool has been created. A zero duration disables the timeout.
func SupportedSource ¶ added in v0.2.3
SupportedSource reports whether Outline can detect the language of source.
Types ¶
type Argument ¶ added in v0.2.3
type Argument struct {
Kind string `json:"kind"`
Text string `json:"text"`
Start uint32 `json:"start"`
End uint32 `json:"end"`
}
Argument is one source argument to a call.
type Call ¶ added in v0.2.3
type Call struct {
Receiver string `json:"receiver,omitempty"`
ReceiverKind ReceiverKind `json:"receiver_kind"`
Name string `json:"name"`
Dispatch DispatchKind `json:"dispatch"`
Arguments []Argument `json:"arguments,omitempty"`
Line int `json:"line"`
Start uint32 `json:"start"`
End uint32 `json:"end"`
In int `json:"-"`
}
Call is one call site. In refers to the innermost enclosing declaration during graph construction and is omitted from JSON.
type DispatchKind ¶ added in v0.2.3
type DispatchKind string
DispatchKind describes how a call reaches its target.
const ( DispatchDirect DispatchKind = "direct" DispatchSubshell DispatchKind = "subshell" )
type Edge ¶ added in v0.2.3
type Edge struct {
From string `json:"from"`
To string `json:"to"`
Rel string `json:"rel"`
Conf string `json:"conf"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Operation string `json:"operation,omitempty"`
Call *Call `json:"call,omitempty"`
}
Edge is one directed relationship between two nodes.
type File ¶
type File struct {
Path string
Content string
Language string
Outlined bool
Symbols []Symbol // populated when Outlined is true
Size int64
Skipped string // reason content was omitted, e.g. "binary", "too-large"
}
File is one packed file.
type Graph ¶ added in v0.2.3
type Graph struct {
SchemaVersion int `json:"schema_version"`
ToolVersion string `json:"tool_version"`
SourceDigest string `json:"source_digest"`
Complete bool `json:"complete"`
Warnings []string `json:"warnings,omitempty"`
Nodes []Node `json:"nodes"`
Edges []Edge `json:"edges"`
// contains filtered or unexported fields
}
Graph is a whole-repository code graph.
func Build ¶ added in v0.2.3
Build walks root, analyses every supported source file, resolves cross-file references for supported languages, and returns a Graph.
func (*Graph) Affected ¶ added in v0.2.3
func (g *Graph) Affected(seeds []string, opts TraverseOptions) []Path
Affected walks the graph in reverse from each seed and returns one evidence path per reached node. The default relation set is RelCalls, so with default options this is the transitive caller set.
func (*Graph) Def ¶ added in v0.2.3
Def returns nodes whose Name or Qualified exactly matches name, or whose ID is name.
func (*Graph) Path ¶ added in v0.2.3
func (g *Graph) Path(from, to string, opts TraverseOptions) Path
Path returns the shortest forward edge chain from from to to under opts, or nil if none exists.
type Import ¶ added in v0.2.0
type Import struct {
Module string
Kind ImportKind
Names []Name
Form string
Relative bool
Line int
}
Import is one source import form. A statement containing more than one form, such as a JavaScript default plus named import, produces one Import value for each form. Form and Relative retain language-specific loading details when they affect graph construction.
type ImportKind ¶ added in v0.2.0
type ImportKind string
ImportKind identifies the source-language form of an import.
const ( // ImportNamed imports one or more named exports. ImportNamed ImportKind = "named" // ImportDefault imports a default export. ImportDefault ImportKind = "default" // ImportNamespace imports a module namespace. ImportNamespace ImportKind = "namespace" // ImportModule binds a module object using the language's module form. ImportModule ImportKind = "module" // ImportSideEffect loads a module without binding a local name. ImportSideEffect ImportKind = "side-effect" // ImportWildcard imports every exported name. ImportWildcard ImportKind = "wildcard" )
type Name ¶ added in v0.2.0
Name is one named import and its optional local alias. ImportDefault, ImportNamespace, and ImportModule use Alias for a local binding declared by the source syntax.
type Node ¶ added in v0.2.3
type Node struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
Qualified string `json:"qualified,omitempty"`
File string `json:"file,omitempty"`
Line int `json:"line,omitempty"`
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
Exported bool `json:"exported,omitempty"`
Sig string `json:"sig,omitempty"`
}
Node is one graph vertex. IDs are opaque and produced only by the id encoder helpers below.
type Options ¶
type Options struct {
// MaxFileSize is the per-file byte limit. Files larger than this are
// listed in the tree but their content is omitted. Zero means 1MB.
MaxFileSize int64
// MaxFiles caps the number of files read. Zero means 10000.
MaxFiles int
// Compress applies tree-sitter outlining to supported source files.
// When false, full file contents are kept.
Compress bool
// Ignore adds gitignore-syntax patterns on top of .gitignore and the
// built-in defaults.
Ignore []string
// Concurrency is the number of files processed in parallel.
// Zero means runtime.NumCPU().
Concurrency int
// Resolution supplies caller-provided source roots and package hints
// for graph module resolution. Pack ignores it.
Resolution ResolutionHints
}
Options configures Pack.
type PackageHint ¶ added in v0.2.3
PackageHint maps an installed distribution to the import names it provides, for ecosystems where the two differ.
type Path ¶ added in v0.2.3
type Path []Edge
Path is an ordered chain of edges from a seed to a reached node.
type ReceiverKind ¶ added in v0.2.3
type ReceiverKind string
ReceiverKind describes the syntax used to select a call receiver.
const ( ReceiverBare ReceiverKind = "bare" ReceiverConstant ReceiverKind = "constant" ReceiverLocal ReceiverKind = "local" ReceiverSelf ReceiverKind = "self" ReceiverExpression ReceiverKind = "expression" )
type ResolutionHints ¶ added in v0.2.3
type ResolutionHints struct {
SourceRoots []string
Ecosystems []string
Packages []PackageHint
}
ResolutionHints carries caller-supplied context that improves module resolution beyond what the repository files alone reveal.
type Result ¶
Result is the output of Pack.
func Pack ¶
Pack walks root, reads text files that survive gitignore and default filtering, optionally outlines them, and returns the collected result.
type Symbol ¶ added in v0.2.0
type Symbol struct {
Name string
Kind string // func, type, class, const, or var
Line int // one-based source line
Exported bool
}
Symbol is a top-level declaration captured while outlining a file.
type TraverseOptions ¶ added in v0.2.3
type TraverseOptions struct {
// Depth caps hop distance. Zero means unbounded.
Depth int
// Relations restricts which edge relations are followed. Nil means
// RelCalls only.
Relations []string
// IncludeInferred follows inferred-confidence edges as well as
// extracted ones. Extracted edges are always followed.
IncludeInferred bool
}
TraverseOptions filters graph traversal.
func (TraverseOptions) Allow ¶ added in v0.2.3
func (o TraverseOptions) Allow(e Edge) bool
Allow reports whether e passes the relation and confidence filter.