mago_analyzer/plugin/hook/expression.rs
1//! Expression hooks for intercepting expression analysis.
2
3use mago_syntax::ast::Expression;
4
5use crate::plugin::context::HookContext;
6use crate::plugin::hook::ExpressionHookResult;
7use crate::plugin::hook::HookResult;
8use crate::plugin::provider::Provider;
9
10/// Hook trait for intercepting expression analysis.
11///
12/// This hook receives the real AST expression and full mutable context,
13/// allowing hooks to inspect expressions, report issues, modify analysis state,
14/// and optionally skip analysis with a custom type.
15pub trait ExpressionHook: Provider {
16 /// Called before an expression is analyzed.
17 ///
18 /// Return `ExpressionHookResult::Continue` to proceed with normal analysis,
19 /// `ExpressionHookResult::Skip` to skip analysis (type will be `mixed`), or
20 /// `ExpressionHookResult::SkipWithType(ty)` to skip with a custom type.
21 fn before_expression(
22 &self,
23 _expr: &Expression<'_>,
24 _context: &mut HookContext<'_, '_>,
25 ) -> HookResult<ExpressionHookResult> {
26 Ok(ExpressionHookResult::Continue)
27 }
28
29 /// Called after an expression has been analyzed.
30 fn after_expression(&self, _expr: &Expression<'_>, _context: &mut HookContext<'_, '_>) -> HookResult<()> {
31 Ok(())
32 }
33}