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;
9pub mod complexity;
10pub mod language_support;
11
12// Legacy modules (kept for compatibility)
13pub mod ast;
14pub mod parser;
15pub mod analyzer;
16pub mod metrics;
17pub mod symbols;
18pub mod dependencies;
19
20// Re-export main heuristics types
21pub use heuristics::{
22    HeuristicSystem, 
23    HeuristicScorer, 
24    ScoreComponents, 
25    HeuristicWeights,
26    ScoringFeatures,
27    DocumentAnalysis,
28    TemplateDetector,
29    TemplateEngine,
30    ImportGraphBuilder,
31    ImportGraph,
32    is_template_file,
33    get_template_score_boost,
34    import_matches_file,
35};
36
37// Re-export complexity analysis types
38pub use complexity::{
39    ComplexityAnalyzer,
40    ComplexityMetrics as ComplexityAnalysisMetrics,
41    ComplexityConfig,
42    ComplexityThresholds,
43    LanguageSpecificMetrics,
44};
45
46// Re-export language support types
47pub use language_support::{
48    AstLanguage, LanguageTier, LanguageFeatures,
49    FunctionExtractor, FunctionInfo, ClassInfo,
50    DocumentationAnalyzer, DocumentationCoverage,
51    SymbolAnalyzer, SymbolUsage, SymbolType,
52    LanguageMetrics, LanguageSpecificComplexity,
53    LanguageSupport, LanguageAnalysisResult,
54    analyze_file_language,
55};
56
57// Legacy re-exports
58pub use ast::{AstNode, AstWalker};
59pub use parser::{Parser, ParseResult};
60pub use analyzer::{CodeAnalyzer, AnalysisResult};
61pub use metrics::{Metrics, ComplexityMetrics as LegacyComplexityMetrics};
62pub use symbols::{Symbol, SymbolTable};
63
64use scribe_core::Result;
65
66// Import the types module
67pub use ast::types;
68
69/// Main entry point for code analysis
70pub struct Analysis {
71    parser: Parser,
72    analyzer: CodeAnalyzer,
73}
74
75impl Analysis {
76    /// Create a new analysis instance
77    pub fn new() -> Result<Self> {
78        Ok(Self {
79            parser: Parser::new()?,
80            analyzer: CodeAnalyzer::new(),
81        })
82    }
83
84    /// Analyze a piece of code
85    pub async fn analyze(&self, code: &str, language: &str) -> Result<AnalysisResult> {
86        let ast = self.parser.parse(code, language)?;
87        self.analyzer.analyze(&ast).await
88    }
89}
90
91impl Default for Analysis {
92    fn default() -> Self {
93        Self::new().expect("Failed to create Analysis")
94    }
95}
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100
101    #[tokio::test]
102    async fn test_analysis_creation() {
103        let analysis = Analysis::new();
104        assert!(analysis.is_ok());
105    }
106}