util

package
v0.0.0-...-6320ad3 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateFileSHA256

func CalculateFileSHA256(content []byte) string

CalculateFileSHA256 calculates the SHA256 hash of file content

func DoWorkList

func DoWorkList[T any, R any](list []T, work func(T) R) []R

func ExtractPathFromURI

func ExtractPathFromURI(uri string) string

func FormatSignatureString

func FormatSignatureString(info SignatureInfo) string

FormatSignatureString creates a human-readable signature string Example: "User findByEmail(String email)"

func GetFileContentFromGit

func GetFileContentFromGit(gitRootPath, filePath string) ([]byte, error)

GetFileContentFromGit retrieves file content from git HEAD Returns error if file is not tracked by git gitRootPath should be the git repository root (from GitInfo.GitRootPath)

func GetLastCommitForFile

func GetLastCommitForFile(repoPath, filePath string) (string, error)

GetLastCommitForFile gets the commit SHA of the last commit that modified a file

func GetRelativePath

func GetRelativePath(repoPath, filePath string) (string, error)

GetRelativePath returns the relative path of a file from the repository root

func IsFileModified

func IsFileModified(gitInfo *GitInfo, filePath string) bool

IsFileModified checks if a file is modified compared to HEAD

func NormalizeSignatureForEmbedding

func NormalizeSignatureForEmbedding(info SignatureInfo) string

NormalizeSignatureForEmbedding converts a method signature into a normalized text representation optimized for embedding-based semantic search.

Example:

Input: class=UserService, method=findByEmail, params=[(email, String)], returns=User
Output: "UserService find By Email String email returns User"

func Ptr

func Ptr[T any](v T) *T

func ReadFileOptimized

func ReadFileOptimized(repoPath, filePath string, useHead bool, gitInfo *GitInfo) ([]byte, error)

ReadFileOptimized reads file content, using git HEAD if useHead is true and file is unmodified In HEAD mode, untracked files are skipped (returns nil content with error)

func ShouldSkipDirectory

func ShouldSkipDirectory(path string) bool

ShouldSkipDirectory checks if a directory should be skipped during traversal

func ShouldSkipFile

func ShouldSkipFile(filePath string, repo *config.Repository) bool

ShouldSkipFile checks if a file should be skipped during indexing This includes special files like Dockerfiles, lock files, build artifacts, etc. If repo is provided and SkipOtherLanguages is true, only files matching the repo language are processed

func ToRelativePath

func ToRelativePath(rootPath, fullPath string) string

func ToUri

func ToUri(path, rootPath string) (string, error)

func WalkDirTree

func WalkDirTree(root string, walkFn WalkFunc, skipPath SkipFunc, logger *zap.Logger, gcThreshold int64, numThreads int) error

Walk traverses a directory tree concurrently, calling walkFn for each file and directory. Unlike filepath.Walk, this implementation does not guarantee any particular ordering of children directories and files. gcThreshold controls how often to trigger GC (every N files). Set to 0 to disable. Uses 2 worker goroutines to process files concurrently.

Types

type BloomFilterManager

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

BloomFilterManager manages bloom filters for repositories with disk persistence

func NewBloomFilterManager

func NewBloomFilterManager(cfg config.BloomFilterConfig, logger *zap.Logger) (*BloomFilterManager, error)

NewBloomFilterManager creates a new bloom filter manager

func (*BloomFilterManager) Add

func (bfm *BloomFilterManager) Add(repoName string, data string) error

Add adds data to the bloom filter for a repository

func (*BloomFilterManager) Clear

func (bfm *BloomFilterManager) Clear(repoName string)

Clear removes the bloom filter for a repository from memory

func (*BloomFilterManager) ClearAll

func (bfm *BloomFilterManager) ClearAll()

ClearAll removes all bloom filters from memory

func (*BloomFilterManager) Delete

func (bfm *BloomFilterManager) Delete(repoName string) error

Delete removes the bloom filter for a repository from both memory and disk

func (*BloomFilterManager) GetOrCreateFilter

func (bfm *BloomFilterManager) GetOrCreateFilter(repoName string) (*bloom.BloomFilter, error)

GetOrCreateFilter gets or creates a bloom filter for a repository

func (*BloomFilterManager) Save

