Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Vine/Server/Notification/
TerminalEnvCollection.rs

1//! Cocoon → Mountain `terminal.envCollection.<op>` notifications.
2//! Each `op` (`replace` / `append` / `prepend` / `delete` / `clear` /
3//! `setPersistent` / `setDescription`) mutates the in-memory env
4//! collection registry keyed by extension id. Mutations are picked up
5//! by every PTY spawn that runs after the notification arrives - no
6//! retro-active mutation of running terminals (matches VS Code
7//! semantics).
8
9use serde_json::Value;
10
11use crate::{
12	Environment::TerminalEnvCollection,
13	Vine::Server::MountainVinegRPCService::MountainVinegRPCService,
14	dev_log,
15};
16
17pub async fn TerminalEnvCollectionDispatch(_Service:&MountainVinegRPCService, MethodName:&str, Parameter:&Value) {
18	let Suffix = MethodName.strip_prefix("terminal.envCollection.").unwrap_or(MethodName);
19
20	let (ExtensionId, Variable, ValueStr) = TerminalEnvCollection::ParsePayload(Parameter);
21
22	if ExtensionId.is_empty() && Suffix != "clear" && Suffix != "setPersistent" && Suffix != "setDescription" {
23		// Extension id is mandatory for every per-variable op. Without
24		// it we'd land mutations in a global "" bucket that no
25		// extension can ever clear; refuse rather than corrupt state.
26		dev_log!(
27			"terminal",
28			"warn: [EnvCollection] {} called without extensionId - dropped",
29			Suffix
30		);
31
32		return;
33	}
34
35	match Suffix {
36		"replace" => TerminalEnvCollection::Replace(&ExtensionId, Variable, ValueStr),
37
38		"append" => TerminalEnvCollection::Append(&ExtensionId, Variable, ValueStr),
39
40		"prepend" => TerminalEnvCollection::Prepend(&ExtensionId, Variable, ValueStr),
41
42		"delete" => TerminalEnvCollection::Delete(&ExtensionId, &Variable),
43
44		"clear" => TerminalEnvCollection::Clear(&ExtensionId),
45
46		"setPersistent" => {
47			let Persistent = Parameter.get("persistent").and_then(|V| V.as_bool()).unwrap_or(false);
48
49			TerminalEnvCollection::SetPersistent(&ExtensionId, Persistent);
50		},
51
52		"setDescription" => {
53			let Description = Parameter.get("description").and_then(|V| V.as_str()).map(|S| S.to_string());
54
55			TerminalEnvCollection::SetDescription(&ExtensionId, Description);
56		},
57
58		Other => {
59			dev_log!("terminal", "warn: [EnvCollection] unknown op '{}'", Other);
60		},
61	}
62}