Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Search/
FindFiles.rs

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