Documentation
¶
Index ¶
Constants ¶
const ( FallbackTimeout = "timeout" FallbackLarge = "large" FallbackGenerated = "generated" FallbackMinified = "minified" )
Fallback reasons recorded on FileInfo.Fallback and in the scan report.
Variables ¶
This section is empty.
Functions ¶
func IsDataLanguage ¶ added in v0.5.0
IsDataLanguage reports whether lang is config or build data, which should not decide a project's or module's primary language.
Types ¶
type Cache ¶ added in v0.5.0
Cache stores parse results keyed by a content-and-path hash so unchanged files skip parsing on the next run.
type FileInfo ¶
type FileInfo struct {
Path string `json:"path"`
Language string `json:"language"`
Imports []string `json:"imports,omitempty"`
Exports []string `json:"exports,omitempty"`
TypeDefs map[string]string `json:"type_defs,omitempty"` // type name -> brief definition
LineCount int `json:"line_count"`
IsEntrypoint bool `json:"is_entrypoint,omitempty"`
Fallback string `json:"fallback,omitempty"` // why tree-sitter was skipped, see limits.go
}
FileInfo holds the result of parsing a source file.
func ParseAll ¶
ParseAll parses multiple files and returns all results. Errors from individual files are collected and non-fatal.
func ParseContent ¶ added in v0.5.0
ParseContent runs the registered parsers on in-memory content. A panic in any parser is converted into an error so one bad file cannot kill a scan.
func ParseContentWith ¶ added in v0.5.0
ParseContentWith is ParseContent under cost limits.
type GenericParser ¶
type GenericParser struct{}
GenericParser is a fallback parser that identifies languages by file extension but does not perform import/export analysis.
func (*GenericParser) CanParse ¶
func (g *GenericParser) CanParse(_ string) bool
CanParse always returns true — the generic parser handles any file.
type GoParser ¶
type GoParser struct{}
GoParser parses Go source files using the stdlib go/parser + go/ast.
type Limits ¶ added in v0.5.0
type Limits struct {
ParseTimeout time.Duration // wall-clock budget per file
MaxBytes int64 // largest file given to tree-sitter
MaxLineLen int // longest line before a file counts as minified or generated
Generated bool // route files marked as generated code to the lightweight path
}
Limits bound the cost of structural (tree-sitter) parsing. Files that exceed them are indexed with the lightweight generic parser instead, so one huge or pathological file cannot stall or bloat a whole scan. Zero disables a limit.
type PanicError ¶ added in v0.5.0
PanicError reports a recovered parser panic.
func (*PanicError) Error ¶ added in v0.5.0
func (e *PanicError) Error() string
type Parser ¶
type Parser interface {
CanParse(filename string) bool
Parse(path string, content []byte) (*FileInfo, error)
}
Parser extracts structured information from a source file.
type PoolOptions ¶ added in v0.5.0
type PoolOptions struct {
Root string // files are read from Root/<rel>
Workers int // pool size; values below 1 mean 1
MaxFileSize int64 // content larger than this is rejected (race with growth); 0 disables
Cache Cache // optional
// Visit sees each file's bytes once, inside the worker, so callers can
// extract extra data without keeping every file in memory. It must be
// safe for concurrent use.
Visit func(rel string, content []byte)
// MemoryBudget caps the estimated working set of concurrent tree-sitter
// parses, in bytes. One file larger than the budget still runs, alone.
// 0 disables the cap.
MemoryBudget int64
// Limits routes expensive files to the lightweight parser.
Limits Limits
// contains filtered or unexported fields
}
PoolOptions configures ScanFiles.
type Scanned ¶ added in v0.5.0
type Scanned struct {
Path string
Info *FileInfo
Leaf []byte // sha256(path || content), the Merkle leaf and cache key
Err error
Cached bool
Panicked bool
Dur time.Duration // parse time, zero for cache hits
}
Scanned is the per-file outcome of ScanFiles.
func ScanFiles ¶ added in v0.5.0
func ScanFiles(files []string, o PoolOptions) []Scanned
ScanFiles parses files with a bounded worker pool. At most Workers file bodies are in memory at once. Results are returned in input order, so output does not depend on scheduling.
type TreeSitterParser ¶ added in v0.2.0
type TreeSitterParser struct{}
TreeSitterParser uses tree-sitter ASTs to extract structured info from source files. Handles all languages that have tree-sitter grammars, except Go (which uses stdlib AST).
func (*TreeSitterParser) CanParse ¶ added in v0.2.0
func (p *TreeSitterParser) CanParse(filename string) bool
func (*TreeSitterParser) Parse ¶ added in v0.2.0
func (p *TreeSitterParser) Parse(path string, content []byte) (*FileInfo, error)
func (*TreeSitterParser) ParseWithTimeout ¶ added in v0.5.0
func (p *TreeSitterParser) ParseWithTimeout(path string, content []byte, timeout time.Duration) (*FileInfo, error)
ParseWithTimeout is Parse with a wall-clock budget. When the budget runs out the partial tree is discarded and the file gets the generic parser's result, marked with FallbackTimeout.
Source Files
¶
- datarun.go
- generic.go
- golang.go
- limits.go
- parser.go
- pool.go
- treesitter.go
- ts_build.go
- ts_c.go
- ts_clojure.go
- ts_common.go
- ts_config.go
- ts_csharp.go
- ts_dart.go
- ts_elixir.go
- ts_elm.go
- ts_erlang.go
- ts_fortran.go
- ts_fsharp.go
- ts_gdscript.go
- ts_gleam.go
- ts_groovy.go
- ts_haskell.go
- ts_hcl.go
- ts_java.go
- ts_julia.go
- ts_kotlin.go
- ts_lua.go
- ts_nim.go
- ts_objc.go
- ts_ocaml.go
- ts_perl.go
- ts_php.go
- ts_powershell.go
- ts_proto.go
- ts_python.go
- ts_r.go
- ts_ruby.go
- ts_rust.go
- ts_scala.go
- ts_sfc.go
- ts_shell.go
- ts_solidity.go
- ts_sql.go
- ts_swift.go
- ts_typescript.go
- ts_zig.go