scip

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package scip provides the main service for SCIP code intelligence.

Package scip provides SCIP index storage and querying for precise code navigation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallInstructions

func InstallInstructions() map[string]string

InstallInstructions returns instructions for installing SCIP indexers.

func ParseSymbol

func ParseSymbol(symbol string) (scheme, pkg string, descriptors []string, isLocal bool)

ParseSymbol parses a SCIP symbol string into its components. Symbol format: "<scheme> <package> <descriptors>..." or "local <id>".

func SymbolToHumanReadable

func SymbolToHumanReadable(symbol string) string

SymbolToHumanReadable converts a SCIP symbol to a human-readable name.

Types

type DefinitionResult

type DefinitionResult struct {
	Symbol     string      `json:"symbol"`
	Definition *Occurrence `json:"definition,omitempty"`
	Info       *SymbolInfo `json:"info,omitempty"`
	External   bool        `json:"external"` // True if definition is in external package
}

DefinitionResult contains the result of a go-to-definition query.

type FederatedClient

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

FederatedClient proxies SCIP requests to the correct indexer shard based on repository ownership (FNV-1a hash on repo name).

func NewFederatedClient

func NewFederatedClient(indexerService string, indexerPort, totalShards int) *FederatedClient

NewFederatedClient creates a client for federated SCIP access.

func (*FederatedClient) FindReferences

func (c *FederatedClient) FindReferences(
	ctx context.Context,
	repoName string,
	repoID int64,
	filePath string,
	line, column, limit int,
) (json.RawMessage, error)

FindReferences proxies a find-references request to the owning shard. For cross-repo references, this could fan out to all shards in the future.

func (*FederatedClient) GetStats

func (c *FederatedClient) GetStats(ctx context.Context, repoName string, repoID int64) (map[string]any, error)

GetStats proxies a stats request to the owning shard.

func (*FederatedClient) GoToDefinition

func (c *FederatedClient) GoToDefinition(
	ctx context.Context,
	repoName string,
	repoID int64,
	filePath string,
	line, column int,
) (json.RawMessage, error)

GoToDefinition proxies a go-to-definition request to the owning shard.

func (*FederatedClient) HasIndex

func (c *FederatedClient) HasIndex(ctx context.Context, repoName string, repoID int64) (bool, error)

HasIndex checks if a SCIP index exists for a repo on its owning shard.

func (*FederatedClient) ListFiles

func (c *FederatedClient) ListFiles(
	ctx context.Context,
	repoName string,
	repoID int64,
	limit int,
) (json.RawMessage, error)

ListFiles proxies a file listing request to the owning shard.

func (*FederatedClient) SearchSymbols

func (c *FederatedClient) SearchSymbols(
	ctx context.Context,
	repoName string,
	repoID int64,
	query string,
	limit int,
) (json.RawMessage, error)

SearchSymbols proxies a symbol search request to the owning shard.

type IndexOptions

type IndexOptions struct {
	// CodeHostURL is the URL of the code host (e.g., https://gitlab.example.com)
	CodeHostURL string
	// CodeHostType is the type of code host (github, gitlab, gitea, bitbucket)
	CodeHostType string
	// Token is the authentication token for the code host
	Token string
	// ClearFirst controls whether to clear existing index data before importing.
	// When true (default behavior for single-language calls), the index is cleared
	// before importing new data. When false, new data is appended to the existing index.
	// This is used by the worker for multi-language indexing: clear once before the
	// first language, then append for subsequent languages.
	ClearFirst bool
}

IndexOptions contains optional parameters for indexing.

type IndexResult

type IndexResult struct {
	Success       bool           `json:"success"`
	Language      string         `json:"language"`
	Duration      time.Duration  `json:"duration"`
	Files         int            `json:"files"`
	Symbols       int            `json:"symbols"`
	Occurrences   int            `json:"occurrences"`
	Error         string         `json:"error,omitempty"`
	IndexerOutput string         `json:"indexerOutput,omitempty"`
	Stats         map[string]any `json:"stats,omitempty"`
}

