trace

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package trace provides symbol extraction and call graph analysis for code navigation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsKeyword

func IsKeyword(name string, lang string) bool

IsKeyword checks if a name is a language keyword.

func SupportedExtensions

func SupportedExtensions() []string

SupportedExtensions returns all supported file extensions.

Types

type CallEdge

type CallEdge struct {
	Caller   string `json:"caller"`
	Callee   string `json:"callee"`
	File     string `json:"file"`
	Line     int    `json:"line"`
	CallType string `json:"call_type,omitempty"`
}

CallEdge represents a caller -> callee relationship.

type CallGraph

type CallGraph struct {
	Root  string            `json:"root"`
	Nodes map[string]Symbol `json:"nodes"`
	Edges []CallEdge        `json:"edges"`
	Depth int               `json:"depth"`
}

CallGraph represents a multi-level call graph.

type CallSite

type CallSite struct {
	File    string `json:"file"`
	Line    int    `json:"line"`
	Context string `json:"context"`
}

CallSite represents the location of a function call.

type CalleeInfo

type CalleeInfo struct {
	Symbol   Symbol   `json:"symbol"`
	CallSite CallSite `json:"call_site"`
}

CalleeInfo represents a function called by the target.

type CallerInfo

type CallerInfo struct {
	Symbol   Symbol   `json:"symbol"`
	CallSite CallSite `json:"call_site"`
}

CallerInfo represents a function that calls the target.

type GOBSymbolStore

type GOBSymbolStore struct {
	// contains filtered or unexported fields
}

GOBSymbolStore implements SymbolStore using GOB encoding.

func NewGOBSymbolStore

func NewGOBSymbolStore(indexPath string) *GOBSymbolStore

NewGOBSymbolStore creates a new GOB-based symbol store.

func (*GOBSymbolStore) Close

func (s *GOBSymbolStore) Close() error

Close shuts down the store.

func (*GOBSymbolStore) DeleteFile

func (s *GOBSymbolStore) DeleteFile(ctx context.Context, filePath string) error

DeleteFile removes all symbols and references for a file.

func (*GOBSymbolStore) GetCallGraph

func (s *GOBSymbolStore) GetCallGraph(ctx context.Context, symbolName string, depth int) (*CallGraph, error)

GetCallGraph builds a call graph from a starting symbol.

func (*GOBSymbolStore) GetStats

func (s *GOBSymbolStore) GetStats(ctx context.Context) (*SymbolStats, error)

GetStats returns statistics about the symbol index.

func (*GOBSymbolStore) IsFileIndexed

func (s *GOBSymbolStore) IsFileIndexed(filePath string) bool

IsFileIndexed checks if a file has been indexed.

func (*GOBSymbolStore) Load

func (s *GOBSymbolStore) Load(ctx context.Context) error

Load reads the index from storage.

func (*GOBSymbolStore) LookupCallees

func (s *GOBSymbolStore) LookupCallees(ctx context.Context, symbolName string, file string) ([]Reference, error)

LookupCallees finds all symbols called by a function.

func (*GOBSymbolStore) LookupCallers

func (s *GOBSymbolStore) LookupCallers(ctx context.Context, symbolName string) ([]Reference, error)

LookupCallers finds all references/callers of a symbol.

func (*GOBSymbolStore) LookupSymbol

func (s *GOBSymbolStore) LookupSymbol(ctx context.Context, name string) ([]Symbol, error)

LookupSymbol finds symbol definitions by name.

func (*GOBSymbolStore) Persist

func (s *GOBSymbolStore) Persist(ctx context.Context) error

Persist writes the index to storage.

func (*GOBSymbolStore) SaveFile

func (s *GOBSymbolStore) SaveFile(ctx context.Context, filePath string, symbols []Symbol, refs []Reference) error

SaveFile persists symbols and references for a file.

type LanguagePatterns

type LanguagePatterns struct {
	Extension    string
	Language     string
	Functions    []*regexp.Regexp
	Methods      []*regexp.Regexp
	Classes      []*regexp.Regexp
	Interfaces   []*regexp.Regexp
	Types        []*regexp.Regexp
	FunctionCall *regexp.Regexp
	MethodCall   *regexp.Regexp
}

LanguagePatterns holds regex patterns for a specific language.

func GetPatternsForLanguage

func GetPatternsForLanguage(ext string) *LanguagePatterns

GetPatternsForLanguage returns patterns for a file extension.

type Reference

type Reference struct {
	SymbolName string `json:"symbol_name"`
	File       string `json:"file"`
	Line       int    `json:"line"`
	Column     int    `json:"column,omitempty"`
	Context    string `json:"context"`
	CallerName string `json:"caller_name"`
	CallerFile string `json:"caller_file"`
	CallerLine int    `json:"caller_line"`
}

Reference represents a usage/call of a symbol.

type RegexExtractor

type RegexExtractor struct {
	// contains filtered or unexported fields
}

RegexExtractor implements SymbolExtractor using regex patterns.

func NewRegexExtractor

func NewRegexExtractor() (*RegexExtractor, error)

