discovery

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package discovery handles code unit discovery and indexing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangedFiles

func ChangedFiles(root, ref1, ref2 string) ([]string, error)

ChangedFiles returns files changed between two git refs (or working tree if ref2 is empty).

func DeduplicateFileLevel

func DeduplicateFileLevel(units []domain.Unit) []domain.Unit

DeduplicateFileLevel removes file-level units when symbol-level units exist for the same file from a language adapter.

func DetectedAdapters

func DetectedAdapters(langs []LanguageInfo) []string

DetectedAdapters returns the unique adapter names needed for detected languages.

func FilterByPaths

func FilterByPaths(units []domain.Unit, paths []string) []domain.Unit

FilterByPaths returns units whose paths match any of the given path prefixes.

func FilterChanged

func FilterChanged(units []domain.Unit, changedFiles []string) []domain.Unit

FilterChanged returns only units whose paths appear in the changed files list.

func Merge

func Merge(lists ...UnitList) []domain.Unit

Merge combines multiple unit lists, deduplicating by UnitID string. When duplicate IDs exist, the more specific type wins (function > file).

func Scanners added in v0.2.0

func Scanners() map[string]Scanner

Scanners returns a registry mapping adapter names to Scanner implementations. Use this for polymorphic dispatch instead of switch statements on adapter names. GenericScanner is excluded because it requires config params and always runs unconditionally.

Languages with a registered analysis.Analyzer get tree-sitter-backed discovery (full AST, symbol-level units). Languages without fall back to regex or file-level.

Types

type AnalysisAdapter added in v0.11.0

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

AnalysisAdapter discovers code units using the analysis.Analyzer interface. This replaces language-specific regex adapters with tree-sitter-backed discovery.

func NewAnalysisAdapter added in v0.11.0

func NewAnalysisAdapter(lang string, extensions []string) *AnalysisAdapter

NewAnalysisAdapter creates a discovery adapter backed by an Analyzer.

func (*AnalysisAdapter) Scan added in v0.11.0

func (a *AnalysisAdapter) Scan(root string) ([]domain.Unit, error)

Scan discovers all code units for this language.

type DiffResult

type DiffResult struct {
	Added     []domain.Unit
	Removed   []domain.Unit
	Unchanged []domain.Unit
}

DiffResult represents changes between two index snapshots.

func Diff

func Diff(old, new_ *Index) DiffResult

Diff computes the difference between an old and new index.

type GenericScanner

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

GenericScanner discovers all files as file-level units.

func NewGenericScanner

func NewGenericScanner(include, exclude []string) *GenericScanner

NewGenericScanner creates a scanner with include/exclude patterns.

func (*GenericScanner) Scan

func (s *GenericScanner) Scan(root string) ([]domain.Unit, error)

Scan walks the directory tree and returns file-level units.

type GoAdapter

type GoAdapter struct{}

GoAdapter discovers Go code units using go/ast.

func NewGoAdapter

func NewGoAdapter() *GoAdapter

NewGoAdapter creates a new Go discovery adapter.

func (*GoAdapter) Scan

func (a *GoAdapter) Scan(root string) ([]domain.Unit, error)

Scan discovers Go functions, methods, and types in .go files.

type Index

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

Index holds a snapshot of discovered code units.

func LoadIndex

func LoadIndex(path string) (*Index, error)

LoadIndex reads an index from a JSON file.

func NewIndex

func NewIndex(units []domain.Unit) *Index

NewIndex creates an Index from a slice of units.

func (*Index) Save

func (idx *Index) Save(path string) error

Save writes the index to a JSON file.

func (*Index) Units

func (idx *Index) Units() []domain.Unit

Units returns the units in this index.

type LanguageInfo

type LanguageInfo struct {
	Name      string // "go", "typescript", "python", etc.
	FileCount int
	HasConfig bool   // go.mod, package.json, pyproject.toml, etc.
	Adapter   string // "go", "ts", "generic"
}

LanguageInfo describes a detected language in a repository.

func DetectLanguages

func DetectLanguages(root string) []LanguageInfo

DetectLanguages walks a directory and detects programming languages present.

type MovedFile

type MovedFile struct {
	OldPath string
	NewPath string
}

MovedFile represents a file rename detected by git.

func DetectMoves

func DetectMoves(root string) ([]MovedFile, error)

DetectMoves identifies likely file renames between old and new unit lists. Uses git's rename detection when available, falls back to symbol matching.

type Scanner

type Scanner interface {
	// Scan discovers all code units under the given root directory.
	Scan(root string) ([]domain.Unit, error)
}

Scanner discovers certifiable code units in a repository.

type TSAdapter

type TSAdapter struct{}

TSAdapter discovers TypeScript symbols using regex patterns.

func NewTSAdapter

func NewTSAdapter() *TSAdapter

NewTSAdapter creates a new TypeScript discovery adapter.

func (*TSAdapter) Scan

func (a *TSAdapter) Scan(root string) ([]domain.Unit, error)

Scan discovers exported TypeScript symbols in .ts/.tsx files.

type UnitList

type UnitList = []domain.Unit

UnitList is a convenience alias for a slice of units.

Jump to

Keyboard shortcuts

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