IndexResult contains the result of an indexing operation.

type Indexer

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

Indexer runs SCIP indexers for different languages.

func NewIndexer

func NewIndexer(config IndexerConfig, store *Store, logger *zap.Logger) *Indexer

NewIndexer creates a new SCIP indexer.

func (*Indexer) DetectLanguage

func (i *Indexer) DetectLanguage(repoPath string) (string, error)

DetectLanguage detects the primary language of a repository. It returns the highest-priority language that has at least one project directory.

func (*Indexer) DetectLanguages

func (i *Indexer) DetectLanguages(repoPath string) []string

DetectLanguages detects all languages present in a repository. It returns languages in priority order (Go, TypeScript, JavaScript, ...).

func (*Indexer) GetAvailableIndexers

func (i *Indexer) GetAvailableIndexers() map[string]bool

GetAvailableIndexers returns which indexers are available on the system.

func (*Indexer) Index

func (i *Indexer) Index(
	ctx context.Context,
	repoID int64,
	repoPath string,
	language string,
) (*IndexResult, error)

Index runs the appropriate SCIP indexer for a repository.

func (*Indexer) IndexWithOptions

func (i *Indexer) IndexWithOptions(
	ctx context.Context,
	repoID int64,
	repoPath string,
	language string,
	opts *IndexOptions,
) (*IndexResult, error)

IndexWithOptions runs the appropriate SCIP indexer for a repository with optional credentials.

func (*Indexer) IsIndexerAvailable

func (i *Indexer) IsIndexerAvailable(language string) bool

IsIndexerAvailable checks if an indexer is available for a language.

func (*Indexer) SupportedLanguages

func (i *Indexer) SupportedLanguages() []string

SupportedLanguages returns the list of languages with SCIP indexer support.

type IndexerConfig

type IndexerConfig struct {
	// Paths to SCIP indexer binaries (optional, will look in PATH if not set)
	SCIPTypeScript string `yaml:"scip_typescript"`
	SCIPGo         string `yaml:"scip_go"`
	SCIPJava       string `yaml:"scip_java"`
	SCIPRust       string `yaml:"scip_rust"`
	SCIPPython     string `yaml:"scip_python"`

	// Timeout for indexing operations
	Timeout time.Duration `yaml:"timeout"`

	// Working directory for temporary files
	WorkDir string `yaml:"work_dir"`
}

IndexerConfig holds configuration for SCIP indexers.

func DefaultIndexerConfig

func DefaultIndexerConfig() IndexerConfig

DefaultIndexerConfig returns default configuration.

type Occurrence

type Occurrence struct {
	Symbol     string `json:"symbol"`
	FilePath   string `json:"filePath"`
	StartLine  int    `json:"startLine"`         // 0-indexed
	StartCol   int    `json:"startCol"`          // 0-indexed
	EndLine    int    `json:"endLine"`           // 0-indexed
	EndCol     int    `json:"endCol"`            // 0-indexed
	Role       int    `json:"role"`              // Bitmask: 1=Definition, 2=Import, 4=WriteAccess, 8=ReadAccess
	SyntaxKind int    `json:"syntaxKind"`        // SCIP syntax kind
	Context    string `json:"context,omitempty"` // The source line content (populated by handlers)
}

Occurrence represents a symbol occurrence in the code.

func (*Occurrence) IsDefinition

func (o *Occurrence) IsDefinition() bool

IsDefinition returns true if this occurrence is a definition.

func (*Occurrence) IsImport

func (o *Occurrence) IsImport() bool

IsImport returns true if this occurrence is an import.

func (*Occurrence) IsReference

func (o *Occurrence) IsReference() bool

IsReference returns true if this occurrence is a read reference.

func (*Occurrence) IsWrite

func (o *Occurrence) IsWrite() bool

IsWrite returns true if this occurrence is a write.

type Parser

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

Parser handles parsing and importing SCIP index files.

func NewParser

func NewParser(store *Store) *Parser

NewParser creates a new SCIP parser.

