web_search_providers.rs

 1mod cloud;
 2
 3use client::Client;
 4use feature_flags::{FeatureFlagAppExt, ZedProWebSearchTool};
 5use gpui::{App, Context};
 6use std::sync::Arc;
 7use web_search::WebSearchRegistry;
 8
 9pub fn init(client: Arc<Client>, cx: &mut App) {
10    let registry = WebSearchRegistry::global(cx);
11    registry.update(cx, |registry, cx| {
12        register_web_search_providers(registry, client, cx);
13    });
14}
15
16fn register_web_search_providers(
17    _registry: &mut WebSearchRegistry,
18    client: Arc<Client>,
19    cx: &mut Context<WebSearchRegistry>,
20) {
21    cx.observe_flag::<ZedProWebSearchTool, _>({
22        let client = client.clone();
23        move |is_enabled, cx| {
24            if is_enabled {
25                WebSearchRegistry::global(cx).update(cx, |registry, cx| {
26                    registry.register_provider(
27                        cloud::CloudWebSearchProvider::new(client.clone(), cx),
28                        cx,
29                    );
30                });
31            }
32        }
33    })
34    .detach();
35}