Skip to main content

Vine/Server/Notification/
UnregisterScmProvider.rs

1//! Cocoon → `unregister_scm_provider` notification.
2//! Emitted when `vscode.scm.createSourceControl(...).dispose()` fires.
3//! Resolves the provider handle: uses the explicit `handle` field when
4//! Cocoon sends it, otherwise recomputes the DJB-31 hash of `scmId`
5//! that `RegisterScmProvider` used when it originally registered the provider
6//! (necessary because Cocoon's dispose path only carries the string id).
7
8use serde_json::{Value, json};
9
10use crate::{Host::VineHost, dev_log};
11
12pub async fn UnregisterScmProvider(Host:&dyn VineHost, Parameter:&Value) {
13	let ScmId = Parameter
14		.get("scmId")
15		.or_else(|| Parameter.get("scm_id"))
16		.and_then(Value::as_str)
17		.unwrap_or("")
18		.to_string();
19
20	let DirectHandle = Parameter.get("handle").and_then(Value::as_u64).map(|H| H as u32);
21
22	if ScmId.is_empty() && DirectHandle.is_none() {
23		dev_log!("provider-register", "[ProviderUnregister] scm skip: missing handle / scmId");
24
25		return;
26	}
27
28	let Handle = DirectHandle.unwrap_or_else(|| {
29		ScmId
30			.as_bytes()
31			.iter()
32			.fold(0u32, |Acc, B| Acc.wrapping_mul(31).wrapping_add(*B as u32))
33	});
34
35	Host.UnregisterProvider(Handle);
36
37	Host.EmitToRenderer("sky://scm/unregister", json!({ "scmId": ScmId }));
38
39	dev_log!(
40		"provider-register",
41		"[ProviderUnregister] scm scm_id={} handle={}",
42		ScmId,
43		Handle
44	);
45}