Skip to content

Commit ff81326

Browse files
refactor(Mountain/RPC): Restructure services into modular, feature-gated submodules and align Common error types
This commit refactors the `Mountain` RPC layer to support granular feature flags and aligns error handling with the updated `Common` crate definition. **Architectural Restructuring:** The monolithic `RPC/mod.rs` is replaced by a modular system where services (Commands, Workspace, Configuration, Telemetry, etc.) reside in dedicated files. This enables precise feature gating (e.g., `terminals`, `scm-support`) so that services like `Debug` or `SCM` are only compiled when targeting the `Cocoon` extension host, while core services like `EchoAction` and `Commands` remain available to `Sky` (WASM) and `Grove`. **New Service Modules:** - `commands`: Defines `CommandService` and `CommandValidation`. - `workspace`: Implements `WorkspaceService` with `WorkspaceFolder` and `TextDocumentInfo` DTOs. - `configuration`: Provides `ConfigurationService` for scoped config management. - `telemetry`: Introduces `TelemetryService`, `TraceSpan`, and `ServiceMetrics` to centralize OTEL data structures. - `echo_action`: Contains `EchoActionServer`, `ExtensionHostRegistry`, and `ExtensionRouter` for host communication. - `types` & `vine`: Consolidate shared types and Vine protocol connection structures. **Error Alignment:** Updated all error instantiations in `AirClient.rs` to match the `CommonError` enum variants. Specifically: - Replaced `CommonError::IPCError { Message: ... }` with `CommonError::IPCError { Description: ... }`. - Replaced `CommonError::AccessDenied { Message: ... }` with `CommonError::AccessDenied { Reason: ... }`. **Impact:** This refactoring reduces binary size for frontend-only builds (Sky/Grove) by excluding heavy backend services (Terminals, SCM), improves compilation times, and resolves compilation errors caused by recent structural changes in the `Common` crate's error definitions.
1 parent 05cc637 commit ff81326

9 files changed

Lines changed: 421 additions & 132 deletions

File tree

