index

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 27, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package index provides a unified code indexer with signature-based lookup, inspired by ATLANTIS's multi-tier code retrieval approach.

Key features: - Fast O(1) lookup of functions, classes, and methods - Signature-based matching (partial name, parameter patterns) - Cross-file reference resolution - Definition-usage linking - LRU caching for performance - Glob pattern matching for bulk queries

Index

Constants

View Source
const (
	SymbolFunction  = constants.SymbolFunction
	SymbolMethod    = constants.SymbolMethod
	SymbolClass     = constants.SymbolClass
	SymbolInterface = constants.SymbolInterface
	SymbolVariable  = constants.SymbolVariable
	SymbolConstant  = constants.SymbolConstant
	SymbolProperty  = constants.SymbolProperty
	SymbolParameter = constants.SymbolParameter
)

Re-export SymbolType constants for backward compatibility

Variables

This section is empty.

Functions

This section is empty.

Types

type Indexer

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

Indexer provides fast symbol lookup and cross-reference

func NewIndexer

func NewIndexer() *Indexer

NewIndexer creates a new code indexer

func (*Indexer) AddReference

func (idx *Indexer) AddReference(symbolID string, ref Reference)

AddReference adds a reference to a symbol

func (*Indexer) AddSymbol

func (idx *Indexer) AddSymbol(sym *Symbol)

AddSymbol adds a symbol to the index

func (*Indexer) Clear

func (idx *Indexer) Clear()

Clear clears the entire index

func (*Indexer) FindDefinition

func (idx *Indexer) FindDefinition(filePath string, line int, name string) *Symbol

FindDefinition finds the definition of a symbol referenced at a location

func (*Indexer) FindUsages

func (idx *Indexer) FindUsages(symbolID string) []Reference

FindUsages finds all usages of a symbol

func (*Indexer) GetAllClasses

func (idx *Indexer) GetAllClasses() []*Symbol

GetAllClasses returns all indexed classes

func (*Indexer) GetAllFunctions

func (idx *Indexer) GetAllFunctions() []*Symbol

GetAllFunctions returns all indexed functions

func (*Indexer) GetByName

func (idx *Indexer) GetByName(name string) []*Symbol

GetByName retrieves all symbols with a given name

func (*Indexer) GetClass

func (idx *Indexer) GetClass(name string) *Symbol

GetClass retrieves a class by name

func (*Indexer) GetFunction

func (idx *Indexer) GetFunction(name string) []*Symbol

GetFunction retrieves functions by name

func (*Indexer) GetMethod

func (idx *Indexer) GetMethod(className, methodName string) *Symbol

GetMethod retrieves a method by class and method name

func (*Indexer) GetReferences

func (idx *Indexer) GetReferences(symbolID string) []Reference

GetReferences retrieves all references to a symbol

func (*Indexer) GetSymbol

func (idx *Indexer) GetSymbol(id string) *Symbol

GetSymbol retrieves a symbol by ID

func (*Indexer) GetSymbolsInFile

func (idx *Indexer) GetSymbolsInFile(filePath string) []*Symbol

GetSymbolsInFile retrieves all symbols in a file

func (*Indexer) Search

func (idx *Indexer) Search(query *SearchQuery) []*SearchResult

Search performs a search query against the index

func (*Indexer) Stats

func (idx *Indexer) Stats() map[string]int

Stats returns indexer statistics

type Reference

type Reference struct {
	FilePath string `json:"file_path"`
	Line     int    `json:"line"`
	Column   int    `json:"column"`
	Context  string `json:"context,omitempty"` // Surrounding code
	RefType  string `json:"ref_type"`          // call, assignment, import, etc.
}

Reference represents a usage of a symbol

type SearchQuery

type SearchQuery struct {
	Name         string     // Exact or partial name
	NamePattern  string     // Regex pattern for name
	Type         SymbolType // Filter by type
	ClassName    string     // Filter by class
	FilePath     string     // Filter by file
	FilePattern  string     // Glob pattern for files
	Language     string     // Filter by language
	HasParameter string     // Has parameter matching this name
	ReturnType   string     // Filter by return type
	Limit        int        // Max results (0 = unlimited)
}

SearchQuery represents a search query

type SearchResult

type SearchResult struct {
	Symbol    *Symbol `json:"symbol"`
	Score     float64 `json:"score"`      // Match quality score
	MatchedBy string  `json:"matched_by"` // What matched (name, signature, etc.)
}

SearchResult represents a search result

type Symbol

type Symbol struct {
	ID        string     `json:"id"`   // Unique identifier
	Name      string     `json:"name"` // Symbol name
	Type      SymbolType `json:"type"`
	FilePath  string     `json:"file_path"`
	Line      int        `json:"line"`
	Column    int        `json:"column"`
	EndLine   int        `json:"end_line"`
	EndColumn int        `json:"end_column"`

	// For functions/methods
	Signature  string   `json:"signature,omitempty"`   // Full signature
	Parameters []string `json:"parameters,omitempty"`  // Parameter names
	ParamTypes []string `json:"param_types,omitempty"` // Parameter types
	ReturnType string   `json:"return_type,omitempty"`

	// For methods/properties
	ClassName  string `json:"class_name,omitempty"`
	Visibility string `json:"visibility,omitempty"` // public/private/protected
	IsStatic   bool   `json:"is_static,omitempty"`

	// Metadata
	Language    string   `json:"language"`
	DocComment  string   `json:"doc_comment,omitempty"`
	Annotations []string `json:"annotations,omitempty"`

	// References
	References []Reference `json:"references,omitempty"`
}

Symbol represents an indexed code symbol

type SymbolType

type SymbolType = constants.SymbolType

SymbolType represents the type of a code symbol Re-exported from pkg/sources/constants for backward compatibility

Jump to

Keyboard shortcuts

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