Mountain/Environment/IPCProvider.rs
1//! # IPCProvider (Environment)
2//!
3//! Implements [`IPCProvider`](CommonLibrary::IPC::IPCProvider) for
4//! `MountainEnvironment`. Serves as the IPC bridge between Mountain and
5//! extension sidecar processes (Cocoon), delegating all transport to the
6//! Vine gRPC client with JSON-RPC 2.0 over the wire.
7//!
8//! ## Communication patterns
9//!
10//! - **Request/response** (`SendRequestToSideCar`) - synchronous RPC with
11//! caller-specified timeout; used for config resolution, URI lookup, and
12//! content retrieval.
13//! - **Notification** (`SendNotificationToSideCar`) - fire-and-forget; used for
14//! document changes, diagnostics, and UI events. Returns `Result<(),
15//! CommonError>` indicating send success only.
16//!
17//! ## VS Code reference
18//!
19//! - `vs/workbench/services/extensions/common/extensionHostProtocol.ts`
20//! - `vs/base/parts/ipc/common/ipc.net.ts`
21//! - `vs/workbench/services/extensions/common/rpcProtocol.ts`
22//!
23//! ## Planned Work
24//!
25//! - Message queuing for offline scenarios
26//! - Bidirectional request handling (sidecar → main)
27//! - Streaming support
28//! - Request cancellation
29//! - Priority queue and batch operations
30//! - Request deduplication
31//! - Connection health checking
32//! - Unix domain socket support
33//! - Latency/success-rate telemetry
34
35use CommonLibrary::{Error::CommonError::CommonError, IPC::IPCProvider::IPCProvider};
36use async_trait::async_trait;
37use serde_json::Value;
38
39use super::MountainEnvironment::MountainEnvironment;
40use crate::Vine::Client;
41
42// TODO: message queuing for offline scenarios, bidirectional request handling
43// (sidecar → main), streaming support, request cancellation, priority queue,
44// batch operations, request deduplication, connection health checking,
45// Unix domain socket support, latency/success-rate telemetry.
46#[async_trait]
47impl IPCProvider for MountainEnvironment {
48 /// Sends a fire-and-forget notification to a specified sidecar.
49 async fn SendNotificationToSideCar(
50 &self,
51
52 SideCarIdentifier:String,
53
54 Method:String,
55
56 Parameters:Value,
57 ) -> Result<(), CommonError> {
58 Client::SendNotification::Fn(SideCarIdentifier, Method, Parameters)
59 .await
60 .map_err(|Error| CommonError::IPCError { Description:Error.to_string() })
61 }
62
63 /// Sends a request to a specified sidecar and awaits a response.
64 async fn SendRequestToSideCar(
65 &self,
66
67 SideCarIdentifier:String,
68
69 Method:String,
70
71 Parameters:Value,
72
73 TimeoutMilliseconds:u64,
74 ) -> Result<Value, CommonError> {
75 Client::SendRequest::Fn(&SideCarIdentifier, Method, Parameters, TimeoutMilliseconds)
76 .await
77 .map_err(|Error| CommonError::IPCError { Description:Error.to_string() })
78 }
79}