symbols

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package symbols provides symbol extraction and caching.

Package symbols provides a unified symbol extraction service.

Package symbols provides symbol extraction using Tree-sitter for accurate AST parsing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheEntry

type CacheEntry struct {
	Symbol

	RepoID    int64
	CommitSHA string
	CreatedAt time.Time
}

CacheEntry represents a cached symbol with metadata.

type Service

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

Service provides symbol extraction with caching.

func NewService

func NewService(cacheDir string) (*Service, error)

NewService creates a new symbol service.

func NewServiceWithoutCache

func NewServiceWithoutCache() *Service

NewServiceWithoutCache creates a symbol service without caching (useful for testing).

func (*Service) Close

func (s *Service) Close() error

Close closes the service and releases resources.

func (*Service) ExtractSymbols

func (s *Service) ExtractSymbols(
	ctx context.Context,
	repoID int64,
	filePath, commitSHA string,
	code []byte,
	language string,
) ([]Symbol, error)

ExtractSymbols extracts symbols from code, using cache when available.

func (*Service) GetSymbolAtPosition

func (s *Service) GetSymbolAtPosition(
	ctx context.Context,
	code []byte,
	language string,
	line, col int,
) (*Symbol, error)

GetSymbolAtPosition returns the symbol at a specific position.

func (*Service) InvalidateFile

func (s *Service) InvalidateFile(ctx context.Context, repoID int64, filePath string) error

InvalidateFile invalidates cached symbols for a file.

func (*Service) InvalidateRepo

func (s *Service) InvalidateRepo(ctx context.Context, repoID int64) error

InvalidateRepo invalidates all cached symbols for a repository.

func (*Service) IsLanguageSupported

func (s *Service) IsLanguageSupported(language string) bool

IsLanguageSupported checks if Tree-sitter supports a language.

func (*Service) SearchSymbols

func (s *Service) SearchSymbols(
	ctx context.Context,
	repoID int64,
	query, kind string,
	limit int,
) ([]Symbol, error)

SearchSymbols searches for symbols in a repository's cache.

func (*Service) Stats

func (s *Service) Stats(ctx context.Context, repoID int64) (map[string]any, error)

Stats returns cache statistics.

func (*Service) SupportedLanguages

func (s *Service) SupportedLanguages() []string

SupportedLanguages returns the list of supported languages.

type Symbol

type Symbol struct {
	Name      string `json:"name"`
	Kind      string `json:"kind"` // function, class, method, struct, interface, etc.
	Line      int    `json:"line"`
	Column    int    `json:"column"`
	EndLine   int    `json:"endLine,omitempty"`
	EndColumn int    `json:"endColumn,omitempty"`
	Signature string `json:"signature,omitempty"`
	Parent    string `json:"parent,omitempty"`
	FilePath  string `json:"filePath,omitempty"`
}

Symbol represents a code symbol (function, class, method, etc.)

type SymbolCache

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

SymbolCache provides SQLite-based caching for extracted symbols.

func NewSymbolCache

func NewSymbolCache(cacheDir string) (*SymbolCache, error)

NewSymbolCache creates a new symbol cache with the specified cache directory.

func (*SymbolCache) Close

func (c *SymbolCache) Close() error

Close closes all database connections.

func (*SymbolCache) GetSymbols

func (c *SymbolCache) GetSymbols(
	ctx context.Context,
	repoID int64,
	filePath, commitSHA string,
) ([]Symbol, bool, error)

GetSymbols retrieves cached symbols for a file.

func (*SymbolCache) InvalidateFile

func (c *SymbolCache) InvalidateFile(ctx context.Context, repoID int64, filePath string) error

InvalidateFile removes cached symbols for a file.

func (*SymbolCache) InvalidateRepo

func (c *SymbolCache) InvalidateRepo(ctx context.Context, repoID int64) error

InvalidateRepo clears all cached symbols for a repository.

func (*SymbolCache) SearchSymbols

func (c *SymbolCache) SearchSymbols(
	ctx context.Context,
	repoID int64,
	query string,
	kind string,
	limit int,
) ([]Symbol, error)

SearchSymbols searches for symbols by name across all files in a repo.

func (*SymbolCache) SetSymbols

func (c *SymbolCache) SetSymbols(
	ctx context.Context,
	repoID int64,
	filePath, commitSHA string,
	symbols []Symbol,
) error

SetSymbols stores symbols in the cache.

func (*SymbolCache) Stats

func (c *SymbolCache) Stats(ctx context.Context, repoID int64) (map[string]any, error)

Stats returns cache statistics for a repository.

type TreeSitterService

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

TreeSitterService provides AST-based symbol extraction.

func NewTreeSitterService

func NewTreeSitterService() *TreeSitterService

NewTreeSitterService creates a new Tree-sitter service with supported languages.

func (*TreeSitterService) ExtractSymbols

func (s *TreeSitterService) ExtractSymbols(
	ctx context.Context,
	code []byte,
	lang string,
) ([]Symbol, error)

ExtractSymbols extracts symbols from source code using Tree-sitter.

func (*TreeSitterService) GetSymbolAtPosition

func (s *TreeSitterService) GetSymbolAtPosition(
	ctx context.Context,
	code []byte,
	lang string,
	line, col int,
) (*Symbol, error)

GetSymbolAtPosition returns the symbol at a specific line and column.

func (*TreeSitterService) IsSupported

func (s *TreeSitterService) IsSupported(lang string) bool

IsSupported checks if a language has Tree-sitter support.

func (*TreeSitterService) SupportedLanguages

func (s *TreeSitterService) SupportedLanguages() []string

SupportedLanguages returns the list of languages with Tree-sitter support.

Jump to

Keyboard shortcuts

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