Skip to content

Commit 8b7e172

Browse files
refactor(Mountain): update workspace folder access from async to sync API
Update WindServiceHandlers and CocoonService to use the new synchronous workspace folder API: - Replace `GetFolders().await` with `GetWorkspaceFolders()` in handlers for getFolders, findInFiles, and findFiles - Refactor addFolder and removeFolder to use direct folder manipulation via GetWorkspaceFolders/SetWorkspaceFolders instead of async AddFolder/RemoveFolder methods - Update getName handler to extract display name from first workspace folder synchronously - Fix field access: change `Folder.Uri` to `Folder.URI.to_string()` for consistency with the new DTO structure - Add missing `IgnoreFocusOut` field to the showInputBox handler These changes align with the updated Common library API where workspace folder operations are now synchronous, removing the need for async/await in workspace folder handlers.
1 parent 241b132 commit 8b7e172

2 files changed

Lines changed: 39 additions & 37 deletions

File tree

Source/IPC/WindServiceHandlers.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ use CommonLibrary::{
192192
Storage::StorageProvider::StorageProvider,
193193
};
194194

195-
use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
195+
use crate::{
196+
ApplicationState::DTO::WorkspaceFolderStateDTO::WorkspaceFolderStateDTO,
197+
RunTime::ApplicationRunTime::ApplicationRunTime,
198+
};
196199

197200
/// Handler for Wind's MainProcessService.invoke() calls
198201
/// Maps Tauri IPC commands to Mountain's internal command system
@@ -1373,6 +1376,7 @@ async fn handle_quick_input_show_input_box(runtime:Arc<ApplicationRunTime>, args
13731376
IsPassword:Some(Opts.and_then(|V| V.get("password")).and_then(|B| B.as_bool()).unwrap_or(false)),
13741377
Value:Opts.and_then(|V| V.get("value")).and_then(|V| V.as_str()).map(|S| S.to_string()),
13751378
Title:Opts.and_then(|V| V.get("title")).and_then(|T| T.as_str()).map(|S| S.to_string()),
1379+
IgnoreFocusOut:None,
13761380
};
13771381

