Types Reference
Chunk
A semantic unit of code or documentation.
type Chunk struct {
Content string
Symbol string
Kind Kind
StartLine int
EndLine int
Context []string
}
| Field | Type | Description |
|---|---|---|
Content | string | The actual source code or text, including comments |
Symbol | string | Name of the function, class, type, or section |
Kind | Kind | Category of this chunk (function, method, class, etc.) |
StartLine | int | 1-indexed starting line number |
EndLine | int | 1-indexed ending line number |
Context | []string | Parent chain, e.g. ["class UserService"] |
Notes:
Contentincludes documentation comments attached to the constructSymbolfor methods may include receiver:"User.Validate"Contextis empty for top-level constructs- Line numbers are 1-indexed (first line is 1, not 0)
Kind
Categorizes what a chunk represents.
type Kind string
const (
KindFunction Kind = "function"
KindMethod Kind = "method"
KindClass Kind = "class"
KindInterface Kind = "interface"
KindType Kind = "type"
KindEnum Kind = "enum"
KindConstant Kind = "constant"
KindVariable Kind = "variable"
KindSection Kind = "section"
KindModule Kind = "module"
)
| Constant | Value | Description |
|---|---|---|
KindFunction | "function" | Standalone function |
KindMethod | "method" | Function with receiver/self |
KindClass | "class" | Class, struct, or impl block |
KindInterface | "interface" | Interface, trait, or protocol |
KindType | "type" | Type alias or other type definition |
KindEnum | "enum" | Enumeration |
KindConstant | "constant" | Constant declaration |
KindVariable | "variable" | Variable declaration |
KindSection | "section" | Markdown header/section |
KindModule | "module" | Package or file-level construct |
Language mappings:
| Language | Construct | Kind |
|---|---|---|
| Go | func | function |
| Go | func (r *T) | method |
| Go | type T struct | class |
| Go | type T interface | interface |
| Go | type T = U | type |
| TypeScript | function | function |
| TypeScript | class method | method |
| TypeScript | class | class |
| TypeScript | interface | interface |
| TypeScript | type | type |
| Python | def (top-level) | function |
| Python | def (in class) | method |
| Python | class | class |
| Rust | fn (top-level) | function |
| Rust | fn (in impl) | method |
| Rust | struct | type |
| Rust | impl | class |
| Rust | trait | interface |
| Rust | enum | enum |
| Markdown | # header | section |
Language
Identifies a programming language.
type Language string
const (
Go Language = "go"
TypeScript Language = "typescript"
JavaScript Language = "javascript"
Python Language = "python"
Rust Language = "rust"
Markdown Language = "markdown"
)
| Constant | Value | Provider Package |
|---|---|---|
Go | "go" | chisel/golang |
TypeScript | "typescript" | chisel/typescript |
JavaScript | "javascript" | chisel/typescript |
Python | "python" | chisel/python |
Rust | "rust" | chisel/rust |
Markdown | "markdown" | chisel/markdown |
Notes:
- TypeScript and JavaScript use the same provider package
- Use
typescript.NewJavaScript()for JavaScript files
Provider
Interface for language-specific parsers.
type Provider interface {
Chunk(ctx context.Context, filename string, content []byte) ([]Chunk, error)
Language() Language
}
| Method | Description |
|---|---|
Chunk | Parses content and returns semantic chunks |
Language | Returns the language this provider handles |
Implementing a custom provider:
type MyProvider struct{}
func (p *MyProvider) Chunk(ctx context.Context, filename string, content []byte) ([]chisel.Chunk, error) {
// Parse content and extract chunks
return chunks, nil
}
func (p *MyProvider) Language() chisel.Language {
return "mylang"
}
Chunker
Routes chunking requests to appropriate providers.
type Chunker struct {
// contains filtered or unexported fields
}
Created with chisel.New(). See API Reference for methods.