Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/RPC/CocoonService/Debug/
StartDebugging.rs

1//! Start a debug session. Mints a session id, emits `sky://debug/start` so
2//! the workbench can render the debug toolbar/console.
3
4use std::time::{SystemTime, UNIX_EPOCH};
5
6use serde_json::json;
7use tauri::Emitter;
8use tonic::{Response, Status};
9
10use crate::{
11	RPC::CocoonService::CocoonServiceImpl,
12	Vine::Generated::{StartDebuggingRequest, StartDebuggingResponse},
13	dev_log,
14};
15
16pub async fn Fn(
17	Service:&CocoonServiceImpl,
18
19	Request:StartDebuggingRequest,
20) -> Result<Response<StartDebuggingResponse>, Status> {
21	dev_log!("cocoon", "[CocoonService] start_debugging: type={}", Request.debug_type);
22
23	let SessionIdentifier = format!(
24		"debug-{}",
25		SystemTime::now().duration_since(UNIX_EPOCH).map(|D| D.as_millis()).unwrap_or(0)
26	);
27
28	let _ = Service.environment.ApplicationHandle.emit(
29		"sky://debug/start",
30		json!({
31			"sessionId": SessionIdentifier,
32			"debugType": Request.debug_type,
33			"configuration": Request.configuration.as_ref().map(|C| json!({
34				"name": C.name,
35				"type": C.r#type,
36				"request": C.request,
37			})),
38		}),
39	);
40
41	Ok(Response::new(StartDebuggingResponse { success:true }))
42}