Help us shape the future of Go! Take the 2026 Go Developer Survey

code

package
v0.412.3 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package code provides tree-sitter based code indexing with semantic search.

Package code provides code indexing with tree-sitter and semantic search.

Index

Constants

View Source
const (
	IndexingStatusPending    = treesitter.IndexingStatusPending
	IndexingStatusInProgress = treesitter.IndexingStatusInProgress
	IndexingStatusCompleted  = treesitter.IndexingStatusCompleted
	IndexingStatusFailed     = treesitter.IndexingStatusFailed
	IndexingStatusCancelled  = treesitter.IndexingStatusCancelled
)

Re-export constants

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeFile

type CodeFile = treesitter.CodeFile

Re-export treesitter types for convenience

type CodeIndexer

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

CodeIndexer manages code indexing projects using tree-sitter for parsing and embeddings for semantic search.

func NewCodeIndexer

func NewCodeIndexer(db *sql.DB, embedder embeddings.Embedder, workers int) *CodeIndexer

NewCodeIndexer creates a new CodeIndexer with the given number of concurrent workers. If workers is <= 0, the defaultWorkers value is used.

func (*CodeIndexer) DeleteFile added in v0.320.0

func (c *CodeIndexer) DeleteFile(ctx context.Context, projectID, filePath string) error

DeleteFile removes a single indexed file and all related indexed symbols.

func (*CodeIndexer) DeleteFileDirect added in v0.326.0

func (c *CodeIndexer) DeleteFileDirect(ctx context.Context, projectID, filePath string) error

DeleteFileDirect removes a single indexed file and all related symbols. Called by the primary IPC dispatcher when a secondary forwards a CodeDeleteFile write.

func (*CodeIndexer) DeleteProject added in v0.162.0

func (c *CodeIndexer) DeleteProject(ctx context.Context, projectID string) error

DeleteProject removes an indexed project and all related indexed data.

func (*CodeIndexer) DeleteProjectDirect added in v0.326.0

func (c *CodeIndexer) DeleteProjectDirect(ctx context.Context, projectID string) error

DeleteProjectDirect removes an indexed project and all related data. Called by the primary IPC dispatcher when a secondary forwards a CodeDeleteProject write.

func (*CodeIndexer) FindReferences

func (c *CodeIndexer) FindReferences(ctx context.Context, projectID, symbolID, symbolName string, limit int) ([]*CodeSymbol, error)

FindReferences finds all symbols that reference the given symbol by name.

func (*CodeIndexer) FindSymbol

func (c *CodeIndexer) FindSymbol(ctx context.Context, query SymbolQuery) ([]*CodeSymbol, error)

FindSymbol finds symbols matching the given query criteria.

func (*CodeIndexer) GetFileSymbols

func (c *CodeIndexer) GetFileSymbols(ctx context.Context, projectID, filePath string, includeBody bool) ([]*CodeSymbol, error)

GetFileSymbols returns all symbols for a file.

func (*CodeIndexer) GetJob

func (c *CodeIndexer) GetJob(jobID string) (*IndexingJob, bool)

GetJob returns the current status of an indexing job.

func (*CodeIndexer) GetProjectStats

func (c *CodeIndexer) GetProjectStats(ctx context.Context, projectID string) (map[string]interface{}, error)

GetProjectStats returns statistics for a project.

func (*CodeIndexer) GetSymbolsOverview

func (c *CodeIndexer) GetSymbolsOverview(ctx context.Context, projectID, filePath string, maxResults int) ([]*CodeSymbol, error)

GetSymbolsOverview returns a high-level overview of symbols in a file.

func (*CodeIndexer) HasProject added in v0.320.0

func (c *CodeIndexer) HasProject(ctx context.Context, projectID, rootPath string) (bool, error)

HasProject reports whether a project is already registered for code indexing and whether the stored root path matches the requested one.

func (*CodeIndexer) HybridSearch

func (c *CodeIndexer) HybridSearch(ctx context.Context, projectID, query string, limit int, langs []Language, symbolTypes []SymbolType) ([]HybridSearchResult, error)

HybridSearch performs hybrid vector + FTS search over code symbols.

func (*CodeIndexer) IndexFileDirect added in v0.326.0

