Documentation
¶
Index ¶
- Variables
- func Names() []string
- type Document
- func (d *Document) AddCollection(coll model.Collection)
- func (d *Document) Chunk(start int, end int) ([]byte, error)
- func (d *Document) Collections() []model.Collection
- func (d *Document) Content() ([]byte, error)
- func (d *Document) ETag() string
- func (d *Document) ID() model.DocumentID
- func (d *Document) Metadata() map[string]any
- func (d *Document) Sections() []model.Section
- func (d *Document) SetETag(etag string)
- func (d *Document) SetMetadata(metadata map[string]any)
- func (d *Document) SetSource(source *url.URL)
- func (d *Document) Source() *url.URL
- type Language
- type OptionFunc
- type Options
- type Registry
- type Section
- func (s *Section) Branch() []model.SectionID
- func (s *Section) Content() ([]byte, error)
- func (s *Section) Document() model.Document
- func (s *Section) End() int
- func (s *Section) ID() model.SectionID
- func (s *Section) Level() uint
- func (s *Section) Parent() model.Section
- func (s *Section) Sections() []model.Section
- func (s *Section) Start() int
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedExtension = errors.New("unsupported file extension")
Functions ¶
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
func Parse ¶
func Parse(filename string, data []byte, funcs ...OptionFunc) (*Document, error)
Parse builds a document whose section tree mirrors the declarations (functions, methods, types/classes...) found in a source file.
Parsing is best-effort: when the syntax tree cannot be obtained (timeout, unparseable input, oversized file) the document degrades to a single root section covering the whole file. Only unknown extensions and invalid language definitions are reported as errors.
func (*Document) AddCollection ¶
func (d *Document) AddCollection(coll model.Collection)
func (*Document) Collections ¶
func (d *Document) Collections() []model.Collection
Collections implements model.Document.
func (*Document) SetMetadata ¶
SetMetadata attaches arbitrary metadata used for filtering at search time.
type Language ¶
type Language struct {
// Name identifies the language in document metadata (e.g. "go", "python").
Name string
// Grammar lazily returns the tree-sitter grammar.
Grammar func() *ts.Language
// Query is a tree-sitter S-expression pattern capturing the declarations
// to expose as sections, each tagged @def.
Query string
// contains filtered or unexported fields
}
Language describes how to parse and chunk one programming language.
type OptionFunc ¶
type OptionFunc func(opts *Options)
func WithMaxParseBytes ¶
func WithMaxParseBytes(maxBytes int) OptionFunc
func WithMaxWordPerSection ¶
func WithMaxWordPerSection(maxWord int) OptionFunc
func WithRegistry ¶
func WithRegistry(registry *Registry) OptionFunc
type Options ¶
type Options struct {
MaxWordPerSection int
Registry *Registry
// MaxParseBytes caps structural extraction: larger files are indexed as a
// single root section (later force-split by word budget).
MaxParseBytes int
}
func NewOptions ¶
func NewOptions(funcs ...OptionFunc) *Options
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maps file extensions (lowercase, with leading dot) to languages.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns a registry with the built-in extension mapping.
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) SupportedExtensions ¶
SupportedExtensions returns the registered extensions, sorted.
type Section ¶
type Section struct {
// contains filtered or unexported fields
}
func (*Section) Content ¶
Content implements model.Section.
Unlike markdown sections, the chunk is returned as-is: source code must not be re-rendered or trimmed.