Skip to main content

Mountain/IPC/WindServiceHandlers/Search/
FindInFiles.rs

1#![allow(unused_variables, dead_code, unused_imports)]
2
3//! Wire method: `search:findInFiles` / `search:textSearch`.
4//! Delegates to `SearchProvider::TextSearch`.
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>, mut Arguments:Vec<Value>) -> Result<Value, String> {
13	use CommonLibrary::Search::SearchProvider::SearchProvider;
14
15	let QueryValue = if Arguments.first().map(|V| V.is_object()).unwrap_or(false) {
16		Arguments.remove(0)
17	} else if let Some(Pattern) = Arguments.first().and_then(|V| V.as_str()) {
18		let IsRegex = Arguments.get(1).and_then(|V| V.as_bool()).unwrap_or(false);
19
20		let IsCase = Arguments.get(2).and_then(|V| V.as_bool()).unwrap_or(false);
21
22		let IsWord = Arguments.get(3).and_then(|V| V.as_bool()).unwrap_or(false);
23
24		json!({
25			"pattern": Pattern,
26			"isRegex": IsRegex,
27			"isCaseSensitive": IsCase,
28			"isWordMatch": IsWord,
29		})
30	} else {
31		return Err("search:findInFiles requires pattern or TextSearchQuery".to_string());
32	};
33
34	let OptionsValue = Arguments.into_iter().next().unwrap_or(Value::Null);
35
36	dev_log!("search", "search:textSearch delegating to SearchProvider::TextSearch");
37
38	RunTime
39		.Environment
40		.TextSearch(QueryValue, OptionsValue)
41		.await
42		.map_err(|Error| Error.to_string())
43}