Skip to main content

mago_analyzer/plugin/
plugin.rs

1//! Plugin trait and metadata for analyzer plugins.
2
3use crate::plugin::PluginRegistry;
4
5/// Metadata describing an analyzer plugin.
6#[derive(Debug, Clone)]
7pub struct PluginMeta {
8    /// Canonical plugin identifier (e.g., "stdlib").
9    pub id: &'static str,
10    /// Human-readable name (e.g., "PHP Standard Library").
11    pub name: &'static str,
12    /// Description of what the plugin provides.
13    pub description: &'static str,
14    /// Alternative names that resolve to this plugin.
15    pub aliases: &'static [&'static str],
16    /// Whether this plugin is enabled by default.
17    pub default_enabled: bool,
18}
19
20impl PluginMeta {
21    /// Creates a new plugin metadata.
22    #[must_use]
23    pub const fn new(
24        id: &'static str,
25        name: &'static str,
26        description: &'static str,
27        aliases: &'static [&'static str],
28        default_enabled: bool,
29    ) -> Self {
30        Self { id, name, description, aliases, default_enabled }
31    }
32
33    /// Checks if the given name matches this plugin (either id or alias).
34    #[must_use]
35    pub fn matches(&self, name: &str) -> bool {
36        let name_lower = name.to_lowercase();
37        if self.id.to_lowercase() == name_lower {
38            return true;
39        }
40        self.aliases.iter().any(|alias| alias.to_lowercase() == name_lower)
41    }
42}
43
44/// Trait for analyzer plugins that provide type inference and analysis hooks.
45pub trait Plugin: Send + Sync {
46    /// Returns the metadata for this plugin.
47    fn meta(&self) -> &'static PluginMeta;
48
49    /// Registers all providers and hooks from this plugin into the registry.
50    fn register(&self, registry: &mut PluginRegistry);
51}