Tidy remote installed marketplace grouping

This commit is contained in:
xli-oai
2026-05-15 03:05:07 -07:00
parent 510e886624
commit 4064ad2e35

View File

@@ -63,6 +63,24 @@ const REMOTE_PLUGIN_CATALOG_TIMEOUT: Duration = Duration::from_secs(30);
const REMOTE_PLUGIN_LIST_PAGE_LIMIT: u32 = 200;
const MAX_REMOTE_DEFAULT_PROMPT_LEN: usize = 128;
const INVALID_REQUEST_ERROR_CODE: i64 = -32600;
const REMOTE_INSTALLED_MARKETPLACE_DISPLAY_ORDER: [(&str, &str); 4] = [
(
REMOTE_GLOBAL_MARKETPLACE_NAME,
REMOTE_GLOBAL_MARKETPLACE_DISPLAY_NAME,
),
(
REMOTE_WORKSPACE_MARKETPLACE_NAME,
REMOTE_WORKSPACE_MARKETPLACE_DISPLAY_NAME,
),
(
REMOTE_WORKSPACE_SHARED_WITH_ME_PRIVATE_MARKETPLACE_NAME,
REMOTE_WORKSPACE_SHARED_WITH_ME_PRIVATE_MARKETPLACE_DISPLAY_NAME,
),
(
REMOTE_WORKSPACE_SHARED_WITH_ME_UNLISTED_MARKETPLACE_NAME,
REMOTE_WORKSPACE_SHARED_WITH_ME_UNLISTED_MARKETPLACE_DISPLAY_NAME,
),
];
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemotePluginServiceConfig {
@@ -611,13 +629,7 @@ fn build_remote_marketplace(
})
.map(|(plugin, installed_plugin)| build_remote_plugin_summary(plugin, installed_plugin))
.collect::<Result<Vec<_>, _>>()?;
plugins.sort_by(|left, right| {
remote_plugin_display_name(left)
.to_ascii_lowercase()
.cmp(&remote_plugin_display_name(right).to_ascii_lowercase())
.then_with(|| remote_plugin_display_name(left).cmp(remote_plugin_display_name(right)))
.then_with(|| left.id.cmp(&right.id))
});
sort_remote_plugin_summaries_by_display_name(&mut plugins);
Ok(Some(RemoteMarketplace {
name: name.to_string(),
display_name: display_name.to_string(),
@@ -660,8 +672,11 @@ pub fn group_remote_installed_plugins_by_marketplaces(
) -> Vec<RemoteMarketplace> {
let mut plugins_by_marketplace = BTreeMap::<String, Vec<RemotePluginSummary>>::new();
for (marketplace_name, plugin_summary) in plugins.iter().filter_map(|plugin| {
let plugin_id = PluginId::new(plugin.name.clone(), plugin.marketplace_name.clone()).ok()?;
for plugin in plugins {
let Ok(plugin_id) = PluginId::new(plugin.name.clone(), plugin.marketplace_name.clone())
else {
continue;
};
let plugin_summary = RemotePluginSummary {
id: plugin_id.as_key(),
remote_plugin_id: plugin.id.clone(),
@@ -675,51 +690,24 @@ pub fn group_remote_installed_plugins_by_marketplaces(
interface: plugin.interface.clone(),
keywords: plugin.keywords.clone(),
};
Some((plugin.marketplace_name.clone(), plugin_summary))
}) {
plugins_by_marketplace
.entry(marketplace_name)
.entry(plugin.marketplace_name.clone())
.or_default()
.push(plugin_summary);
}
[
(
REMOTE_GLOBAL_MARKETPLACE_NAME,
REMOTE_GLOBAL_MARKETPLACE_DISPLAY_NAME,
),
(
REMOTE_WORKSPACE_MARKETPLACE_NAME,
REMOTE_WORKSPACE_MARKETPLACE_DISPLAY_NAME,
),
(
REMOTE_WORKSPACE_SHARED_WITH_ME_PRIVATE_MARKETPLACE_NAME,
REMOTE_WORKSPACE_SHARED_WITH_ME_PRIVATE_MARKETPLACE_DISPLAY_NAME,
),
(
REMOTE_WORKSPACE_SHARED_WITH_ME_UNLISTED_MARKETPLACE_NAME,
REMOTE_WORKSPACE_SHARED_WITH_ME_UNLISTED_MARKETPLACE_DISPLAY_NAME,
),
]
.into_iter()
.filter_map(|(marketplace_name, display_name)| {
let mut marketplace_plugins = plugins_by_marketplace.remove(marketplace_name)?;
marketplace_plugins.sort_by(|left, right| {
let left_display_name = remote_plugin_display_name(left);
let right_display_name = remote_plugin_display_name(right);
left_display_name
.to_ascii_lowercase()
.cmp(&right_display_name.to_ascii_lowercase())
.then_with(|| left_display_name.cmp(right_display_name))
.then_with(|| left.id.cmp(&right.id))
});
Some(RemoteMarketplace {
name: marketplace_name.to_string(),
display_name: display_name.to_string(),
plugins: marketplace_plugins,
REMOTE_INSTALLED_MARKETPLACE_DISPLAY_ORDER
.into_iter()
.filter_map(|(marketplace_name, display_name)| {
let mut marketplace_plugins = plugins_by_marketplace.remove(marketplace_name)?;
sort_remote_plugin_summaries_by_display_name(&mut marketplace_plugins);
Some(RemoteMarketplace {
name: marketplace_name.to_string(),
display_name: display_name.to_string(),
plugins: marketplace_plugins,
})
})
})
.collect()
.collect()
}
pub async fn fetch_remote_plugin_detail(
@@ -1141,6 +1129,18 @@ fn remote_plugin_display_name(plugin: &RemotePluginSummary) -> &str {
.unwrap_or(&plugin.name)
}
fn sort_remote_plugin_summaries_by_display_name(plugins: &mut [RemotePluginSummary]) {
plugins.sort_by(|left, right| {
let left_display_name = remote_plugin_display_name(left);
let right_display_name = remote_plugin_display_name(right);
left_display_name
.to_ascii_lowercase()
.cmp(&right_display_name.to_ascii_lowercase())
.then_with(|| left_display_name.cmp(right_display_name))
.then_with(|| left.id.cmp(&right.id))
});
}
fn non_empty_string(value: Option<&str>) -> Option<String> {
value.and_then(|value| {
let value = value.trim();