CommonLibrary/LanguageFeature/RegisterProvider.rs
1//! # RegisterProvider Effect
2//!
3//! Defines the `ActionEffect` for registering a new language feature provider.
4
5use std::sync::Arc;
6
7use serde_json::Value;
8
9use super::{DTO::ProviderType::ProviderType, LanguageFeatureProviderRegistry::LanguageFeatureProviderRegistry};
10use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
11
12/// Creates an effect that, when executed, will register a new language feature
13/// provider with the host's central registry.
14///
15/// It uses the `LanguageFeatureProviderRegistry` capability from the
16/// environment.
17///
18/// # Parameters
19/// * `ProviderType`: The enum variant identifying the feature type.
20/// * `SelectorDTO`: The document selector that determines when this provider is
21/// active.
22/// * `SideCarIdentifier`: The ID of the sidecar hosting the provider logic.
23/// * `ExtensionIdentifierDTO`: The ID of the extension contributing the
24/// provider.
25/// * `OptionsDTO`: Optional, feature-specific options.
26///
27/// # Returns
28/// An `ActionEffect` that resolves with a unique `u32` handle for the
29/// registration.
30pub fn RegisterProvider(
31 ProviderType:ProviderType,
32
33 SelectorDTO:Value,
34
35 SideCarIdentifier:String,
36
37 ExtensionIdentifierDTO:Value,
38
39 OptionsDTO:Option<Value /* ProviderOptionsDTO */>,
40) -> ActionEffect<Arc<dyn LanguageFeatureProviderRegistry>, CommonError, u32> {
41 ActionEffect::New(Arc::new(move |Registry:Arc<dyn LanguageFeatureProviderRegistry>| {
42 let SelectorClone = SelectorDTO.clone();
43
44 let SideCarIdentifierClone = SideCarIdentifier.clone();
45
46 let ExtensionIdentifierClone = ExtensionIdentifierDTO.clone();
47
48 let OptionsClone = OptionsDTO.clone();
49
50 Box::pin(async move {
51 Registry
52 .RegisterProvider(
53 SideCarIdentifierClone,
54 ProviderType,
55 SelectorClone,
56 ExtensionIdentifierClone,
57 OptionsClone,
58 )
59 .await
60 })
61 }))
62}