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