Mountain/Environment/LanguageFeatureProvider/
Registration.rs1use CommonLibrary::{Error::CommonError::CommonError, LanguageFeature::DTO::ProviderType::ProviderType};
4use serde_json::Value;
5
6use crate::{
7 ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
8 Environment::Utility::ErrorMapping::MapApplicationStateLockErrorToCommonError,
9 dev_log,
10};
11
12pub(super) async fn register_provider(
13 environment:&crate::Environment::MountainEnvironment::MountainEnvironment,
14
15 side_car_identifier:String,
16
17 provider_type:ProviderType,
18
19 selector_dto:Value,
20
21 extension_identifier_dto:Value,
22
23 options_dto:Option<Value>,
24) -> Result<u32, CommonError> {
25 let handle = environment.ApplicationState.GetNextProviderHandle();
26
27 let new_registration = ProviderRegistrationDTO {
28 Handle:handle,
29
30 ProviderType:provider_type,
31
32 Selector:selector_dto,
33
34 SideCarIdentifier:side_car_identifier,
35
36 ExtensionIdentifier:extension_identifier_dto,
37
38 Options:options_dto,
39 };
40
41 environment
42 .ApplicationState
43 .Extension
44 .ProviderRegistration
45 .LanguageProviders
46 .lock()
47 .map_err(MapApplicationStateLockErrorToCommonError)?
48 .insert(handle, new_registration);
49
50 Ok(handle)
51}
52
53pub(super) async fn unregister_provider(
54 environment:&crate::Environment::MountainEnvironment::MountainEnvironment,
55
56 handle:u32,
57) -> Result<(), CommonError> {
58 let mut providers = environment
59 .ApplicationState
60 .Extension
61 .ProviderRegistration
62 .LanguageProviders
63 .lock()
64 .map_err(MapApplicationStateLockErrorToCommonError)?;
65
66 if providers.remove(&handle).is_none() {
67 dev_log!(
68 "extensions",
69 "warn: Attempted to unregister non-existent provider handle: {}",
70 handle
71 );
72 }
73
74 Ok(())
75}