Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Vine/Server/Notification/
DebugLifecycle.rs

1//! Cocoon → Mountain `debug.addBreakpoints` / `debug.removeBreakpoints` /
2//! `debug.consoleAppend` notifications. Fans on `sky://debug/<suffix>`
3//! so the Sky-side debug view picks up breakpoint changes and console
4//! output from the extension's `vscode.debug.*` surface.
5
6use serde_json::{Value, json};
7use tauri::Emitter;
8
9use crate::{Vine::Server::MountainVinegRPCService::MountainVinegRPCService, dev_log};
10
11pub async fn DebugLifecycle(Service:&MountainVinegRPCService, MethodName:&str, Parameter:&Value) {
12	let EventName = format!("sky://debug/{}", &MethodName["debug.".len()..]);
13
14	if let Err(Error) = Service.ApplicationHandle().emit(&EventName, Parameter) {
15		dev_log!("grpc", "warn: [MountainVinegRPCService] {} emit failed: {}", EventName, Error);
16	}
17
18	// For breakpoint changes specifically, also fan back to Cocoon so
19	// `vscode.debug.onDidChangeBreakpoints` subscribers in OTHER
20	// extensions observe the change. Without this round-trip, only the
21	// extension that called `addBreakpoints`/`removeBreakpoints` knows
22	// about its own write - peer extensions miss it. `debug.consoleAppend`
23	// doesn't need this; console output isn't an observable surface.
24	if MethodName == "debug.addBreakpoints" || MethodName == "debug.removeBreakpoints" {
25		let Added:Vec<Value> = if MethodName == "debug.addBreakpoints" {
26			Parameter
27				.get("breakpoints")
28				.and_then(Value::as_array)
29				.cloned()
30				.unwrap_or_default()
31		} else {
32			Vec::new()
33		};
34
35		let Removed:Vec<Value> = if MethodName == "debug.removeBreakpoints" {
36			Parameter
37				.get("breakpoints")
38				.and_then(Value::as_array)
39				.cloned()
40				.unwrap_or_default()
41		} else {
42			Vec::new()
43		};
44
45		let _ = crate::Vine::Client::SendNotification::Fn(
46			"cocoon-main".to_string(),
47			"$onDidChangeBreakpoints".to_string(),
48			json!({
49				"added": Added,
50				"removed": Removed,
51				"changed": [],
52			}),
53		)
54		.await;
55	}
56}