Skip to content

Commit 27f798c

Browse files
refactor(Mountain): Thread safety improvements and code cleanup
This commit follows the TLS infrastructure addition with refinements and improvements across the Mountain backend: ### Thread Safety Improvements - **Scheme.rs**: Replaced unsafe static mut with RwLock-based thread-safe implementations for SERVICE_REGISTRY and CACHE, eliminating potential data races in the land:// protocol handler ### Code Cleanup - Added `#![allow(unused_imports, unused_variables)]` module attributes to suppress warnings in Environment, Command, IPC, FileSystem, Track, RPC, and Vine modules - Removed unused imports across multiple provider files (DebugProvider, FileSystemProvider, LanguageFeatureProvider, StatusBarProvider, TreeViewProvider, WebviewProvider) - Cleaned up unused parameters in Air client callback stubs - Removed unused imports from SecretProvider and TestProvider ### Formatting Standardization - Consistent struct field formatting: `pub field:Type` → `pub field:Type` with proper spacing - Standardized module documentation comments ### Vine gRPC Updates - Reformatted generated vine.rs protobuf code for consistency - Updated ServiceInfo and HealthStatus serializable field annotations ### Minor Fixes - Fixed variable naming (e.g., `mut checker` → `checker` where mutation was unnecessary) - Added placeholder Hover/Interface.rs for future hover feature implementation - Removed unused `Utility` imports where no longer needed This cleanup prepares the codebase for continued TLS integration work and improves overall code quality.
1 parent edbc84c commit 27f798c

101 files changed

Lines changed: 5701 additions & 7252 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Source/Air/AirClient.rs

Lines changed: 93 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,12 @@
7979
//! - [`DEFAULT_AIR_SERVER_ADDRESS`]: Default gRPC server address constant
8080
8181
use std::{collections::HashMap, sync::Arc};
82-
use tokio::sync::Mutex;
8382

83+
use tokio::sync::Mutex;
8484
use CommonLibrary::Error::CommonError::CommonError;
8585
#[cfg(feature = "AirIntegration")]
8686
use AirLibrary::Vine::Generated::air::air_service_client::AirServiceClient;
87-
use futures_util::StreamExt;
88-
use log::{debug, error, info, warn};
87+
use log::{debug, error, info};
8988
use tonic::{Request, transport::Channel};
9089