NewRegexExtractor creates a new regex-based symbol extractor. Returns error for consistency with NewTreeSitterExtractor (always nil).

func (*RegexExtractor) ExtractAll

func (e *RegexExtractor) ExtractAll(ctx context.Context, filePath string, content string) ([]Symbol, []Reference, error)

ExtractAll extracts both symbols and references in one pass.

func (*RegexExtractor) ExtractReferences

func (e *RegexExtractor) ExtractReferences(ctx context.Context, filePath string, content string) ([]Reference, error)

ExtractReferences extracts all symbol references from a file.

func (*RegexExtractor) ExtractSymbols

func (e *RegexExtractor) ExtractSymbols(ctx context.Context, filePath string, content string) ([]Symbol, error)

ExtractSymbols extracts all symbol definitions from a file.

func (*RegexExtractor) Mode

func (e *RegexExtractor) Mode() string

Mode returns the extraction mode.

func (*RegexExtractor) SupportedLanguages

func (e *RegexExtractor) SupportedLanguages() []string

SupportedLanguages returns list of supported file extensions.

type Symbol

type Symbol struct {
	Name      string     `json:"name"`
	Kind      SymbolKind `json:"kind"`
	File      string     `json:"file"`
	Line      int        `json:"line"`
	EndLine   int        `json:"end_line,omitempty"`
	Signature string     `json:"signature,omitempty"`
	Receiver  string     `json:"receiver,omitempty"`
	Package   string     `json:"package,omitempty"`
	Exported  bool       `json:"exported,omitempty"`
	Language  string     `json:"language"`
}

Symbol represents a symbol definition in the codebase.

type SymbolExtractor

type SymbolExtractor interface {
	// ExtractSymbols extracts all symbol definitions from a file.
	ExtractSymbols(ctx context.Context, filePath string, content string) ([]Symbol, error)

	// ExtractReferences extracts all symbol references from a file.
	ExtractReferences(ctx context.Context, filePath string, content string) ([]Reference, error)

	// ExtractAll extracts both symbols and references in one pass.
	ExtractAll(ctx context.Context, filePath string, content string) ([]Symbol, []Reference, error)

	// SupportedLanguages returns list of supported file extensions.
	SupportedLanguages() []string

	// Mode returns "fast" or "precise".
	Mode() string
}

SymbolExtractor extracts symbols and references from source code.

type SymbolIndex

type SymbolIndex struct {
	Symbols    map[string][]Symbol    `json:"symbols"`
	References map[string][]Reference `json:"references"`
	CallGraph  []CallEdge             `json:"call_graph"`
	UpdatedAt  time.Time              `json:"updated_at"`
	Version    int                    `json:"version"`
}

SymbolIndex is the main index structure for symbols and references.

type SymbolKind

type SymbolKind string

SymbolKind represents the type of symbol.

const (
	KindFunction  SymbolKind = "function"
	KindMethod    SymbolKind = "method"
	KindClass     SymbolKind = "class"
	KindInterface SymbolKind = "interface"
	KindType      SymbolKind = "type"
	KindVariable  SymbolKind = "variable"
	KindConstant  SymbolKind = "constant"
)

type SymbolStats

type SymbolStats struct {
	TotalSymbols    int       `json:"total_symbols"`
	TotalReferences int       `json:"total_references"`
	TotalFiles      int       `json:"total_files"`
	IndexSize       int64     `json:"index_size"`
	LastUpdated     time.Time `json:"last_updated"`
}

SymbolStats contains index statistics.

type SymbolStore

type SymbolStore interface {
	// SaveFile persists symbols and references for a file.
	SaveFile(ctx context.Context, filePath string, symbols []Symbol, refs []Reference) error

	// DeleteFile removes all symbols and references for a file.
	DeleteFile(ctx context.Context, filePath string) error

	// LookupSymbol finds symbol definitions by name.
	LookupSymbol(ctx context.Context, name string) ([]Symbol, error)

	// LookupCallers finds all references/callers of a symbol.
	LookupCallers(ctx context.Context, symbolName string) ([]Reference, error)

	// LookupCallees finds all symbols called by a function.
	LookupCallees(ctx context.Context, symbolName string, file string) ([]Reference, error)

	// GetCallGraph builds a call graph from a starting symbol.
	GetCallGraph(ctx context.Context, symbolName string, depth int) (*CallGraph, error)

	// Load reads the index from storage.
	Load(ctx context.Context) error

	// Persist writes the index to storage.
	Persist(ctx context.Context) error

	// Close shuts down the store.
	Close() error

	// GetStats returns statistics about the symbol index.
	GetStats(ctx context.Context) (*SymbolStats, error)
}

SymbolStore persists and queries the symbol index.

type TraceResult

type TraceResult struct {
	Query   string       `json:"query"`
	Mode    string       `json:"mode"`
	Symbol  *Symbol      `json:"symbol,omitempty"`
	Callers []CallerInfo `json:"callers,omitempty"`
	Callees []CalleeInfo `json:"callees,omitempty"`
	Graph   *CallGraph   `json:"graph,omitempty"`
}

TraceResult represents the output of a trace query.

Jump to

Keyboard shortcuts

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