func (*Parser) AppendFromBytesWithPrefix

func (p *Parser) AppendFromBytesWithPrefix(
	ctx context.Context,
	repoID int64,
	data []byte,
	pathPrefix string,
) error

AppendFromBytesWithPrefix imports a SCIP index from raw bytes, prefixing all file paths. Unlike ImportFromBytesWithPrefix, it does NOT clear the existing index first, allowing multiple project indexes to be merged into a single repo index (for monorepos).

func (*Parser) ImportFromBytes

func (p *Parser) ImportFromBytes(ctx context.Context, repoID int64, data []byte) error

ImportFromBytes imports a SCIP index from raw bytes.

func (*Parser) ImportFromBytesWithPrefix

func (p *Parser) ImportFromBytesWithPrefix(
	ctx context.Context,
	repoID int64,
	data []byte,
	pathPrefix string,
) error

ImportFromBytesWithPrefix imports a SCIP index from raw bytes, prefixing all file paths. It clears any existing index before importing.

func (*Parser) ImportFromFile

func (p *Parser) ImportFromFile(ctx context.Context, repoID int64, filePath string) error

ImportFromFile imports a SCIP index from a file path.

func (*Parser) ImportFromReader

func (p *Parser) ImportFromReader(ctx context.Context, repoID int64, r io.Reader) error

ImportFromReader imports a SCIP index from a reader.

func (*Parser) ImportIndex

func (p *Parser) ImportIndex(ctx context.Context, repoID int64, index *scipproto.Index) error

ImportIndex imports a parsed SCIP index into the store.

func (*Parser) ImportIndexWithPrefix

func (p *Parser) ImportIndexWithPrefix(
	ctx context.Context,
	repoID int64,
	index *scipproto.Index,
	pathPrefix string,
) error

ImportIndexWithPrefix imports a parsed SCIP index into the store, prefixing all file paths. It clears any existing index before importing.

type ReferencesResult

type ReferencesResult struct {
	Symbol     string       `json:"symbol"`
	Definition *Occurrence  `json:"definition,omitempty"`
	References []Occurrence `json:"references"`
	TotalCount int          `json:"totalCount"`
}

ReferencesResult contains the result of a find-references query.

type Service

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

Service provides SCIP-based code intelligence.

func NewService

func NewService(cacheDir string, logger *zap.Logger) (*Service, error)

NewService creates a new SCIP service. cacheDir should be the directory where SCIP databases are stored (e.g., data/scip).

func NewServiceWithConfig

func NewServiceWithConfig(cacheDir string, indexerCfg IndexerConfig, logger *zap.Logger) (*Service, error)

NewServiceWithConfig creates a new SCIP service with an explicit IndexerConfig. This allows callers to configure indexer binary paths and timeouts.

func (*Service) ClearIndex

func (s *Service) ClearIndex(ctx context.Context, repoID int64) error

ClearIndex removes the SCIP index for a repository.

func (*Service) Close

func (s *Service) Close() error

Close releases resources.

func (*Service) DeleteIndex

func (s *Service) DeleteIndex(ctx context.Context, repoID int64) error

DeleteIndex removes the SCIP database files for a repository entirely.

func (*Service) DetectLanguage

func (s *Service) DetectLanguage(repoPath string) (string, error)

DetectLanguage detects the primary language of a repository.

func (*Service) DetectLanguages

func (s *Service) DetectLanguages(repoPath string) []string

DetectLanguages detects all languages present in a repository. Languages are returned in priority order.

func (*Service) EvictCache

func (s *Service) EvictCache(repoID int64)

EvictCache evicts the in-memory cached connection for a repo.

func (*Service) FindReferences

func (s *Service) FindReferences(
	ctx context.Context,
	repoID int64,
	filePath string,
	line, col int,
	limit int,
) (*ReferencesResult, error)

FindReferences finds all references to the symbol at the given position. Line is 1-indexed (from editor), column is 0-indexed. Returns nil if no SCIP index is available or no symbol is at the position.

func (*Service) GetAvailableIndexers

