provider

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package provider defines the public interface for language extractors. External packages implement this interface to add language support to graphize.

This follows the omnillm-core provider pattern, allowing external packages to register extractors without creating circular dependencies.

Index

Constants

View Source
const (
	PriorityDefault = 0   // Default built-in providers
	PriorityThick   = 10  // SDK-based providers (can override default)
	PriorityCustom  = 100 // User-provided custom providers
)

Priority levels for provider registration. Higher priority extractors override lower priority ones for the same extension.

Variables

This section is empty.

Functions

func CanExtract

func CanExtract(path string) bool

CanExtract returns true if there is an extractor registered for the given path.

func Extensions

func Extensions() []string

Extensions returns all registered file extensions.

func Languages

func Languages() []string

Languages returns all registered language names.

func NodeIDPrefix

func NodeIDPrefix(language string) string

NodeIDPrefix returns the standard prefix for node IDs for a given language. This ensures unique node IDs in polyglot repositories.

func Register

func Register(factory ExtractorFactory, priority int)

Register adds an extractor factory with priority. Higher priority extractors override lower priority ones for the same extension. Call this from init() in your extractor package.

Types

type ExtractStats

type ExtractStats struct {
	TotalFiles  int            `json:"total_files"`
	CacheHits   int            `json:"cache_hits"`
	CacheMisses int            `json:"cache_misses"`
	Errors      int            `json:"errors"`
	ByLanguage  map[string]int `json:"by_language,omitempty"`
}

ExtractStats tracks extraction statistics across multiple files.

func NewExtractStats

func NewExtractStats() *ExtractStats

NewExtractStats creates a new ExtractStats instance.

type ExtractorFactory

type ExtractorFactory func() LanguageExtractor

ExtractorFactory creates an extractor instance.

type FrameworkInfo

type FrameworkInfo struct {
	// Name is the canonical framework name (e.g., "spring", "express", "rails").
	Name string `json:"name"`

	// Version is the detected version if available.
	Version string `json:"version,omitempty"`

	// Layer indicates the architectural layer (e.g., "controller", "service", "repository").
	Layer string `json:"layer,omitempty"`

	// Annotations are framework-specific annotations found (for Java/Kotlin).
	Annotations []string `json:"annotations,omitempty"`

	// Conventions are framework-specific conventions matched (for Rails, etc.).
	Conventions []string `json:"conventions,omitempty"`
}

FrameworkInfo describes a detected framework in source code.

type LanguageExtractor

type LanguageExtractor interface {
	// Language returns the canonical name of the language (e.g., "go", "typescript", "java").
	Language() string

	// Extensions returns the file extensions this extractor handles (e.g., [".go"], [".ts", ".tsx"]).
	Extensions() []string

	// CanExtract returns true if this extractor can handle the given file path.
	// This is typically based on file extension but may include additional logic.
	CanExtract(path string) bool

	// ExtractFile extracts nodes and edges from a single source file.
	// The baseDir is used to compute relative paths for node IDs.
	ExtractFile(path, baseDir string) ([]*graph.Node, []*graph.Edge, error)

	// DetectFramework returns framework information if detected in the file.
	// Returns nil if no framework is detected.
	DetectFramework(path string) *FrameworkInfo
}

LanguageExtractor defines the interface for language-specific code extractors. Each implementation handles parsing and extraction for a specific programming language.

External packages implement this interface and register via Register() in their init().

func Get

func Get(extension string) LanguageExtractor

Get returns the extractor for a file extension. Returns nil if no extractor is registered for the extension.

func GetByLanguage

func GetByLanguage(language string) LanguageExtractor

GetByLanguage returns the extractor for a language name. Returns nil if no extractor is registered for the language.

func GetByPath

func GetByPath(path string) LanguageExtractor

GetByPath returns the extractor for a file path. Returns nil if no extractor is registered for the file's extension.

Jump to

Keyboard shortcuts

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