mago_analyzer/plugin/hook/expression.rs
1//! Expression hooks for intercepting expression analysis.
2
3use mago_syntax::cst::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 ///
22 /// # Errors
23 ///
24 /// Returns [`HookError`] if the underlying plugin implementation propagates one.
25 fn before_expression(
26 &self,
27 _expr: &Expression<'_>,
28 _context: &mut HookContext<'_, '_>,
29 ) -> HookResult<ExpressionHookResult> {
30 Ok(ExpressionHookResult::Continue)
31 }
32
33 /// Called after an expression has been analyzed.
34 ///
35 /// # Errors
36 ///
37 /// Returns [`HookError`] if the underlying plugin implementation propagates one.
38 fn after_expression(&self, _expr: &Expression<'_>, _context: &mut HookContext<'_, '_>) -> HookResult<()> {
39 Ok(())
40 }
41}