mago_analyzer/plugin/
mod.rs

1//! Plugin system for extending the analyzer with custom type inference and hooks.
2#![allow(clippy::module_inception)]
3
4pub mod context;
5pub mod error;
6pub mod hook;
7pub mod libraries;
8pub mod plugin;
9pub mod provider;
10pub mod registry;
11
12pub use context::*;
13pub use error::*;
14pub use hook::*;
15pub use plugin::*;
16pub use provider::*;
17pub use registry::PluginRegistry;
18
19/// Returns a list of all available plugins with their metadata.
20#[must_use]
21pub fn available_plugins() -> Vec<&'static PluginMeta> {
22    libraries::ALL_PLUGINS.iter().map(|p| p.meta()).collect()
23}
24
25/// Resolves a plugin name or alias to its canonical id.
26///
27/// Returns `None` if no plugin matches the given name.
28#[must_use]
29pub fn resolve_plugin_name(name: &str) -> Option<&'static str> {
30    for plugin in libraries::ALL_PLUGINS.iter() {
31        if plugin.meta().matches(name) {
32            return Some(plugin.meta().id);
33        }
34    }
35    None
36}
37
38/// Creates a plugin registry with the specified plugins enabled.
39///
40/// # Arguments
41///
42/// * `enabled_plugins` - List of plugin names/aliases to enable
43/// * `disable_defaults` - If true, default plugins are not automatically enabled
44///
45/// # Returns
46///
47/// A new `PluginRegistry` with only the specified plugins registered.
48#[must_use]
49pub fn create_registry_with_plugins(enabled_plugins: &[String], disable_defaults: bool) -> PluginRegistry {
50    let mut registry = PluginRegistry::new();
51
52    for plugin in libraries::ALL_PLUGINS.iter() {
53        let meta = plugin.meta();
54
55        // Check if explicitly enabled
56        let explicitly_enabled = enabled_plugins.iter().any(|name| meta.matches(name));
57
58        // Check if should be enabled by default
59        let default_enabled = !disable_defaults && meta.default_enabled;
60
61        if explicitly_enabled || default_enabled {
62            plugin.register(&mut registry);
63        }
64    }
65
66    registry
67}
68
69/// Creates a plugin registry with all library providers enabled.
70///
71/// This is the legacy behavior for backwards compatibility.
72#[must_use]
73pub fn create_registry() -> PluginRegistry {
74    let mut registry = PluginRegistry::new();
75    for plugin in libraries::ALL_PLUGINS.iter() {
76        plugin.register(&mut registry);
77    }
78
79    registry
80}