Documentation
¶
Index ¶
- Variables
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Get(key string) *CachedParse
- func (c *Cache) MemoryUsage() int64
- func (c *Cache) Put(key string, data *CachedParse)
- func (c *Cache) Remove(key string)
- func (c *Cache) Size() int
- func (c *Cache) Stats() (hits, misses int64)
- func (c *Cache) StatsWithMemory() (hits, misses, memUsage int64)
- type CachedParse
- type ParseResult
- type Service
- func (s *Service) CacheStats() (hits, misses int64)
- func (s *Service) ClearCache()
- func (s *Service) DetectLanguage(filePath string) string
- func (s *Service) GetLanguage(name string) *sitter.Language
- func (s *Service) IsSupported(filePath string) bool
- func (s *Service) ParseFile(filePath string) (*ParseResult, error)
- func (s *Service) ParseWithTree(source []byte, language string) (*sitter.Tree, *sitter.Node, error)
- func (s *Service) RegisterLanguage(name string, lang *sitter.Language)
- func (s *Service) SupportedLanguages() []string
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyParseTree = errors.New("parser: parse produced an empty tree")
ErrEmptyParseTree is returned when Tree-Sitter returns a nil tree for valid input.
var ErrLanguageNotRegistered = errors.New("parser: language not registered")
ErrLanguageNotRegistered is returned when the requested language has no registered grammar.
var ErrParserCreationFailed = errors.New("parser: failed to create parser instance")
ErrParserCreationFailed is returned when a new Tree-Sitter parser cannot be allocated.
var ErrUnsupportedLanguage = errors.New("parser: unsupported file type")
ErrUnsupportedLanguage is returned when a file's language is not supported.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is an LRU cache with O(1) operations and memory limits
func NewCache ¶
NewCache creates a new cache with entry and memory limits MEMORY FIX: Reduced default memory limit from 256MB to 32MB for multi-threaded usage
func NewCacheWithMemoryLimit ¶
NewCacheWithMemoryLimit creates a cache with custom memory limit MEMORY FIX: Reduced default max entries from 1000 to 100 for multi-threaded usage
func (*Cache) Clear ¶
func (c *Cache) Clear()
Clear clears all entries from the cache - O(n) but infrequent MEMORY FIX: Now properly closes all trees to release AST memory
func (*Cache) Get ¶
func (c *Cache) Get(key string) *CachedParse
Get retrieves a cached parse result - O(1) Uses an optimistic read → upgrade pattern: check existence under RLock, then re-acquire a write lock only when a hit is confirmed (MoveToFront mutates the list).
func (*Cache) MemoryUsage ¶
MemoryUsage returns current memory usage estimate
func (*Cache) Put ¶
func (c *Cache) Put(key string, data *CachedParse)
Put adds or updates a cached parse result - O(1)
func (*Cache) Remove ¶
Remove removes an entry from the cache - O(1) MEMORY FIX: Now properly closes the tree to release AST memory
func (*Cache) StatsWithMemory ¶
StatsWithMemory returns cache statistics including memory usage
type CachedParse ¶
type CachedParse struct {
Root *sitter.Node
Tree *sitter.Tree // Keep tree reference to close on eviction
Source []byte
}
CachedParse represents a cached parse result MEMORY FIX: Now stores the Tree reference to properly close it on eviction
type ParseResult ¶
ParseResult contains the result of parsing a file
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides parsing capabilities for multiple languages
func NewService ¶
NewService creates a new parser service
func (*Service) CacheStats ¶
CacheStats returns cache statistics
func (*Service) DetectLanguage ¶
DetectLanguage detects the programming language from file path. Uses the centralized extension mappings from pkg/parser/languages.
func (*Service) GetLanguage ¶
GetLanguage returns the registered language by name
func (*Service) IsSupported ¶
IsSupported checks if a file type is supported
func (*Service) ParseFile ¶
func (s *Service) ParseFile(filePath string) (*ParseResult, error)
ParseFile parses a file and returns the parse result MEMORY FIX: Now stores tree in cache for proper cleanup on eviction
func (*Service) ParseWithTree ¶
ParseWithTree parses source code and returns both tree and root node MEMORY FIX: Now returns the tree so it can be closed later
func (*Service) RegisterLanguage ¶
RegisterLanguage registers a language parser
func (*Service) SupportedLanguages ¶
SupportedLanguages returns all supported language names