scribe_analysis/
lib.rs

1//! # Scribe Analysis
2//! 
3//! Code analysis algorithms and heuristic scoring for the Scribe library.
4//! This crate provides sophisticated file prioritization using multi-dimensional 
5//! heuristic scoring, template detection, and import graph analysis.
6
7pub mod heuristics;
8pub mod ast_import_parser;
9
10// Legacy modules (kept for compatibility)
11pub mod ast;
12pub mod parser;
13pub mod analyzer;
14pub mod metrics;
15pub mod symbols;
16pub mod dependencies;
17
18// Re-export main heuristics types
19pub use heuristics::{
20    HeuristicSystem, 
21    HeuristicScorer, 
22    ScoreComponents, 
23    HeuristicWeights,
24    ScoringFeatures,
25    DocumentAnalysis,
26    TemplateDetector,
27    TemplateEngine,
28    ImportGraphBuilder,
29    ImportGraph,
30    is_template_file,
31    get_template_score_boost,
32    import_matches_file,
33};
34
35// Legacy re-exports
36pub use ast::{AstNode, AstWalker};
37pub use parser::{Parser, ParseResult};
38pub use analyzer::{CodeAnalyzer, AnalysisResult};
39pub use metrics::{Metrics, ComplexityMetrics};
40pub use symbols::{Symbol, SymbolTable};
41
42use scribe_core::Result;
43
44// Import the types module
45pub use ast::types;
46
47/// Main entry point for code analysis
48pub struct Analysis {
49    parser: Parser,
50    analyzer: CodeAnalyzer,
51}
52
53impl Analysis {
54    /// Create a new analysis instance
55    pub fn new() -> Result<Self> {
56        Ok(Self {
57            parser: Parser::new()?,
58            analyzer: CodeAnalyzer::new(),
59        })
60    }
61
62    /// Analyze a piece of code
63    pub async fn analyze(&self, code: &str, language: &str) -> Result<AnalysisResult> {
64        let ast = self.parser.parse(code, language)?;
65        self.analyzer.analyze(&ast).await
66    }
67}
68
69impl Default for Analysis {
70    fn default() -> Self {
71        Self::new().expect("Failed to create Analysis")
72    }
73}
74
75#[cfg(test)]
76mod tests {
77    use super::*;
78
79    #[tokio::test]
80    async fn test_analysis_creation() {
81        let analysis = Analysis::new();
82        assert!(analysis.is_ok());
83    }
84}