Source/Air/AirClient.rs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ impl AirClient {
135135
let endpoint = address.parse::<tonic::transport::Endpoint>().map_err(|e| {
136136
error!("[AirClient] Failed to parse address '{}': {}", address, e);
137137
CommonError::IPCError {
138-
Message: format!("Invalid address '{}': {}", address, e),
138+
Description: format!("Invalid address '{}': {}", address, e),
139139
}
140140
})?;
141141

142142
let channel = endpoint.connect().await.map_err(|e| {
143143
error!("[AirClient] Failed to connect to Air daemon: {}", e);
144144
CommonError::IPCError {
145-
Message: format!("Connection failed: {}", e),
145+
Description: format!("Connection failed: {}", e),
146146
}
147147
})?;
148148

@@ -236,14 +236,14 @@ impl AirClient {
236236
username, response.error
237237
);
238238
Err(CommonError::AccessDenied {
239-
Message: response.error,
239+
Reason: response.error,
240240
})
241241
}
242242
}
243243
Err(e) => {
244244
error!("[AirClient] Authentication RPC error: {}", e);
245-
Err(CommonError::IPCError {
246-
Message: format!("Authentication RPC error: {}", e),
245+
Err(CommonError::IPCError { Description:
246+
format!("Authentication RPC error: {}", e),
247247
})
248248
}
249249
}
@@ -309,8 +309,8 @@ impl AirClient {
309309
}
310310
Err(e) => {
311311
error!("[AirClient] Check for updates RPC error: {}", e);
312-
Err(CommonError::IPCError {
313-
Message: format!("Check for updates RPC error: {}", e),
312+
Err(CommonError::IPCError { Description:
313+
format!("Check for updates RPC error: {}", e),
314314
})
315315
}
316316
}
@@ -374,15 +374,15 @@ impl AirClient {
374374
})
375375
} else {
376376
error!("[AirClient] Update download failed: {}", response.error);
377-
Err(CommonError::IPCError {
378-
Message: response.error,
377+
Err(CommonError::IPCError { Description:
378+
response.error,
379379
})
380380
}
381381
}
382382
Err(e) => {
383383
error!("[AirClient] Download update RPC error: {}", e);
384-
Err(CommonError::IPCError {
385-
Message: format!("Download update RPC error: {}", e),
384+
Err(CommonError::IPCError { Description:
385+
format!("Download update RPC error: {}", e),
386386
})
387387
}
388388
}
@@ -433,15 +433,15 @@ impl AirClient {
433433
Ok(())
434434
} else {
435435
error!("[AirClient] Update application failed: {}", response.error);
436-
Err(CommonError::IPCError {
437-
Message: response.error,
436+
Err(CommonError::IPCError { Description:
437+
response.error,
438438
})
439439
}
440440
}
441441
Err(e) => {
442442
error!("[AirClient] Apply update RPC error: {}", e);
443-
Err(CommonError::IPCError {
444-
Message: format!("Apply update RPC error: {}", e),
443+
Err(CommonError::IPCError { Description:
444+
format!("Apply update RPC error: {}", e),
445445
})
446446
}
447447
}
@@ -509,15 +509,15 @@ impl AirClient {
509509
})
510510
} else {
511511
error!("[AirClient] File download failed: {}", response.error);
512-
Err(CommonError::IPCError {
513-
Message: response.error,
512+
Err(CommonError::IPCError { Description:
513+
response.error,
514514
})
515515
}
516516
}
517517
Err(e) => {
518518
error!("[AirClient] Download file RPC error: {}", e);
519-
Err(CommonError::IPCError {
520-
Message: format!("Download file RPC error: {}", e),
519+
Err(CommonError::IPCError { Description:
520+
format!("Download file RPC error: {}", e),
521521
})
522522
}
523523
}
@@ -609,8 +609,8 @@ impl AirClient {
609609
}
610610
Err(e) => {
611611
error!("[AirClient] Download stream RPC error: {}", e);
612-
Err(CommonError::IPCError {
613-
Message: format!("Download stream RPC error: {}", e),
612+
Err(CommonError::IPCError { Description:
613+
format!("Download stream RPC error: {}", e),
614614
})
615615
}
616616
}
@@ -677,15 +677,15 @@ impl AirClient {
677677
})
678678
} else {
679679
error!("[AirClient] File indexing failed: {}", response.error);
680-
Err(CommonError::IPCError {
681-
Message: response.error,
680+
Err(CommonError::IPCError { Description:
681+
response.error,
682682
})
683683
}
684684
}
685685
Err(e) => {
686686
error!("[AirClient] Index files RPC error: {}", e);
687-
Err(CommonError::IPCError {
688-
Message: format!("Index files RPC error: {}", e),
687+
Err(CommonError::IPCError { Description:
688+
format!("Index files RPC error: {}", e),
689689
})
690690
}
691691
}
@@ -752,8 +752,8 @@ impl AirClient {
752752
}
753753
Err(e) => {
754754
error!("[AirClient] Search files RPC error: {}", e);
755-
Err(CommonError::IPCError {
756-
Message: format!("Search files RPC error: {}", e),
755+
Err(CommonError::IPCError { Description:
756+
format!("Search files RPC error: {}", e),
757757
})
758758
}
759759
}
@@ -810,8 +810,8 @@ impl AirClient {
810810
}
811811
Err(e) => {
812812
error!("[AirClient] Get file info RPC error: {}", e);
813-
Err(CommonError::IPCError {
814-
Message: format!("Get file info RPC error: {}", e),
813+
Err(CommonError::IPCError { Description:
814+
format!("Get file info RPC error: {}", e),
815815
})
816816
}
817817
}
@@ -863,8 +863,8 @@ impl AirClient {
863863
}
864864
Err(e) => {
865865
error!("[AirClient] Get status RPC error: {}", e);
866-
Err(CommonError::IPCError {
867-
Message: format!("Get status RPC error: {}", e),
866+
Err(CommonError::IPCError { Description:
867+
format!("Get status RPC error: {}", e),
868868
})
869869
}
870870
}
@@ -902,8 +902,8 @@ impl AirClient {
902902
}
903903
Err(e) => {
904904
error!("[AirClient] Health check RPC error: {}", e);
905-
Err(CommonError::IPCError {
906-
Message: format!("Health check RPC error: {}", e),
905+
Err(CommonError::IPCError { Description:
906+
format!("Health check RPC error: {}", e),
907907
})
908908
}
909909
}
@@ -972,8 +972,8 @@ impl AirClient {
972972
}
973973
Err(e) => {
974974
error!("[AirClient] Get metrics RPC error: {}", e);
975-
Err(CommonError::IPCError {
976-
Message: format!("Get metrics RPC error: {}", e),
975+
Err(CommonError::IPCError { Description:
976+
format!("Get metrics RPC error: {}", e),
977977
})
978978
}
979979
}
@@ -1028,8 +1028,8 @@ impl AirClient {
10281028
}
10291029
Err(e) => {
10301030
error!("[AirClient] Get resource usage RPC error: {}", e);
1031-
Err(CommonError::IPCError {
1032-
Message: format!("Get resource usage RPC error: {}", e),
1031+
Err(CommonError::IPCError { Description:
1032+
format!("Get resource usage RPC error: {}", e),
10331033
})
10341034
}
10351035
}
@@ -1087,15 +1087,15 @@ impl AirClient {
10871087
Ok(())
10881088
} else {
10891089
error!("[AirClient] Failed to set resource limits: {}", response.error);
1090-
Err(CommonError::IPCError {
1091-
Message: response.error,
1090+
Err(CommonError::IPCError { Description:
1091+
response.error,
10921092
})
10931093
}
10941094
}
10951095
Err(e) => {
10961096
error!("[AirClient] Set resource limits RPC error: {}", e);
1097-
Err(CommonError::IPCError {
1098-
Message: format!("Set resource limits RPC error: {}", e),
1097+
Err(CommonError::IPCError { Description:
1098+
format!("Set resource limits RPC error: {}", e),
10991099
})
11001100
}
11011101
}
@@ -1151,8 +1151,8 @@ impl AirClient {
11511151
}
11521152
Err(e) => {
11531153
error!("[AirClient] Get configuration RPC error: {}", e);
1154-
Err(CommonError::IPCError {
1155-
Message: format!("Get configuration RPC error: {}", e),
1154+
Err(CommonError::IPCError { Description:
1155+
format!("Get configuration RPC error: {}", e),
11561156
})
11571157
}
11581158
}
@@ -1213,15 +1213,15 @@ impl AirClient {
12131213
"[AirClient] Failed to update configuration: {}",
12141214
response.error
12151215
);
1216-
Err(CommonError::IPCError {
1217-
Message: response.error,
1216+
Err(CommonError::IPCError { Description:
1217+
response.error,
12181218
})
12191219
}
12201220
}
12211221
Err(e) => {
12221222
error!("[AirClient] Update configuration RPC error: {}", e);
1223-
Err(CommonError::IPCError {
1224-
Message: format!("Update configuration RPC error: {}", e),
1223+
Err(CommonError::IPCError { Description:
1224+
format!("Update configuration RPC error: {}", e),
12251225
})
12261226
}
12271227
}
@@ -1393,8 +1393,8 @@ impl DownloadStream {
13931393
}
13941394
Some(Err(e)) => {
13951395
error!("[DownloadStream] Stream error: {}", e);
1396-
Some(Err(CommonError::IPCError {
1397-
Message: format!("Stream error: {}", e),
1396+
Some(Err(CommonError::IPCError { Description:
1397+
format!("Stream error: {}", e),
13981398
}))
13991399
}
14001400
None => None,

Source/RPC/commands.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//! # Commands RPC Service
2+
//!
3+
//! Command registration and execution service.
4+
5+
use serde::{Deserialize, Serialize};
6+
use std::collections::HashMap;
7+
8+
/// Command service
9+
pub struct CommandService {
10+
commands: HashMap<String, String>,
11+
}
12+
13+
impl CommandService {
14+
pub fn new() -> Self {
15+
Self {
16+
commands: HashMap::new(),
17+
}
18+
}
19+
}
20+
21+
impl Default for CommandService {
22+
fn default() -> Self {
23+
Self::new()
24+
}
25+
}
26+
27+
/// Command validation
28+
pub struct CommandValidation;
29+
30+
impl CommandValidation {
31+
pub fn new() -> Self {
32+
Self {}
33+
}
34+
}
35+
36+
impl Default for CommandValidation {
37+
fn default() -> Self {
38+
Self::new()
39+
}
40+
}
41+
42+
/// Command definition
43+
#[derive(Debug, Clone, Serialize, Deserialize)]
44+
pub struct Command {
45+
pub id: String,
46+
pub title: String,
47+
pub description: Option<String>,
48+
}

Source/RPC/configuration.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! # Configuration RPC Service
2+
//!
3+
//! Configuration management service for read/write operations.
4+
5+
use serde::{Deserialize, Serialize};
6+
use std::collections::HashMap;
7+
8+
/// Configuration service
9+
pub struct ConfigurationService {
10+
config: HashMap<String, serde_json::Value>,
11+
}
12+
13+
impl ConfigurationService {
14+
pub fn new() -> Self {
15+
Self {
16+
config: HashMap::new(),
17+
}
18+
}
19+
20+
pub fn get(&self, key: &str) -> Option<&serde_json::Value> {
21+
self.config.get(key)
22+
}
23+
24+
pub fn set(&mut self, key: String, value: serde_json::Value) {
25+
self.config.insert(key, value);
26+
}
27+
}
28+
29+
impl Default for ConfigurationService {
30+
fn default() -> Self {
31+
Self::new()
32+
}
33+
}
34+
35+
/// Configuration scope
36+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
37+
pub enum ConfigurationScope {
38+
Global,
39+
Workspace,
40+
Folder,
41+
}
42+
43+
/// Configuration update
44+
#[derive(Debug, Clone, Serialize, Deserialize)]
45+
pub struct ConfigurationUpdate {
46+
pub key: String,
47+
pub value: serde_json::Value,
48+
pub scope: ConfigurationScope,
49+
}

0 commit comments

Comments
 (0)