Mountain/RPC/CocoonService/Debug/
RegisterDebugAdapter.rs1#![allow(non_snake_case)]
2
3use serde_json::json;
7use tauri::Emitter;
8use tonic::{Response, Status};
9use CommonLibrary::LanguageFeature::DTO::ProviderType::ProviderType;
10
11use crate::{
12 ApplicationState::DTO::ProviderRegistrationDTO::ProviderRegistrationDTO,
13 RPC::CocoonService::CocoonServiceImpl,
14 Vine::Generated::{Empty, RegisterDebugAdapterRequest},
15 dev_log,
16};
17
18pub async fn Fn(Service:&CocoonServiceImpl, Request:RegisterDebugAdapterRequest) -> Result<Response<Empty>, Status> {
19 dev_log!("cocoon", "[CocoonService] Registering debug adapter: {}", Request.debug_type);
20
21 let Handle = Request
22 .debug_type
23 .as_bytes()
24 .iter()
25 .fold(0u32, |Acc, B| Acc.wrapping_mul(31).wrapping_add(*B as u32));
26
27 let DTO = ProviderRegistrationDTO {
28 Handle,
29
30 ProviderType:ProviderType::DebugAdapter,
31
32 Selector:json!([{ "debugType": Request.debug_type }]),
33
34 SideCarIdentifier:"cocoon-main".to_string(),
35
36 ExtensionIdentifier:json!(Request.extension_id),
37
38 Options:Some(json!({ "debugType": Request.debug_type })),
39 };
40
41 Service
42 .environment
43 .ApplicationState
44 .Extension
45 .ProviderRegistration
46 .RegisterProvider(Handle, DTO);
47
48 let _ = Service.environment.ApplicationHandle.emit(
49 "sky://debug/register",
50 json!({ "debugType": Request.debug_type, "extensionId": Request.extension_id }),
51 );
52
53 Ok(Response::new(Empty {}))
54}