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
- type CodeEdge
- type CodeFile
- type CodeIndexer
- func (c *CodeIndexer) DeleteFile(ctx context.Context, projectID, filePath string) error
- func (c *CodeIndexer) DeleteProject(ctx context.Context, projectID string) error
- func (c *CodeIndexer) FindReferences(ctx context.Context, projectID, symbolID, symbolName string, limit int) ([]*CodeSymbol, error)
- func (c *CodeIndexer) FindSymbol(ctx context.Context, query SymbolQuery) ([]*CodeSymbol, error)
- func (c *CodeIndexer) GetFileSymbols(ctx context.Context, projectID, filePath string, includeBody bool) ([]*CodeSymbol, error)
- func (c *CodeIndexer) GetJob(jobID string) (*IndexingJob, bool)
- func (c *CodeIndexer) GetProjectStats(ctx context.Context, projectID string) (map[string]interface{}, error)
- func (c *CodeIndexer) GetSymbolsOverview(ctx context.Context, projectID, filePath string, maxResults int) ([]*CodeSymbol, error)
- func (c *CodeIndexer) GraphEnabled() bool
- func (c *CodeIndexer) HasProject(ctx context.Context, projectID, rootPath string) (bool, error)
- func (c *CodeIndexer) HybridSearch(ctx context.Context, projectID, query string, limit int, langs []Language, ...) ([]HybridSearchResult, error)
- func (c *CodeIndexer) ImpactAnalysis(ctx context.Context, projectID, symbolName string, maxDepth, limit int) (*ImpactResult, error)
- func (c *CodeIndexer) IndexFileDirect(ctx context.Context, projectID, filePath, language, fileHash string, ...) error
- func (c *CodeIndexer) IndexProject(ctx context.Context, projectID, projectPath string, languages []Language) (string, error)
- func (c *CodeIndexer) ListIndexedFiles(ctx context.Context, rootPath, query string, limit int) ([]string, error)
- func (c *CodeIndexer) ListProjects(ctx context.Context) ([]*CodeProject, error)
- func (c *CodeIndexer) ReindexFile(ctx context.Context, projectID, filePath string) error
- func (c *CodeIndexer) RelatedFiles(ctx context.Context, projectID, filePath string, limit int) (*RelatedResult, error)
- func (c *CodeIndexer) ResolveProjectID(ctx context.Context, requestedID, rootPath string) (string, error)
- func (c *CodeIndexer) SearchPattern(ctx context.Context, projectID, pattern string, caseSensitive bool, ...) ([]*CodeSymbol, error)
- func (c *CodeIndexer) SetGraphEnabled(enabled bool)
- type CodeProject
- type CodeSymbol
- type EdgeType
- type HybridSearchResult
- type ImpactCaller
- type ImpactResult
- type IndexingJob
- type IndexingStatus
- type Language
- type ParseResult
- type RelatedFile
- type RelatedResult
- type SemanticSearchQuery
- type SemanticSearchResult
- type SymbolQuery
- type SymbolType
Constants ¶
const ( EdgeImports = treesitter.EdgeImports EdgeCalls = treesitter.EdgeCalls EdgeTypeRef = treesitter.EdgeTypeRef )
Re-export edge-type constants.
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 CodeEdge ¶ added in v0.608.1
type CodeEdge = treesitter.CodeEdge
Re-export edge 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) 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) 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) GraphEnabled ¶ added in v0.608.1
func (c *CodeIndexer) GraphEnabled() bool
GraphEnabled reports whether property-graph edge extraction is active.
func (*CodeIndexer) HasProject ¶ added in v0.320.0
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) ImpactAnalysis ¶ added in v0.608.1
func (c *CodeIndexer) ImpactAnalysis(ctx context.Context, projectID, symbolName string, maxDepth, limit int) (*ImpactResult, error)
ImpactAnalysis returns the symbols that call (directly or transitively, up to maxDepth) a symbol named symbolName — i.e. "what breaks if I change this".
Resolution is name-based via the `calls` edges, which is cheap and works cross-file/cross-package but is approximate when a name is shared by unrelated symbols. Results are deduplicated by caller symbol and capped at limit.
func (*CodeIndexer) IndexFileDirect ¶ added in v0.326.0
func (c *CodeIndexer) IndexFileDirect(ctx context.Context, projectID, filePath, language, fileHash string, symbolsJSON, edgesJSON json.RawMessage) error
IndexFileDirect inserts or updates a file and its symbols, then generates embeddings. symbolsJSON is the JSON-encoded []*treesitter.CodeSymbol payload and edgesJSON the optional []*treesitter.CodeEdge payload. Symbol embeddings are generated with the configured embedder after the transaction commits.
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.
projectID is passed through ResolveProjectID first, so a directory that is already indexed keeps its id; callers that report the id should resolve it themselves beforehand to show the one actually used.
func (*CodeIndexer) ListIndexedFiles ¶ added in v0.418.6
func (c *CodeIndexer) ListIndexedFiles(ctx context.Context, rootPath, query string, limit int) ([]string, error)
ListIndexedFiles returns up to limit indexed file paths (relative to the project root) for the project whose root_path matches rootPath. When query is non-empty it is used as a substring pre-filter (SQL LIKE) to keep the result small. It returns (nil, nil) when no project is indexed for rootPath, so the caller can transparently fall back to a filesystem scan.
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) RelatedFiles ¶ added in v0.608.1
func (c *CodeIndexer) RelatedFiles(ctx context.Context, projectID, filePath string, limit int) (*RelatedResult, error)
RelatedFiles returns files related to filePath, ranked by a weighted blend of resolved imports and bidirectional call coupling. Import resolution is best-effort: relative ESM specifiers are resolved against the project's file list; bare/package import paths rely on call coupling instead.
func (*CodeIndexer) ResolveProjectID ¶ added in v1.2.12
func (c *CodeIndexer) ResolveProjectID(ctx context.Context, requestedID, rootPath string) (string, error)
ResolveProjectID returns the project id rootPath must be indexed under. Callers derive ids in different ways (directory name, sanitized full path, configured id), so without this one directory ends up indexed twice under two ids, or one id is moved back and forth between two directories, and every switch re-embeds the whole tree. The rules are:
- rootPath is already registered: its existing id, whatever was requested (the most recently indexed one if a previous version left several).
- requestedID is free, or registered for a directory that no longer exists (a moved project): requestedID.
- requestedID belongs to another existing directory: requestedID plus a short hash of rootPath, so neither project overwrites the other.
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) SetGraphEnabled ¶ added in v0.608.1
func (c *CodeIndexer) SetGraphEnabled(enabled bool)
SetGraphEnabled toggles code property-graph edge extraction during indexing (lean-ctx Phase 4). When false, no `code_edges` rows are written, leaving the impact/related tools to operate on whatever edges already exist.
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 EdgeType ¶ added in v0.608.1
type EdgeType = treesitter.EdgeType
Re-export edge 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 ImpactCaller ¶ added in v0.608.1
type ImpactCaller struct {
Name string `json:"name"`
NamePath string `json:"name_path,omitempty"`
FilePath string `json:"file_path"`
StartLine int `json:"start_line"`
SymbolType string `json:"symbol_type"`
Depth int `json:"depth"`
}
ImpactCaller is a symbol that (transitively) depends on the analyzed symbol.
type ImpactResult ¶ added in v0.608.1
type ImpactResult struct {
Symbol string `json:"symbol"`
Callers []ImpactCaller `json:"callers"`
Truncated bool `json:"truncated"`
}
ImpactResult is the outcome of a reverse-call impact analysis.
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 ParseResult ¶
type ParseResult = treesitter.ParseResult
Re-export treesitter types for convenience
type RelatedFile ¶ added in v0.608.1
type RelatedFile struct {
FilePath string `json:"file_path"`
Score float64 `json:"score"`
Reasons []string `json:"reasons"`
}
RelatedFile is a file related to the queried file with a weighted score.
type RelatedResult ¶ added in v0.608.1
type RelatedResult struct {
File string `json:"file"`
Related []RelatedFile `json:"related"`
Truncated bool `json:"truncated"`
}
RelatedResult is the outcome of a related-files query.
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