graph

package
v0.0.0-...-aa42d66 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(data []byte) (uint64, error)

Types

type Asset

type Asset struct {
	Name       string
	Path       string
	ImportPath string
	Content    []byte
}

type Config

type Config struct {
	IncludeUnexported bool
	SkipTests         bool
	RecursivePackages bool
	SkipAsset         bool //
}

func DefaultConfig

func DefaultConfig() *Config

type Constant

type Constant struct {
	Name       string
	Comment    string
	Value      string
	Type       *Type     // Type of the constant if specified
	File       *File     // File where this constant is defined
	IsExported bool      // Whether the constant is exported (public) or not
	Location   *Location // Location of the constant in the source code
}

type ContentGenerator

type ContentGenerator interface {
	// Generate generates content from a file
	Emit(file *File) ([]byte, error)
}

ContentGenerator defines an interface for generating content from a file

type Document

type Document struct {
	ID        string       `json:"id"`        // Unique identifier for the document
	Kind      DocumentKind `json:"kind"`      // Kind of document
	Project   string       `json:"project"`   // Project name
	Path      string       `json:"path"`      // File path
	Package   string       `json:"package"`   // Package name
	Name      string       `json:"name"`      // Element name
	Type      string       `json:"type"`      // Type of the element (e.g., function signature)
	Hash      uint64       `json:"hash"`      // Hash of the content
	Signature string       `json:"signature"` //Signature
	Content   string       `json:"content"`   // Full content of the element including comments, annotations, etc.
	Part      int          `json:"part"`      // Part number for large documents
}

Document represents a code element with its metadata for vector embedding

func (*Document) GetID

func (d *Document) GetID() string

func (*Document) HashContent

func (d *Document) HashContent() uint64

HashContent generates content hash

func (*Document) Size

func (d *Document) Size() int

type DocumentKind

type DocumentKind string

DocumentKind indicates the type of code element that the document represents

const (
	// Document kinds
	KindConstant   DocumentKind = "Constant"
	KindVariable   DocumentKind = "Variable"
	KindFileFunc   DocumentKind = "Function" // Function without a receiver
	KindType       DocumentKind = "Type"     // Type declaration only
	KindTypeMethod DocumentKind = "Method"
	KindTypeField  DocumentKind = "Field"
	KindAsset      DocumentKind = "Asset" // Package-level information
	KindCode       DocumentKind = "Code"  // Package-level information

)

type Documents

type Documents []*Document

func SplitDocument

func SplitDocument(doc *Document) Documents

SplitDocument splits a large document into multiple chunks of 8k - 256 bytes.

func (*Documents) Append

func (d *Documents) Append(doc *Document)

func (Documents) FilterBySize

func (d Documents) FilterBySize(totalSize int) Documents

func (Documents) GroupBy

func (d Documents) GroupBy() Documents

func (Documents) Size

func (d Documents) Size() int

type Emitter

type Emitter interface {
	Emit(file *File) ([]byte, error)
}

Emitter represents generator

type Field

type Field struct {
	Name       string
	Type       *Type
	Tag        reflect.StructTag
	Location   *Location
	Comment    string
	Annotation string
	IsExported bool
	IsEmbedded bool
	IsStatic   bool
	IsConstant bool
}

Field represents a struct field

func (*Field) Content

func (f *Field) Content() string

type File

type File struct {
	Name       string      // File name
	Path       string      // File path
	Package    string      // Package name
	ImportPath string      // Import path
	Types      []*Type     // Types declared in this file
	Constants  []*Constant // Constants declared in this file
	Variables  []*Variable // Variables declared in this file
	Functions  []*Function // Functions declared in this file
	Imports    []Import    // Imports used in this file
	// contains filtered or unexported fields
}

File represents a source code file with its types and symbols

func (*File) Content

func (f *File) Content(generator Emitter) ([]byte, error)

Content reconstructs the content of a file from its components

func (*File) GetConstant

func (f *File) GetConstant(name string) *Constant

GetConstant retrieves a constant by name from the file

func (*File) HasFunction

func (f *File) HasFunction(name string) bool

HasFunction checks if a function with the given name exists in the file

func (*File) IndexFunctions

func (f *File) IndexFunctions()

func (*File) IndexTypes

func (f *File) IndexTypes()

func (*File) LookupFunction

func (f *File) LookupFunction(name string) *Function

LookupFunction retrieves a function by name from the file

func (*File) LookupType

func (f *File) LookupType(name string) *Type

LookupType retrieves a type by name from the file

func (*File) LookupVariable

func (f *File) LookupVariable(name string) *Variable

LookupVariable retrieves a variable by name from the file

type Function

type Function struct {
	Name          string
	Comment       *LocationNode
	Annotation    *LocationNode
	Receiver      string
	TypeParams    []*TypeParam
	Parameters    []*Parameter
	Results       []*Parameter
	Body          *LocationNode
	IsExported    bool
	Location      *Location // Location of the method in the source code
	IsStatic      bool      // Whether the method is static (class method)
	IsConstructor bool
	Signature     string
	Hash          int32
}