func (s *Service) GetAvailableIndexers() map[string]bool

GetAvailableIndexers returns which indexers are available.

func (*Service) GetOccurrenceAtPosition

func (s *Service) GetOccurrenceAtPosition(
	ctx context.Context,
	repoID int64,
	filePath string,
	line, col int,
) (*Occurrence, error)

GetOccurrenceAtPosition returns the symbol occurrence at a specific position. Line is 1-indexed (from editor), column is 0-indexed.

func (*Service) GetStats

func (s *Service) GetStats(ctx context.Context, repoID int64) (map[string]any, error)

GetStats returns statistics about the SCIP index for a repository.

func (*Service) GetSymbolInfo

func (s *Service) GetSymbolInfo(
	ctx context.Context,
	repoID int64,
	symbol string,
) (*SymbolInfo, error)

GetSymbolInfo returns information about a symbol.

func (*Service) GoToDefinition

func (s *Service) GoToDefinition(
	ctx context.Context,
	repoID int64,
	filePath string,
	line, col int,
) (*DefinitionResult, error)

GoToDefinition finds the definition of the symbol at the given position. Line is 1-indexed (from editor), column is 0-indexed. Returns nil if no SCIP index is available or no symbol is at the position.

func (*Service) HasIndex

func (s *Service) HasIndex(ctx context.Context, repoID int64) (bool, error)

HasIndex returns true if the repository has a SCIP index.

func (*Service) ImportFromBytes

func (s *Service) ImportFromBytes(ctx context.Context, repoID int64, data []byte) error

ImportFromBytes imports a SCIP index from raw bytes.

func (*Service) ImportFromFile

func (s *Service) ImportFromFile(ctx context.Context, repoID int64, filePath string) error

ImportFromFile imports a SCIP index from a file.

func (*Service) ImportFromReader

func (s *Service) ImportFromReader(ctx context.Context, repoID int64, r io.Reader) error

ImportFromReader imports a SCIP index from a reader.

func (*Service) Index

func (s *Service) Index(
	ctx context.Context,
	repoID int64,
	repoPath string,
	language string,
) (*IndexResult, error)

Index runs the appropriate SCIP indexer for a repository.

func (*Service) IndexWithOptions

func (s *Service) IndexWithOptions(
	ctx context.Context,
	repoID int64,
	repoPath string,
	language string,
	opts *IndexOptions,
) (*IndexResult, error)

IndexWithOptions runs the appropriate SCIP indexer with optional credentials.

func (*Service) IsIndexerAvailable

func (s *Service) IsIndexerAvailable(language string) bool

IsIndexerAvailable checks if an indexer is available for a language.

func (*Service) ListFiles

func (s *Service) ListFiles(ctx context.Context, repoID int64, limit int) ([]string, error)

ListFiles returns all indexed files for a repository.

func (*Service) ListIndexedRepoIDs

func (s *Service) ListIndexedRepoIDs() ([]int64, error)

ListIndexedRepoIDs returns repo IDs that have SCIP database files on disk.

func (*Service) SearchSymbols

func (s *Service) SearchSymbols(
	ctx context.Context,
	repoID int64,
	query string,
	limit int,
) ([]SymbolSearchResult, error)

SearchSymbols searches for symbols by name pattern.

func (*Service) SupportedLanguages

func (s *Service) SupportedLanguages() []string

SupportedLanguages returns the list of supported languages.

type Store

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

Store provides SQLite-based storage for SCIP index data.

func NewStore

func NewStore(cacheDir string, logger *zap.Logger) (*Store, error)

NewStore creates a new SCIP store with the specified cache directory.

func (*Store) ClearIndex

func (s *Store) ClearIndex(ctx context.Context, repoID int64) error

ClearIndex removes all SCIP data for a repository.

func (*Store) Close

func (s *Store) Close() error

Close closes all database connections.

func (*Store) DeleteIndex

func (s *Store) DeleteIndex(ctx context.Context, repoID int64) error

DeleteIndex removes the SCIP database files for a repository, freeing disk space. Unlike ClearIndex (which empties tables), this removes the SQLite files entirely.

