Skip to main content

Mountain/IPC/WindServiceHandlers/Search/
FindFiles.rs

1#![allow(unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `search:findFiles` / `search:fileSearch`.
4//! Delegates to `WorkspaceProvider::FindFilesInWorkspace`.
5
6use std::sync::Arc;
7
8use serde_json::{Value, json};
9
10use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
11
12pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
13	use CommonLibrary::Workspace::WorkspaceProvider::WorkspaceProvider;
14
15	let IncludePattern = Arguments
16		.first()
17		.cloned()
18		.ok_or_else(|| "search:findFiles requires include pattern in slot 0".to_string())?;
19
20	let ExcludePattern = Arguments.get(1).cloned().filter(|V| !V.is_null());
21
22	let MaxResults = Arguments.get(2).and_then(|V| V.as_u64()).map(|N| N as usize);
23
24	let UseIgnoreFiles = Arguments.get(3).and_then(|V| V.as_bool()).unwrap_or(true);
25
26	let FollowSymlinks = Arguments.get(4).and_then(|V| V.as_bool()).unwrap_or(false);
27
28	dev_log!(
29		"search",
30		"search:fileSearch delegating to WorkspaceProvider::FindFilesInWorkspace (ignore={}, symlinks={})",
31		UseIgnoreFiles,
32		FollowSymlinks
33	);
34
35	let Urls = RunTime
36		.Environment
37		.FindFilesInWorkspace(IncludePattern, ExcludePattern, MaxResults, UseIgnoreFiles, FollowSymlinks)
38		.await
39		.map_err(|Error| Error.to_string())?;
40
41	Ok(json!(Urls.into_iter().map(|U| U.to_string()).collect::<Vec<_>>()))
42}