9190
/// Default gRPC server address for the Air daemon.
@@ -104,7 +103,8 @@ pub const DEFAULT_AIR_SERVER_ADDRESS:&str = "[::1]:50053";
104103
#[derive(Clone)]
105104
pub struct AirClient {
106105
#[cfg(feature = "AirIntegration")]
107-
/// The underlying tonic gRPC client wrapped in Arc<Mutex<>> for thread-safe access
106+
/// The underlying tonic gRPC client wrapped in Arc<Mutex<>> for thread-safe
107+
/// access
108108
client:Option<Arc<Mutex<AirServiceClient<Channel>>>>,
109109
/// Address of the Air daemon
110110
address:String,
@@ -213,9 +213,10 @@ impl AirClient {
213213
let username_display = username.clone();
214214
let request = AuthenticationRequest { request_id, username, password, provider };
215215

216-
let client = self.client.as_ref().ok_or_else(|| {
217-
CommonError::IPCError { Description:"Air client not initialized".to_string() }
218-
})?;
216+
let client = self
217+
.client
218+
.as_ref()
219+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
219220

220221
let mut client_guard = client.lock().await;
221222
match client_guard.authenticate(Request::new(request)).await {
@@ -225,7 +226,10 @@ impl AirClient {
225226
info!("[AirClient] Authentication successful for user '{}'", username_display);
226227
Ok(response.token)
227228
} else {
228-
error!("[AirClient] Authentication failed for user '{}': {}", username_display, response.error);
229+
error!(
230+
"[AirClient] Authentication failed for user '{}': {}",
231+
username_display, response.error
232+
);
229233
Err(CommonError::AccessDenied { Reason:response.error })
230234
}
231235
},
@@ -269,12 +273,15 @@ impl AirClient {
269273

270274
let request = UpdateCheckRequest { request_id, current_version, channel };
271275

272-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
276+
let client = self
277+
.client
278+
.as_ref()
279+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
273280
let mut client_guard = client.lock().await;
274281

275282
match client_guard.check_for_updates(Request::new(request)).await {
276283
Ok(response) => {
277-
let response: AirLibrary::Vine::Generated::air::UpdateCheckResponse = response.into_inner();
284+
let response:AirLibrary::Vine::Generated::air::UpdateCheckResponse = response.into_inner();
278285
info!(
279286
"[AirClient] Update check completed. Update available: {}",
280287
response.update_available
@@ -326,12 +333,15 @@ impl AirClient {
326333

327334
let request = DownloadRequest { request_id, url, destination_path, checksum, headers };
328335

329-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
336+
let client = self
337+
.client
338+
.as_ref()
339+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
330340
let mut client_guard = client.lock().await;
331341

332342
match client_guard.download_update(Request::new(request)).await {
333343
Ok(response) => {
334-
let response: AirLibrary::Vine::Generated::air::DownloadResponse = response.into_inner();
344+
let response:AirLibrary::Vine::Generated::air::DownloadResponse = response.into_inner();
335345
if response.success {
336346
info!("[AirClient] Update downloaded successfully to: {}", response.file_path);
337347
Ok(FileInfo {
@@ -375,12 +385,15 @@ impl AirClient {
375385

376386
let request = ApplyUpdateRequest { request_id, version, update_path };
377387

378-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
388+
let client = self
389+
.client
390+
.as_ref()
391+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
379392
let mut client_guard = client.lock().await;
380393

381394
match client_guard.apply_update(Request::new(request)).await {
382395
Ok(response) => {
383-
let response: AirLibrary::Vine::Generated::air::ApplyUpdateResponse = response.into_inner();
396+
let response:AirLibrary::Vine::Generated::air::ApplyUpdateResponse = response.into_inner();
384397
if response.success {
385398
info!("[AirClient] Update applied successfully");
386399
Ok(())
@@ -433,12 +446,15 @@ impl AirClient {
433446

434447
let request = DownloadRequest { request_id, url, destination_path, checksum, headers };
435448

436-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
449+
let client = self
450+
.client
451+
.as_ref()
452+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
437453
let mut client_guard = client.lock().await;
438454

439455
match client_guard.download_file(Request::new(request)).await {
440456
Ok(response) => {
441-
let response: AirLibrary::Vine::Generated::air::DownloadResponse = response.into_inner();
457+
let response:AirLibrary::Vine::Generated::air::DownloadResponse = response.into_inner();
442458
if response.success {
443459
info!("[AirClient] File downloaded successfully to: {}", response.file_path);
444460
Ok(FileInfo {
@@ -531,7 +547,10 @@ impl AirClient {
531547

532548
let request = DownloadStreamRequest { request_id, url, headers };
533549

534-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
550+
let client = self
551+
.client
552+
.as_ref()
553+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
535554
let mut client_guard = client.lock().await;
536555

537556
match client_guard.download_stream(Request::new(request)).await {
@@ -583,7 +602,10 @@ impl AirClient {
583602

584603
let request = IndexRequest { request_id, path, patterns, exclude_patterns, max_depth };
585604

586-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
605+
let client = self
606+
.client
607+
.as_ref()
608+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
587609
let mut client_guard = client.lock().await;
588610

589611
match client_guard.index_files(Request::new(request)).await {
@@ -634,7 +656,10 @@ impl AirClient {
634656

635657
let request = SearchRequest { request_id, query, path, max_results };
636658

637-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
659+
let client = self
660+
.client
661+
.as_ref()
662+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
638663
let mut client_guard = client.lock().await;
639664

640665
match client_guard.search_files(Request::new(request)).await {
@@ -674,13 +699,19 @@ impl AirClient {
674699

675700
let request = FileInfoRequest { request_id, path };
676701

677-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
702+
let client = self
703+
.client
704+
.as_ref()
705+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
678706
let mut client_guard = client.lock().await;
679707

680708
match client_guard.get_file_info(Request::new(request)).await {
681709
Ok(response) => {
682-
let response: AirLibrary::Vine::Generated::air::FileInfoResponse = response.into_inner();
683-
info!("[AirClient] File info retrieved for: {} (exists: {})", path_display, response.exists);
710+
let response:AirLibrary::Vine::Generated::air::FileInfoResponse = response.into_inner();
711+
info!(
712+
"[AirClient] File info retrieved for: {} (exists: {})",
713+
path_display, response.exists
714+
);
684715
Ok(ExtendedFileInfo {
685716
exists:response.exists,
686717
size:response.size,
@@ -720,12 +751,15 @@ impl AirClient {
720751

721752
let request = StatusRequest { request_id };
722753

723-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
754+
let client = self
755+
.client
756+
.as_ref()
757+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
724758
let mut client_guard = client.lock().await;
725759

726760
match client_guard.get_status(Request::new(request)).await {
727761
Ok(response) => {
728-
let response: AirLibrary::Vine::Generated::air::StatusResponse = response.into_inner();
762+
let response:AirLibrary::Vine::Generated::air::StatusResponse = response.into_inner();
729763
info!("[AirClient] Status retrieved. Active requests: {}", response.active_requests);
730764
Ok(AirStatus {
731765
version:response.version,
@@ -766,12 +800,15 @@ impl AirClient {
766800

767801
let request = HealthCheckRequest {};
768802

769-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
803+
let client = self
804+
.client
805+
.as_ref()
806+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
770807
let mut client_guard = client.lock().await;
771808

772809
match client_guard.health_check(Request::new(request)).await {
773810
Ok(response) => {
774-
let response: AirLibrary::Vine::Generated::air::HealthCheckResponse = response.into_inner();
811+
let response:AirLibrary::Vine::Generated::air::HealthCheckResponse = response.into_inner();
775812
debug!("[AirClient] Health check result: {}", response.healthy);
776813
Ok(response.healthy)
777814
},
@@ -808,12 +845,15 @@ impl AirClient {
808845

809846
let request = MetricsRequest { request_id, metric_type:metric_type.unwrap_or_default() };
810847

811-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
848+
let client = self
849+
.client
850+
.as_ref()
851+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
812852
let mut client_guard = client.lock().await;
813853

814854
match client_guard.get_metrics(Request::new(request)).await {
815855
Ok(response) => {
816-
let response: AirLibrary::Vine::Generated::air::MetricsResponse = response.into_inner();
856+
let response:AirLibrary::Vine::Generated::air::MetricsResponse = response.into_inner();
817857
info!("[AirClient] Metrics retrieved");
818858
// Parse metrics from the string map - this is a simplified implementation
819859
let metrics = AirMetrics {
@@ -879,12 +919,15 @@ impl AirClient {
879919

880920
let request = ResourceUsageRequest { request_id };
881921

882-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
922+
let client = self
923+
.client
924+
.as_ref()
925+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
883926
let mut client_guard = client.lock().await;
884927

885928
match client_guard.get_resource_usage(Request::new(request)).await {
886929
Ok(response) => {
887-
let response: AirLibrary::Vine::Generated::air::ResourceUsageResponse = response.into_inner();
930+
let response:AirLibrary::Vine::Generated::air::ResourceUsageResponse = response.into_inner();
888931
info!("[AirClient] Resource usage retrieved");
889932
Ok(ResourceUsage {
890933
memory_usage_mb:response.memory_usage_mb,
@@ -937,12 +980,15 @@ impl AirClient {
937980

938981
let request = ResourceLimitsRequest { request_id, memory_limit_mb, cpu_limit_percent, disk_limit_mb };
939982

940-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
983+
let client = self
984+
.client
985+
.as_ref()
986+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
941987
let mut client_guard = client.lock().await;
942988

943989
match client_guard.set_resource_limits(Request::new(request)).await {
944990
Ok(response) => {
945-
let response: AirLibrary::Vine::Generated::air::ResourceLimitsResponse = response.into_inner();
991+
let response:AirLibrary::Vine::Generated::air::ResourceLimitsResponse = response.into_inner();
946992
if response.success {
947993
info!("[AirClient] Resource limits set successfully");
948994
Ok(())
@@ -991,12 +1037,15 @@ impl AirClient {
9911037

9921038
let request = ConfigurationRequest { request_id, section };
9931039

994-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
1040+
let client = self
1041+
.client
1042+
.as_ref()
1043+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
9951044
let mut client_guard = client.lock().await;
9961045

9971046
match client_guard.get_configuration(Request::new(request)).await {
9981047
Ok(response) => {
999-
let response: AirLibrary::Vine::Generated::air::ConfigurationResponse = response.into_inner();
1048+
let response:AirLibrary::Vine::Generated::air::ConfigurationResponse = response.into_inner();
10001049
info!(
10011050
"[AirClient] Configuration retrieved for section: {} ({} keys)",
10021051
section_display,
@@ -1045,14 +1094,20 @@ impl AirClient {
10451094

10461095
let request = UpdateConfigurationRequest { request_id, section, updates };
10471096

1048-
let client = self.client.as_ref().ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
1097+
let client = self
1098+
.client
1099+
.as_ref()
1100+
.ok_or_else(|| CommonError::IPCError { Description:"Air client not initialized".to_string() })?;
10491101
let mut client_guard = client.lock().await;
10501102

10511103
match client_guard.update_configuration(Request::new(request)).await {
10521104
Ok(response) => {
1053-
let response: AirLibrary::Vine::Generated::air::UpdateConfigurationResponse = response.into_inner();
1105+
let response:AirLibrary::Vine::Generated::air::UpdateConfigurationResponse = response.into_inner();
10541106
if response.success {
1055-
info!("[AirClient] Configuration updated successfully for section: {}", section_display);
1107+
info!(
1108+
"[AirClient] Configuration updated successfully for section: {}",
1109+
section_display
1110+
);
10561111
Ok(())
10571112
} else {
10581113
error!("[AirClient] Failed to update configuration: {}", response.error);
@@ -1236,9 +1291,7 @@ impl DownloadStream {
12361291
// ============================================================================
12371292

12381293
impl std::fmt::Debug for AirClient {
1239-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1240-
write!(f, "AirClient({})", self.address)
1241-
}
1294+
fn fmt(&self, f:&mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "AirClient({})", self.address) }
12421295
}
12431296

12441297
// ============================================================================

Source/Air/AirServiceProvider.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666
use std::{collections::HashMap, sync::Arc};
6767

6868
use CommonLibrary::Error::CommonError::CommonError;
69-
use log::{debug, info, trace};
69+
use log::{info, trace};
7070
use uuid::Uuid;
7171

72+
#[allow(unused_imports)]
7273
use super::{
7374
AirClient::{
7475
AirClient,

Source/Air/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub use AirClient::{
9090
ResourceUsage,
9191
UpdateInfo,
9292
};
93-
9493
// Re-export the original name for compatibility (using type alias inside the module)
9594
pub use AirServiceProvider::generate_request_id;
9695

0 commit comments

Comments
 (0)