Skip to content

Commit d382d0a

Browse files
committed
Optimize search capability check in plugin filtering
1 parent 638a438 commit d382d0a

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ impl PluginManager {
326326
}
327327
if let Some(map) = enabled_caps {
328328
if let Some(caps) = map.get(name) {
329-
if !caps.contains(&"search".to_string()) {
329+
if !caps.iter().any(|c| c == "search") {
330330
continue;
331331
}
332332
}

tests/plugin_routing.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,28 @@ fn global_plugins_and_opt_out_plugins_still_run() {
128128
assert_eq!(prefixed_calls.load(Ordering::SeqCst), 0);
129129
}
130130

131+
#[test]
132+
fn search_capability_gate_skips_plugin_when_disabled() {
133+
use std::collections::HashMap;
134+
135+
let calls = Arc::new(AtomicUsize::new(0));
136+
137+
let mut pm = PluginManager::new();
138+
pm.register(Box::new(CountingPlugin::new(
139+
"searchable",
140+
&[],
141+
false,
142+
calls.clone(),
143+
)));
144+
145+
let mut enabled_caps = HashMap::new();
146+
enabled_caps.insert("searchable".to_string(), vec!["commands".to_string()]);
147+
148+
let out = pm.search_filtered("query", None, Some(&enabled_caps));
149+
assert!(out.is_empty());
150+
assert_eq!(calls.load(Ordering::SeqCst), 0);
151+
}
152+
131153
#[test]
132154
fn existing_prefix_commands_remain_equivalent() {
133155
let plugin = TodoPlugin::default();

0 commit comments

Comments
 (0)