func (c *CodeIndexer) IndexFileDirect(ctx context.Context, projectID, filePath, language, fileHash string, symbolsJSON json.RawMessage) error

IndexFileDirect inserts or updates a file and its symbols, then generates embeddings. Called by the primary IPC dispatcher when a secondary forwards a CodeIndexFile write. symbolsJSON is the JSON-encoded []*treesitter.CodeSymbol payload from the RPC request. Symbol embeddings are generated on the primary using its configured embedder.

func (*CodeIndexer) IndexProject

func (c *CodeIndexer) IndexProject(ctx context.Context, projectID, projectPath string, languages []Language) (string, error)

IndexProject indexes all supported source files in a project directory. It runs asynchronously and updates the job status in the jobs map. Returns the job ID immediately.

func (*CodeIndexer) ListProjects

func (c *CodeIndexer) ListProjects(ctx context.Context) ([]*CodeProject, error)

ListProjects returns all indexed projects.

func (*CodeIndexer) ReindexFile

func (c *CodeIndexer) ReindexFile(ctx context.Context, projectID, filePath string) error

ReindexFile re-indexes a single file in a project.

func (*CodeIndexer) SearchPattern

func (c *CodeIndexer) SearchPattern(ctx context.Context, projectID, pattern string, caseSensitive bool, isRegex bool, limit int, langs []Language, symbolTypes []SymbolType) ([]*CodeSymbol, error)

SearchPattern searches for text patterns in code symbols.

func (*CodeIndexer) SetProjectStatusDirect added in v0.326.0

func (c *CodeIndexer) SetProjectStatusDirect(ctx context.Context, projectID, status string, lastIndexedAt *time.Time, updatedAt time.Time) error

SetProjectStatusDirect updates the indexing status of an existing project. Called by the primary IPC dispatcher when a secondary forwards a CodeSetProjectStatus write.

func (*CodeIndexer) SetWriteProxy added in v0.326.0

func (c *CodeIndexer) SetWriteProxy(proxy *dbproxy.DBProxy)

SetWriteProxy configures a DB proxy for mutating operations.

func (*CodeIndexer) UpdateLanguageStatsDirect added in v0.326.0

func (c *CodeIndexer) UpdateLanguageStatsDirect(ctx context.Context, projectID string) error

UpdateLanguageStatsDirect recomputes and persists language statistics for a project. Called by the primary IPC dispatcher when a secondary forwards a CodeUpdateLanguageStats write.

func (*CodeIndexer) UpsertProjectDirect added in v0.326.0

func (c *CodeIndexer) UpsertProjectDirect(ctx context.Context, projectID, name, rootPath, status string, createdAt, updatedAt time.Time) error

UpsertProjectDirect inserts or updates a code project record. Called by the primary IPC dispatcher when a secondary forwards a CodeUpsertProject write.

type CodeProject

type CodeProject = treesitter.CodeProject

Re-export treesitter types for convenience

type CodeSymbol

type CodeSymbol = treesitter.CodeSymbol

Re-export treesitter types for convenience

type HybridSearchResult

type HybridSearchResult struct {
	Symbol      *CodeSymbol `json:"symbol"`
	Score       float64     `json:"score"`
	VectorScore float64     `json:"vector_score,omitempty"`
	FTSScore    float64     `json:"fts_score,omitempty"`
	Rank        int         `json:"rank"`
}

HybridSearchResult represents a result from hybrid search

type IndexingJob

type IndexingJob = treesitter.IndexingJob

Re-export treesitter types for convenience

type IndexingStatus

type IndexingStatus = treesitter.IndexingStatus

Re-export treesitter types for convenience

type Language

type Language = treesitter.Language

Re-export treesitter types for convenience

type ParseResult

type ParseResult = treesitter.ParseResult

Re-export treesitter types for convenience

type SemanticSearchQuery

type SemanticSearchQuery = treesitter.SemanticSearchQuery

Re-export treesitter types for convenience

type SemanticSearchResult

type SemanticSearchResult = treesitter.SemanticSearchResult

Re-export treesitter types for convenience

type SymbolQuery

type SymbolQuery = treesitter.SymbolQuery

Re-export treesitter types for convenience

type SymbolType

type SymbolType = treesitter.SymbolType

Re-export treesitter types for convenience

Jump to

Keyboard shortcuts

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