goparser

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTypedCallGraph

func BuildTypedCallGraph(dir string) (*callgraph.CallGraph, error)

BuildTypedCallGraph loads the Go module rooted at dir and constructs a call graph using full type information. Unlike the AST-only path, callees are resolved to their declared functions/methods, so a call such as scanner.Scan() and the declared func Scan share a single node, and standard library / third-party calls are identified precisely rather than by name.

It returns an error (so callers can fall back to the AST graph) when the module cannot be loaded or type-checked.

func BuildTypedCallGraphWithOptions added in v0.0.2

func BuildTypedCallGraphWithOptions(dir string, opts BuildOptions) (*callgraph.CallGraph, error)

BuildTypedCallGraphWithOptions is BuildTypedCallGraph with diagnostic instrumentation controlled by opts.

func CalculateCouplingScore

func CalculateCouplingScore(calls []CallInfo, allResults []*processor.Result) float64

CalculateCouplingScore computes a coupling score for a specific function.

Types

type BuildOptions added in v0.0.2

type BuildOptions struct {
	// Logf, when non-nil, receives phase-level progress and timing messages
	// (package load time, package counts, per-package walk timing, final tallies)
	// — useful for understanding why the build is slow on a large repo.
	Logf func(format string, args ...any)
	// PerPackage, when true, logs per-package walk timing and counts via Logf.
	PerPackage bool
	// TracePackages, when true, routes go/packages driver logging through Logf.
	// This surfaces every underlying `go list` invocation and its timing, which
	// is the most granular view of where the type-checking phase spends time.
	TracePackages bool
}

BuildOptions controls diagnostic instrumentation for the typed call-graph build. The zero value is silent and behaves exactly like the original build.

type CallInfo

type CallInfo struct {
	CallerName string // The name of the code that makes the call (e.g., "append")
	CalleeName string // The name/function being called
	File       string // Source file path where call occurs
	Line       int    // Line number in source
	Column     int    // Column number in source
	ParentFunc string // Name of function/method containing this call (e.g., "Process")
}

CallInfo contains information about a function call.

type CallVisitor

type CallVisitor struct {
	Calls map[string][]CallInfo // Map of callee name to list of CallInfo
	// contains filtered or unexported fields
}

CallVisitor traverses Go AST nodes and identifies all function calls.

func NewCallVisitor

func NewCallVisitor() *CallVisitor

NewCallVisitor creates a new CallVisitor instance.

func NewCallVisitorWithFileSet

func NewCallVisitorWithFileSet(fset *token.FileSet) *CallVisitor

NewCallVisitorWithFileSet creates a new CallVisitor with a specific FileSet.

func (*CallVisitor) Visit

func (v *CallVisitor) Visit(node ast.Node) ast.Visitor

Visit implements ast.Visitor interface for traversing AST nodes.

type Processor

type Processor struct {
	ExcludeGenerated bool
}

Processor implements processor.Processor for Go source files.

func (*Processor) Process

func (p *Processor) Process(ctx context.Context, path string, src []byte) (*processor.Result, error)

Process parses the Go source and extracts API surface.

func (*Processor) Supports

func (p *Processor) Supports(ext string) bool

Supports returns true for .go extension.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL