Skip to main content

Mountain/RPC/CocoonService/Debug/
RegisterDebugAdapter.rs

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