scryer-engine 0.2.1

Tree-sitter and stack-graphs AST indexing engine for Scryer code intelligence
use std::path::PathBuf;

/// Intermediate representation of an AST lexical scope extracted before database insertion.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawScope {
    /// Zero-based local scope index within the file.
    pub local_id: usize,
    /// Reference to the enclosing parent scope's `local_id`.
    pub parent_local_id: Option<usize>,
    /// Lexical category: `"module"`, `"class"`, `"function"`, `"closure"`, `"block"`.
    pub scope_kind: String,
    /// Zero-based byte offset of start of scope.
    pub start_byte: usize,
    /// Zero-based byte offset of end of scope.
    pub end_byte: usize,
    /// 1-indexed line number where the scope starts.
    pub start_line: u32,
    /// 1-indexed line number where the scope ends.
    pub end_line: u32,
}

/// Intermediate representation of a code symbol declaration extracted before database insertion.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawSymbol {
    /// Local scope index within the file containing this symbol declaration.
    pub scope_local_id: Option<usize>,
    /// Bare symbol identifier (e.g. `Scanner`).
    pub name: String,
    /// Hierarchically qualified symbol path (e.g. `crate::scanner::Scanner`).
    pub qualified_name: String,
    /// Kind: `"fn"`, `"struct"`, `"trait"`, `"enum"`, `"type"`, `"const"`, `"mod"`.
    pub kind: String,
    /// Normalized visibility modifier: `"public"`, `"crate"`, `"private"`.
    pub visibility: String,
    /// Condensed declaration signature (omitting body).
    pub signature: String,
    /// Associated doc comments / doc attributes formatted as Markdown.
    pub docstring: Option<String>,
    /// Zero-based byte offset of start of symbol.
    pub start_byte: usize,
    /// Zero-based byte offset of end of symbol.
    pub end_byte: usize,
    /// 1-indexed line number where the symbol starts.
    pub start_line: u32,
    /// 1-indexed line number where the symbol ends.
    pub end_line: u32,
}

/// Intermediate representation of a symbol reference extracted before database insertion.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawSymbolReference {
    /// Qualified name of the target symbol being referenced, or bare symbol name.
    pub target_symbol_name: String,
    /// Reference role: "call", "type_annotation", "read", "write", "import".
    pub role: String,
    /// Zero-based byte offset of start of reference.
    pub start_byte: usize,
    /// Zero-based byte offset of end of reference.
    pub end_byte: usize,
    /// 1-indexed line number where the reference occurs.
    pub line_number: u32,
}

/// Intermediate representation of a code graph edge between two symbols.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawCodeGraphEdge {
    /// Qualified or bare name of the source (caller/origin) symbol.
    pub source_symbol_name: String,
    /// Qualified or bare name of the target (callee/destination) symbol.
    pub target_symbol_name: String,
    /// Edge type: "calls", "implements", "instantiates", "imports".
    pub edge_type: String,
}

/// Fully extracted and parsed file metadata and syntactic entities.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParsedFilePayload {
    /// Normalized path relative to the project root.
    pub relative_path: PathBuf,
    /// 256-bit BLAKE3 hash of file content.
    pub content_hash: String,
    /// Canonical language identifier (e.g. `"rust"`).
    pub language: String,
    /// Total lines in the file.
    pub line_count: u32,
    /// File size in bytes.
    pub byte_size: usize,
    /// Extracted scopes in topological/parent-first order.
    pub scopes: Vec<RawScope>,
    /// Extracted symbol declarations.
    pub symbols: Vec<RawSymbol>,
    /// Extracted symbol usages / references.
    pub references: Vec<RawSymbolReference>,
    /// Extracted call graph and dependency edges.
    pub edges: Vec<RawCodeGraphEdge>,
}

/// Structural representation of a type contract extracted from AST and symbol tables.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RawTypeContract {
    pub found: bool,
    pub type_name: String,
    pub kind: Option<String>,
    pub signature: Option<String>,
    pub docstring: Option<String>,
    pub file_path: Option<String>,
    pub members: Vec<String>,
}