refactor: update meta plugins structure to use map and vector

Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-28 17:07:05 -03:00
parent 983af9b30f
commit fe41f95570
3 changed files with 22 additions and 66 deletions

View File

@@ -13,7 +13,8 @@ use crate::meta_plugin;
pub struct StatusInfo { pub struct StatusInfo {
pub paths: PathInfo, pub paths: PathInfo,
pub compression: Vec<CompressionInfo>, pub compression: Vec<CompressionInfo>,
pub meta_plugins: Vec<MetaPluginInfo>, pub meta_plugins: std::collections::HashMap<String, MetaPluginInfo>,
pub enabled_meta_plugins: Vec<String>,
} }
#[derive(serde::Serialize, serde::Deserialize, ToSchema)] #[derive(serde::Serialize, serde::Deserialize, ToSchema)]
@@ -36,10 +37,6 @@ pub struct CompressionInfo {
#[derive(serde::Serialize, serde::Deserialize, ToSchema, Clone)] #[derive(serde::Serialize, serde::Deserialize, ToSchema, Clone)]
pub struct MetaPluginInfo { pub struct MetaPluginInfo {
pub meta_name: String, pub meta_name: String,
pub found: bool,
pub enabled: bool,
pub binary: String,
pub args: String,
pub outputs: std::collections::HashMap<String, serde_yaml::Value>, pub outputs: std::collections::HashMap<String, serde_yaml::Value>,
pub options: std::collections::HashMap<String, serde_yaml::Value>, pub options: std::collections::HashMap<String, serde_yaml::Value>,
} }
@@ -93,7 +90,8 @@ pub fn generate_status_info(
}); });
} }
let mut meta_plugin_info = Vec::new(); let mut meta_plugins_map = std::collections::HashMap::new();
let mut enabled_meta_plugins_vec = Vec::new();
// Sort meta plugin types by their string representation to avoid creating plugins just for sorting // Sort meta plugin types by their string representation to avoid creating plugins just for sorting
let mut sorted_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter().collect(); let mut sorted_meta_plugins: Vec<MetaPluginType> = MetaPluginType::iter().collect();
@@ -104,33 +102,17 @@ pub fn generate_status_info(
log::debug!("STATUS: About to call get_meta_plugin"); log::debug!("STATUS: About to call get_meta_plugin");
let meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone(), None, None); let meta_plugin = meta_plugin::get_meta_plugin(meta_plugin_type.clone(), None, None);
log::debug!("STATUS: Created meta plugin instance"); log::debug!("STATUS: Created meta plugin instance");
let is_supported = meta_plugin.is_supported();
log::debug!("STATUS: Checked is_supported: {}", is_supported);
let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
log::debug!("STATUS: Checked is_enabled: {}", is_enabled);
// Get meta name first to avoid borrowing issues // Get meta name first to avoid borrowing issues
log::debug!("STATUS: Getting meta name..."); log::debug!("STATUS: Getting meta name...");
let meta_name = meta_plugin.meta_type().to_string(); let meta_name = meta_plugin.meta_type().to_string();
log::debug!("STATUS: Got meta name: {}", meta_name); log::debug!("STATUS: Got meta name: {}", meta_name);
// Note: In status mode we don't have access to actual settings, // Check if this plugin is enabled
// so we can't configure plugins with their settings here. let is_enabled = enabled_meta_plugins.contains(&meta_plugin_type);
// Plugin configuration happens during save operations. if is_enabled {
enabled_meta_plugins_vec.push(meta_name.clone());
let (binary_display, args_display) = if !is_supported {
("<NOT FOUND>".to_string(), "".to_string())
} else {
if meta_plugin.is_internal() {
("<INTERNAL>".to_string(), "".to_string())
} else {
if let Some((program, args)) = meta_plugin.program_info() {
(program.to_string(), args.join(" "))
} else {
("<NOT FOUND>".to_string(), "".to_string())
} }
}
};
// Create a display of outputs for status - use configured outputs if available, otherwise defaults // Create a display of outputs for status - use configured outputs if available, otherwise defaults
let outputs_display = if meta_plugin.outputs().is_empty() { let outputs_display = if meta_plugin.outputs().is_empty() {
@@ -145,20 +127,20 @@ pub fn generate_status_info(
meta_plugin.outputs().clone() meta_plugin.outputs().clone()
}; };
meta_plugin_info.push(MetaPluginInfo { // Get options
let options = meta_plugin.options().clone();
meta_plugins_map.insert(meta_name.clone(), MetaPluginInfo {
meta_name, meta_name,
found: is_supported,
enabled: is_enabled,
binary: binary_display,
args: args_display,
outputs: outputs_display, outputs: outputs_display,
options: std::collections::HashMap::new(), options,
}); });
} }
StatusInfo { StatusInfo {
paths: path_info, paths: path_info,
compression: compression_info, compression: compression_info,
meta_plugins: meta_plugin_info, meta_plugins: meta_plugins_map,
enabled_meta_plugins: enabled_meta_plugins_vec,
} }
} }

