Skip to main content

mago_analyzer/plugin/hook/
statement.rs

1//! Statement hooks for intercepting statement analysis.
2
3use mago_syntax::cst::Statement;
4
5use crate::plugin::context::HookContext;
6use crate::plugin::hook::HookAction;
7use crate::plugin::hook::HookResult;
8use crate::plugin::provider::Provider;
9
10/// Hook trait for intercepting statement analysis.
11///
12/// This hook receives the real AST statement and full mutable context,
13/// allowing hooks to inspect statements, report issues, and modify analysis state.
14pub trait StatementHook: Provider {
15    /// Called before a statement is analyzed.
16    ///
17    /// Return `HookAction::Continue` to proceed with normal analysis, or
18    /// `HookAction::Skip` to skip analysis of this statement.
19    ///
20    /// # Errors
21    ///
22    /// Returns [`HookError`] if the underlying plugin implementation propagates one.
23    fn before_statement(&self, _stmt: &Statement<'_>, _context: &mut HookContext<'_, '_>) -> HookResult<HookAction> {
24        Ok(HookAction::Continue)
25    }
26
27    /// Called after a statement has been analyzed.
28    ///
29    /// # Errors
30    ///
31    /// Returns [`HookError`] if the underlying plugin implementation propagates one.
32    fn after_statement(&self, _stmt: &Statement<'_>, _context: &mut HookContext<'_, '_>) -> HookResult<()> {
33        Ok(())
34    }
35}