Skip to content

Commit ae7c728

Browse files
refactor(Mountain/Environment): Improve command handling and workspace search logic
- Added manual `Clone` implementation for `CommandHandler` to support function pointers, ensuring command handlers can be properly cloned during registration in `Mountain`'s command system - Fixed state retrieval in `CommandProvider` by adding explicit type annotation when accessing `ApplicationRunTime` from Tauri state - Enhanced error handling for proxied commands by mapping gRPC errors to `CommonError::IPCError` - Simplified type usage in `TreeViewProvider` by leveraging `TreeViewOptionsDTO` alias - Corrected file search logic in `WorkSpaceProvider` by fixing include/exclude pattern matching and path handling - Updated `Cargo.toml` to explicitly include build assets for packaging These changes strengthen the command execution pipeline between `Mountain` and `Cocoon`, fix file search pattern handling for workspace operations, and ensure proper build artifact inclusion. The improvements directly support implemented workflows like Command Palette execution and file search functionality.
1 parent 9fa448f commit ae7c728

4 files changed

Lines changed: 47 additions & 12 deletions

File tree

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,17 @@ edition = "2024"
8282
license-file = "LICENSE"
8383
name = "Mountain"
8484
publish = false
85+
include = [
86+
"build.rs",
87+
"capabilities/**/*",
88+
"Cargo.toml",
89+
"CHANGELOG.md",
90+
"icons/**/*",
91+
"LICENSE",
92+
"Mountain.key.pub",
93+
"Proto/**/*",
94+
"README.md",
95+
"Source/**/*",
96+
"tauri.conf.json",
97+
]
8598
version = "0.0.1"

Source/Environment/CommandProvider.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use super::MountainEnvironment::MountainEnvironment;
2121
use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, Vine::Client};
2222

2323
/// An enum representing the different ways a command can be handled.
24-
#[derive(Clone)]
2524
pub enum CommandHandler<R:Runtime + 'static> {
2625
/// A command handled by a native, asynchronous Rust function.
2726
Native(
@@ -36,6 +35,21 @@ pub enum CommandHandler<R:Runtime + 'static> {
3635
Proxied { SidecarIdentifier:String, CommandIdentifier:String },
3736
}
3837

38+
// Manually implement Clone because fn pointers are not automatically Clone
39+
impl<R:Runtime> Clone for CommandHandler<R> {
40+
fn clone(&self) -> Self {
41+
match self {
42+
Self::Native(f) => Self::Native(*f),
43+
Self::Proxied { SidecarIdentifier, CommandIdentifier } => {
44+
Self::Proxied {
45+
SidecarIdentifier:SidecarIdentifier.clone(),
46+
CommandIdentifier:CommandIdentifier.clone(),
47+
}
48+
},
49+
}
50+
}
51+
}
52+
3953
#[async_trait]
4054
impl CommandExecutor for MountainEnvironment {
4155
/// Executes a registered command by dispatching it to the appropriate
@@ -52,7 +66,8 @@ impl CommandExecutor for MountainEnvironment {
5266
match HandlerInfoOption {
5367
Some(CommandHandler::Native(Function)) => {
5468
debug!("[CommandProvider] Executing NATIVE command '{}'.", CommandIdentifier);
55-
let RunTime:Arc<ApplicationRunTime> = self.ApplicationHandle.state().inner().clone();
69+
let RunTime:Arc<ApplicationRunTime> =
70+
self.ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
5671
let MainWindow = self.ApplicationHandle.get_webview_window("main").ok_or_else(|| {
5772
CommonError::UserInterfaceInteraction {
5873
Reason:"Main window not found for command execution".into(),
@@ -72,7 +87,9 @@ impl CommandExecutor for MountainEnvironment {
7287
);
7388
let RPCParameters = json!([ProxiedCommandIdentifier, Argument]);
7489
let RPCMethod = format!("{}$ExecuteContributedCommand", ProxyTarget::ExtHostCommands.GetTargetPrefix());
75-
Client::SendRequest(&SidecarIdentifier, RPCMethod, RPCParameters, 30000).await
90+
Client::SendRequest(&SidecarIdentifier, RPCMethod, RPCParameters, 30000)
91+
.await
92+
.map_err(|e| CommonError::IPCError { Description:e.to_string() })
7693
},
7794
None => {
7895
error!("[CommandProvider] Command '{}' not found in registry.", CommandIdentifier);

Source/Environment/TreeViewProvider.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
//! provider manages the lifecycle of custom tree views and orchestrates the
55
//! data flow between the extension host (`Cocoon`) and the UI (`Sky`).
66
7-
use Common::{Error::CommonError::CommonError, TreeView::TreeViewProvider::TreeViewProvider};
7+
use Common::{
8+
Error::CommonError::CommonError,
9+
TreeView::{DTO::TreeViewOptionsDTO::TreeViewOptionsDTO, TreeViewProvider::TreeViewProvider},
10+
};
811
use async_trait::async_trait;
912
use log::{info, warn};
1013
use serde_json::{Value, json};
@@ -18,7 +21,7 @@ impl TreeViewProvider for MountainEnvironment {
1821
/// Registers a new tree data provider from Cocoon.
1922
async fn RegisterTreeDataProvider(&self, ViewIdentifier:String, Options:Value) -> Result<(), CommonError> {
2023
info!("[TreeViewProvider] Registering data provider for view: {}", ViewIdentifier);
21-
let OptionsDTO:Common::TreeView::DTO::TreeViewOptionsDTO::TreeViewOptionsDTO = serde_json::from_value(Options)
24+
let OptionsDTO:TreeViewOptionsDTO = serde_json::from_value(Options)
2225
.map_err(|e| CommonError::InvalidArgument { ArgumentName:"Options".into(), Reason:e.to_string() })?;
2326

2427
let NewState = TreeViewStateDTO {

Source/Environment/WorkSpaceProvider.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,16 @@ impl WorkSpaceProvider for MountainEnvironment {
132132
if Path.is_dir() {
133133
continue;
134134
}
135-
if IncludeMatcher?.is_match(Path) {
136-
if let Some(ref Exclude) = ExcludeMatcher {
137-
if Exclude.is_match(Path) {
138-
continue;
135+
if let Some(ref include) = IncludeMatcher {
136+
if include.is_match(Path) {
137+
if let Some(ref exclude) = ExcludeMatcher {
138+
if exclude.is_match(Path) {
139+
continue;
140+
}
141+
}
142+
if let Ok(URL) = Url::from_file_path(Path) {
143+
Results.push(URL);
139144
}
140-
}
141-
if let Ok(URL) = Url::from_file_path(Path) {
142-
Results.push(URL);
143145
}
144146
}
145147
}

0 commit comments

Comments
 (0)