13781382
let Result = runtime
@@ -1390,18 +1394,14 @@ async fn handle_quick_input_show_input_box(runtime:Arc<ApplicationRunTime>, args
13901394

13911395
/// Return the current workspace folders.
13921396
async fn handle_workspaces_get_folders(runtime:Arc<ApplicationRunTime>) -> Result<Value, String> {
1393-
let Folders = runtime
1394-
.Environment
1395-
.ApplicationState.Workspace
1396-
.GetFolders()
1397-
.await
1398-
.map_err(|Error| format!("workspaces:getFolders failed: {}", Error))?;
1397+
let Workspace = &runtime.Environment.ApplicationState.Workspace;
1398+
let Folders = Workspace.GetWorkspaceFolders();
13991399

14001400
let FolderList:Vec<Value> = Folders
14011401
.iter()
14021402
.enumerate()
14031403
.map(|(Index, Folder)| json!({
1404-
"uri": Folder.Uri,
1404+
"uri": Folder.URI.to_string(),
14051405
"name": Folder.Name,
14061406
"index": Index,
14071407
}))
@@ -1412,38 +1412,43 @@ async fn handle_workspaces_get_folders(runtime:Arc<ApplicationRunTime>) -> Resul
14121412

14131413
/// Add a workspace folder.
14141414
async fn handle_workspaces_add_folder(runtime:Arc<ApplicationRunTime>, args:Vec<Value>) -> Result<Value, String> {
1415-
let Uri = args
1415+
use url::Url;
1416+
1417+
let UriStr = args
14161418
.first()
14171419
.and_then(|V| V.as_str())
14181420
.ok_or("workspaces:addFolder requires uri as first argument".to_string())?
14191421
.to_string();
14201422

14211423
let Name = args.get(1).and_then(|V| V.as_str()).unwrap_or("").to_string();
14221424

1423-
runtime
1424-
.Environment
1425-
.ApplicationState.Workspace
1426-
.AddFolder(Uri, Name)
1427-
.await
1428-
.map_err(|Error| format!("workspaces:addFolder failed: {}", Error))?;
1425+
let Workspace = &runtime.Environment.ApplicationState.Workspace;
1426+
let mut Folders = Workspace.GetWorkspaceFolders();
1427+
let Index = Folders.len();
1428+
let URI = Url::parse(&UriStr).map_err(|E| format!("workspaces:addFolder invalid URI: {}", E))?;
1429+
if let Ok(Folder) = WorkspaceFolderStateDTO::New(URI, Name, Index) {
1430+
Folders.push(Folder);
1431+
Workspace.SetWorkspaceFolders(Folders);
1432+
}
14291433

14301434
Ok(Value::Null)
14311435
}
14321436

14331437
/// Remove a workspace folder by URI.
14341438
async fn handle_workspaces_remove_folder(runtime:Arc<ApplicationRunTime>, args:Vec<Value>) -> Result<Value, String> {
1435-
let Uri = args
1439+
let UriStr = args
14361440
.first()
14371441
.and_then(|V| V.as_str())
14381442
.ok_or("workspaces:removeFolder requires uri as first argument".to_string())?
14391443
.to_string();
14401444

1441-
runtime
1442-
.Environment
1443-
.ApplicationState.Workspace
1444-
.RemoveFolder(Uri)
1445-
.await
1446-
.map_err(|Error| format!("workspaces:removeFolder failed: {}", Error))?;
1445+
let Workspace = &runtime.Environment.ApplicationState.Workspace;
1446+
let mut Folders = Workspace.GetWorkspaceFolders();
1447+
Folders.retain(|F| F.URI.to_string() != UriStr);
1448+
for (I, F) in Folders.iter_mut().enumerate() {
1449+
F.Index = I;
1450+
}
1451+
Workspace.SetWorkspaceFolders(Folders);
14471452

14481453
Ok(Value::Null)
14491454
}
@@ -1453,9 +1458,10 @@ async fn handle_workspaces_get_name(runtime:Arc<ApplicationRunTime>) -> Result<V
14531458
let Name = runtime
14541459
.Environment
14551460
.ApplicationState.Workspace
1456-
.GetName()
1457-
.await
1458-
.map_err(|Error| format!("workspaces:getName failed: {}", Error))?;
1461+
.GetWorkspaceFolders()
1462+
.into_iter()
1463+
.next()
1464+
.map(|F| F.GetDisplayName());
14591465

14601466
Ok(Name.map(|N| json!(N)).unwrap_or(Value::Null))
14611467
}
@@ -1551,15 +1557,13 @@ async fn handle_search_find_in_files(runtime:Arc<ApplicationRunTime>, args:Vec<V
15511557
let WorkspaceFolders = runtime
15521558
.Environment
15531559
.ApplicationState.Workspace
1554-
.GetFolders()
1555-
.await
1556-
.unwrap_or_default();
1560+
.GetWorkspaceFolders();
15571561

15581562
if WorkspaceFolders.is_empty() {
15591563
return Ok(json!([]));
15601564
}
15611565

1562-
let RootPath = PathBuf::from(&WorkspaceFolders[0].Uri.replace("file://", ""));
1566+
let RootPath = PathBuf::from(&WorkspaceFolders[0].URI.to_string().replace("file://", ""));
15631567

15641568
// Build include matcher
15651569
let IncludeMatcher = GlobBuilder::new(&IncludeGlob)
@@ -1659,15 +1663,13 @@ async fn handle_search_find_files(runtime:Arc<ApplicationRunTime>, args:Vec<Valu
16591663
let WorkspaceFolders = runtime
16601664
.Environment
16611665
.ApplicationState.Workspace
1662-
.GetFolders()
1663-
.await
1664-
.unwrap_or_default();
1666+
.GetWorkspaceFolders();
16651667

16661668
if WorkspaceFolders.is_empty() {
16671669
return Ok(json!([]));
16681670
}
16691671

1670-
let RootPath = PathBuf::from(&WorkspaceFolders[0].Uri.replace("file://", ""));
1672+
let RootPath = PathBuf::from(&WorkspaceFolders[0].URI.to_string().replace("file://", ""));
16711673

16721674
let Matcher = GlobBuilder::new(&Pattern)
16731675
.literal_separator(false)

Source/RPC/CocoonService.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,11 +579,11 @@ impl CocoonService for CocoonServiceImpl {
579579
use globset::GlobBuilder;
580580
use std::path::PathBuf;
581581
let Pattern = Params.get("pattern").and_then(|V| V.as_str()).unwrap_or("**").to_string();
582-
let WorkspaceFolders = self.environment.ApplicationState.Workspace.GetFolders().await.unwrap_or_default();
582+
let WorkspaceFolders = self.environment.ApplicationState.Workspace.GetWorkspaceFolders();
583583
if WorkspaceFolders.is_empty() {
584584
return Ok(OkResponse(RequestId, &json!({ "uris": Vec::<String>::new() })));
585585
}
586-
let RootPath = PathBuf::from(&WorkspaceFolders[0].Uri.replace("file://", ""));
586+
let RootPath = PathBuf::from(&WorkspaceFolders[0].URI.to_string().replace("file://", ""));
587587
let Matcher = match GlobBuilder::new(&Pattern).literal_separator(false).build() {
588588
Ok(G) => G.compile_matcher(),
589589
Err(E) => return Ok(ErrResponse(RequestId, -32000, format!("Invalid glob: {}", E))),
@@ -610,9 +610,9 @@ impl CocoonService for CocoonServiceImpl {
610610
use std::path::PathBuf;
611611
let Pattern = Params.get("pattern").and_then(|V| V.as_str()).unwrap_or("").to_string();
612612
let IncludeStr = Params.get("include").and_then(|V| V.as_array()).and_then(|A| A.first()).and_then(|V| V.as_str()).map(|S| S.to_string()).unwrap_or_else(|| "**".to_string());
613-
let WorkspaceFolders = self.environment.ApplicationState.Workspace.GetFolders().await.unwrap_or_default();
613+
let WorkspaceFolders = self.environment.ApplicationState.Workspace.GetWorkspaceFolders();
614614
if WorkspaceFolders.is_empty() { return Ok(OkResponse(RequestId, &json!({ "matches": Vec::<serde_json::Value>::new() }))); }
615-
let RootPath = PathBuf::from(&WorkspaceFolders[0].Uri.replace("file://", ""));
615+
let RootPath = PathBuf::from(&WorkspaceFolders[0].URI.to_string().replace("file://", ""));
616616
let Matcher = GlobBuilder::new(&IncludeStr).literal_separator(false).build().map(|G| G.compile_matcher()).ok();
617617
let PatternLower = Pattern.to_lowercase();
618618
let mut Matches: Vec<serde_json::Value> = Vec::new();

0 commit comments

Comments
 (0)