Function represents a type method

func (*Function) Content

func (m *Function) Content() string

Content returns the content of the method including its receiver, parameters, and results

type Import

type Import struct {
	Name string // Local name (may be empty for default)
	Path string // Import path
}

Import represents an imported package

type Location

type Location struct {
	Start int // Start position in the source code
	End   int // End position in the source code
	Raw   string
}

type LocationNode

type LocationNode struct {
	Text string
	Location
}

func NewNodeLocation

func NewNodeLocation(text string) *LocationNode

type Package

type Package struct {
	Name       string
	ImportPath string
	FileSet    []*File  // Files that are part of this package
	Assets     []*Asset // Assets associated with this package
	// contains filtered or unexported fields
}

Package represents a Go package with its files and types

func (*Package) AddFile

func (p *Package) AddFile(file *File)

func (*Package) IndexTypes

func (p *Package) IndexTypes()

func (*Package) LookupMethod

func (p *Package) LookupMethod(typeName, methodName string) *Function

type Parameter

type Parameter struct {
	Name string
	Type *Type
}

Parameter represents a function parameter or result

type PomInfo

type PomInfo struct {
	GroupID    string
	ArtifactID string
	Version    string
	Name       string
}

PomInfo represents the key information from a Maven POM file

type Project

type Project struct {
	Name          string
	Type          string
	RootPath      string
	RepositoryURL string
	Packages      []*Package
	// contains filtered or unexported fields
}

Project represents a code project with multiple packages

func (*Project) AddFunctionToFile

func (p *Project) AddFunctionToFile(packageName, fileName, functionName, functionContent string) error

AddFunctionToFile adds a function to a file if it doesn't already exist

func (*Project) CreateDocuments

func (p *Project) CreateDocuments(ctx context.Context, pkgPath string) (Documents, error)

CreateDocuments creates Document instances for embedding from a project

func (*Project) GetPackage

func (p *Project) GetPackage(name string) *Package

GetPackage retrieves a constant by name from the file

func (*Project) Init

func (p *Project) Init()

type Type

type Type struct {
	Name          string            // Type name
	Kind          reflect.Kind      // Go reflect kind
	Tag           reflect.StructTag // Tags for struct fields
	Package       string            // Package name
	PackagePath   string            // Full package import path
	ComponentType string            // For container types (slices, maps)
	KeyType       string            // For map types
	Comment       *LocationNode     // Type documentation

	Annotation *LocationNode // Annotations for the type
	IsExported bool          // Whether the type is exported
	Fields     []*Field      // Struct fields (if applicable)
	Methods    []*Function   // Type methods
	TypeParams []*TypeParam  // Generic type parameters
	Implements []string      // Interfaces this type implements
	IsPointer  bool          // Whether the type is a pointer
	Location   *Location     // Location of the type in the source code
	Extends    []string
	// contains filtered or unexported fields
}

Type represents a parsed Go type with rich metadata

func CreateCompositeType

func CreateCompositeType(name string, sourceTypes []*Type, fieldNames [][]string, methodNames [][]string) *Type

CreateCompositeType creates a new type by combining fields and methods from multiple types

func CreateTypeFromFields

func CreateTypeFromFields(name string, sourceType *Type, fieldNames []string) *Type

CreateTypeFromFields creates a new type with the given name and selected fields

func CreateTypeFromMethods

func CreateTypeFromMethods(name string, sourceType *Type, methodNames []string) *Type

CreateTypeFromMethods creates a new type with the given name and selected methods

func (*Type) AddField

func (t *Type) AddField(field *Field)

AddField adds a field to the type

func (*Type) AddMethod

func (t *Type) AddMethod(method *Function)

AddMethod adds a method to the type

func (*Type) Clone

func (t *Type) Clone() *Type

Clone creates a deep copy of the type

func (*Type) Content

func (m *Type) Content() string

Content returns the content of the method including its receiver, parameters, and results

func (*Type) GetField

func (f *Type) GetField(name string) *Field

GetField retrieves a constant by name from the file

func (*Type) GetMethod

func (f *Type) GetMethod(name string) *Function

GetMethod retrieves a constant by name from the file

func (*Type) RemoveField

func (t *Type) RemoveField(fieldName string) bool

RemoveField removes a field from the type by name

func (*Type) RemoveMethod

func (t *Type) RemoveMethod(methodName string) bool

RemoveMethod removes a method from the type by name

type TypeParam

type TypeParam struct {
	Name       string
	Constraint string
}

TypeParam represents a generic type parameter

type Variable

type Variable struct {
	Name       string
	Comment    string
	Type       *Type
	Value      string
	File       *File     // File where this variable is defined
	IsExported bool      // Whether the variable is exported (public) or not
	Annotation string    // Annotation associated with the variable
	IsConst    bool      // Whether the variable is a constant
	Location   *Location // Location of the variable in the source code
}

Jump to

Keyboard shortcuts

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