mago_analyzer/plugin/hook/program.rs
1//! Program hooks for intercepting program-level analysis.
2
3use mago_database::file::File;
4use mago_syntax::ast::Program;
5
6use crate::plugin::context::HookContext;
7use crate::plugin::hook::HookAction;
8use crate::plugin::hook::HookResult;
9use crate::plugin::provider::Provider;
10
11/// Hook trait for intercepting program-level analysis.
12///
13/// This hook is called before and after analyzing a complete program (file).
14/// It receives the source file, full AST, and mutable context, allowing hooks to:
15/// - Access file information (id, path, content)
16/// - Inspect the entire program structure
17/// - Report issues at the program level
18/// - Pre-register variables before analysis
19/// - Skip analysis entirely
20pub trait ProgramHook: Provider {
21 /// Called before a program is analyzed.
22 ///
23 /// Return `HookAction::Continue` to proceed with normal analysis, or
24 /// `HookAction::Skip` to skip analysis of this program entirely.
25 fn before_program(
26 &self,
27 _file: &File,
28 _program: &Program<'_>,
29 _context: &mut HookContext<'_, '_>,
30 ) -> HookResult<HookAction> {
31 Ok(HookAction::Continue)
32 }
33
34 /// Called after a program has been analyzed.
35 fn after_program(
36 &self,
37 _file: &File,
38 _program: &Program<'_>,
39 _context: &mut HookContext<'_, '_>,
40 ) -> HookResult<()> {
41 Ok(())
42 }
43}