View File

@@ -272,7 +272,7 @@ fn build_meta_plugins_configured_table(settings: &config::Settings) -> Option<Ta
Some(table) Some(table)
} }
fn build_meta_plugin_table(meta_plugin_info: &Vec<MetaPluginInfo>) -> Table { fn build_meta_plugin_table(meta_plugin_info: &std::collections::HashMap<String, MetaPluginInfo>) -> Table {
let mut meta_plugin_table = Table::new(); let mut meta_plugin_table = Table::new();
if std::io::stdout().is_terminal() { if std::io::stdout().is_terminal() {
//meta_plugin_table.set_format(get_format_box_chars_no_border_line_separator()); //meta_plugin_table.set_format(get_format_box_chars_no_border_line_separator());
@@ -287,7 +287,7 @@ fn build_meta_plugin_table(meta_plugin_info: &Vec<MetaPluginInfo>) -> Table {
b->"Outputs")); b->"Outputs"));
// Sort meta plugin info by plugin name // Sort meta plugin info by plugin name
let mut sorted_meta_plugin_info = meta_plugin_info.clone(); let mut sorted_meta_plugin_info: Vec<&MetaPluginInfo> = meta_plugin_info.values().collect();
sorted_meta_plugin_info.sort_by(|a, b| a.meta_name.cmp(&b.meta_name)); sorted_meta_plugin_info.sort_by(|a, b| a.meta_name.cmp(&b.meta_name));
for info in sorted_meta_plugin_info { for info in sorted_meta_plugin_info {

View File

@@ -38,21 +38,8 @@ impl StatusService {
let mut status_info = generate_status_info(data_path, db_path, &meta_plugin_types, enabled_compression_type); let mut status_info = generate_status_info(data_path, db_path, &meta_plugin_types, enabled_compression_type);
// Add options to each meta plugin info // The options are now populated directly in generate_status_info
for meta_plugin_info in &mut status_info.meta_plugins { // No need to modify them here
let meta_plugin_type = MetaPluginType::from_str(&meta_plugin_info.meta_name).unwrap();
let plugin = crate::meta_plugin::get_meta_plugin(meta_plugin_type, None, None);
// Convert options to a serializable format
let options: std::collections::HashMap<String, serde_yaml::Value> = plugin
.options()
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
// Add options to the meta plugin info
meta_plugin_info.options = options;
}
status_info status_info
} }
@@ -75,21 +62,8 @@ impl StatusService {
let mut status_info = generate_status_info(data_path, db_path, &supported_meta_plugins, enabled_compression_type); let mut status_info = generate_status_info(data_path, db_path, &supported_meta_plugins, enabled_compression_type);
// Add options to each meta plugin info // The options are now populated directly in generate_status_info
for meta_plugin_info in &mut status_info.meta_plugins { // No need to modify them here
let meta_plugin_type = MetaPluginType::from_str(&meta_plugin_info.meta_name).unwrap();
let plugin = crate::meta_plugin::get_meta_plugin(meta_plugin_type, None, None);
// Convert options to a serializable format
let options: std::collections::HashMap<String, serde_yaml::Value> = plugin
.options()
.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect();
// Add options to the meta plugin info
meta_plugin_info.options = options;
}
status_info status_info
} }