func (*Store) EvictCache

func (s *Store) EvictCache(repoID int64)

EvictCache closes and removes the in-memory cached connection for a repo. The next access will re-open the database from disk, picking up any changes.

func (*Store) FindReferences

func (s *Store) FindReferences(
	ctx context.Context,
	repoID int64,
	filePath string,
	line, col int,
	limit int,
) (*ReferencesResult, error)

FindReferences performs a complete find-references lookup.

func (*Store) GetDefinition

func (s *Store) GetDefinition(
	ctx context.Context,
	repoID int64,
	symbol string,
) (*Occurrence, error)

GetDefinition finds the definition of a symbol. It uses the version-independent symbol path for matching.

func (*Store) GetIndexMeta

func (s *Store) GetIndexMeta(ctx context.Context, repoID int64) (map[string]string, error)

GetIndexMeta returns metadata about the SCIP index.

func (*Store) GetOccurrenceAtPosition

func (s *Store) GetOccurrenceAtPosition(
	ctx context.Context,
	repoID int64,
	filePath string,
	line, col int,
) (*Occurrence, error)

GetOccurrenceAtPosition finds the symbol occurrence at a specific position.

func (*Store) GetReferenceCount

func (s *Store) GetReferenceCount(ctx context.Context, repoID int64, symbol string) (int, error)

GetReferenceCount returns the count of references to a symbol.

func (*Store) GetReferences

func (s *Store) GetReferences(
	ctx context.Context,
	repoID int64,
	symbol string,
	limit int,
) ([]Occurrence, error)

GetReferences finds all references to a symbol. It uses the version-independent symbol path for matching to handle cases where the same symbol was indexed at different commits.

func (*Store) GetSymbolInfo

func (s *Store) GetSymbolInfo(
	ctx context.Context,
	repoID int64,
	symbol string,
) (*SymbolInfo, error)

GetSymbolInfo returns information about a symbol.

func (*Store) GoToDefinition

func (s *Store) GoToDefinition(
	ctx context.Context,
	repoID int64,
	filePath string,
	line, col int,
) (*DefinitionResult, error)

GoToDefinition performs a complete go-to-definition lookup.

func (*Store) HasIndex

func (s *Store) HasIndex(ctx context.Context, repoID int64) (bool, error)

HasIndex checks if a SCIP index exists for a repository.

func (*Store) ListFiles

func (s *Store) ListFiles(ctx context.Context, repoID int64, limit int) ([]string, error)

ListFiles returns all files in the SCIP index.

func (*Store) ListIndexedRepoIDs

func (s *Store) ListIndexedRepoIDs() ([]int64, error)

ListIndexedRepoIDs returns the repo IDs that have SCIP database files on disk.

func (*Store) SearchSymbols

func (s *Store) SearchSymbols(
	ctx context.Context,
	repoID int64,
	query string,
	limit int,
) ([]SymbolSearchResult, error)

SearchSymbols searches for symbols by name pattern.

func (*Store) Stats

func (s *Store) Stats(ctx context.Context, repoID int64) (map[string]any, error)

Stats returns statistics about the SCIP index.

type SymbolInfo

type SymbolInfo struct {
	Symbol          string   `json:"symbol"`
	Documentation   string   `json:"documentation,omitempty"`
	Kind            int      `json:"kind,omitempty"`
	DisplayName     string   `json:"displayName,omitempty"`
	EnclosingSymbol string   `json:"enclosingSymbol,omitempty"`
	Relationships   []string `json:"relationships,omitempty"`
}

SymbolInfo represents metadata about a symbol.

type SymbolSearchResult

type SymbolSearchResult struct {
	Symbol        string `json:"symbol"`
	DisplayName   string `json:"displayName,omitempty"`
	FilePath      string `json:"filePath"`
	Line          int    `json:"line"`
	Documentation string `json:"documentation,omitempty"`
}

SymbolSearchResult represents a symbol found by search.

Jump to

Keyboard shortcuts

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