func (bfm *BloomFilterManager) Save(repoName string) error

Save persists the bloom filter for a repository to disk

func (*BloomFilterManager) SaveAll

func (bfm *BloomFilterManager) SaveAll() error

SaveAll persists all bloom filters to disk

func (*BloomFilterManager) Test

func (bfm *BloomFilterManager) Test(repoName string, data string) (bool, error)

Test checks if data might exist in the bloom filter for a repository Returns true if data might exist (or false positive), false if definitely doesn't exist

type ExecutorPool

type ExecutorPool[T any] struct {
	// contains filtered or unexported fields
}
Example
var processedCount int64

pool := NewExecutorPool(3, 10, func(data string) {
	fmt.Printf("Processing: %s\n", data)
	atomic.AddInt64(&processedCount, 1)
	time.Sleep(100 * time.Millisecond)
})

tasks := []string{"task1", "task2", "task3", "task4", "task5"}

for _, task := range tasks {
	pool.Submit(task)
}

pool.Close()

fmt.Printf("Total processed: %d\n", atomic.LoadInt64(&processedCount))

func NewExecutorPool

func NewExecutorPool[T any](maxConcurrent int, bufferSize int, workerFunc func(T)) *ExecutorPool[T]

func (*ExecutorPool[T]) Close

func (p *ExecutorPool[T]) Close()

func (*ExecutorPool[T]) Submit

func (p *ExecutorPool[T]) Submit(item T)

type GitInfo

type GitInfo struct {
	HeadCommitSHA string
	HeadCommitMsg string
	ModifiedFiles map[string]bool // Set of files modified compared to HEAD (absolute paths)
	GitRootPath   string          // Absolute path to git repository root
	IsGitRepo     bool
}

GitInfo contains git repository information

func GetGitInfo

func GetGitInfo(repoPath string) (*GitInfo, error)

GetGitInfo retrieves git information for a repository path

type ParameterInfo

type ParameterInfo struct {
	Name string
	Type string
}

ParameterInfo holds parameter details

type SafeMap

type SafeMap[V any] struct {
	// contains filtered or unexported fields
}

func NewSafeMap

func NewSafeMap[V any]() *SafeMap[V]

func (*SafeMap[V]) Get

func (sm *SafeMap[V]) Get(key string) (V, bool)

func (*SafeMap[V]) Set

func (sm *SafeMap[V]) Set(key string, value V)

type SignatureInfo

type SignatureInfo struct {
	ClassName      string
	MethodName     string
	Parameters     []ParameterInfo
	ReturnType     string
	ParameterTypes []string
	ParameterNames []string
}

SignatureInfo holds parsed method signature information

func BuildSignatureInfo

func BuildSignatureInfo(className, methodName, returnType string, paramNames, paramTypes []string) SignatureInfo

BuildSignatureInfo creates a SignatureInfo from raw components

func ParseGoSignature

func ParseGoSignature(signature, methodName, className string) SignatureInfo

ParseGoSignature parses a Go function signature string to extract components Example: "FindByEmail(email string) *User" -> SignatureInfo

func ParseJavaScriptSignature

func ParseJavaScriptSignature(signature, methodName, className string) SignatureInfo

ParseJavaScriptSignature parses a JavaScript/TypeScript function signature Example: "findByEmail(email: string): User" -> SignatureInfo

func ParseJavaSignature

func ParseJavaSignature(signature, methodName, className string) SignatureInfo

ParseJavaSignature parses a Java method signature string to extract components Example: "public User findByEmail(String email)" -> SignatureInfo

func ParsePythonSignature

func ParsePythonSignature(signature, methodName, className string) SignatureInfo

ParsePythonSignature parses a Python function signature string to extract components Example: "find_by_email(email: str) -> User" -> SignatureInfo

func ParseSignatureByLanguage

func ParseSignatureByLanguage(signature, methodName, className, language string) SignatureInfo

ParseSignatureByLanguage parses a signature string based on the language

type SkipFunc

type SkipFunc func(path string, isDir bool) bool

type WalkFunc

type WalkFunc func(path string, err error) error

WalkFunc is called for each file or directory visited during the walk. If the function returns an error, the walk will stop.

Jump to

Keyboard shortcuts

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