Skip to main content

Vine/Server/Notification/
DebugLifecycle.rs

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