Mountain/IPC/WindServiceHandlers/
Search.rs1#![allow(non_snake_case, unused_variables, dead_code, unused_imports)]
2
3use std::sync::Arc;
25
26use serde_json::{Value, json};
27use CommonLibrary::{Search::SearchProvider::SearchProvider, Workspace::WorkspaceProvider::WorkspaceProvider};
28
29use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
30
31pub async fn SearchFindInFiles(RunTime:Arc<ApplicationRunTime>, mut Arguments:Vec<Value>) -> Result<Value, String> {
39 let QueryValue = if Arguments.first().map(|V| V.is_object()).unwrap_or(false) {
45 Arguments.remove(0)
46 } else if let Some(Pattern) = Arguments.first().and_then(|V| V.as_str()) {
47 let IsRegex = Arguments.get(1).and_then(|V| V.as_bool()).unwrap_or(false);
48 let IsCase = Arguments.get(2).and_then(|V| V.as_bool()).unwrap_or(false);
49 let IsWord = Arguments.get(3).and_then(|V| V.as_bool()).unwrap_or(false);
50 json!({
51 "pattern": Pattern,
52 "isRegex": IsRegex,
53 "isCaseSensitive": IsCase,
54 "isWordMatch": IsWord,
55 })
56 } else {
57 return Err("search:findInFiles requires pattern or TextSearchQuery".to_string());
58 };
59
60 let OptionsValue = Arguments.into_iter().next().unwrap_or(Value::Null);
61
62 dev_log!("search", "search:textSearch delegating to SearchProvider::TextSearch");
63
64 RunTime
65 .Environment
66 .TextSearch(QueryValue, OptionsValue)
67 .await
68 .map_err(|Error| Error.to_string())
69}
70
71pub async fn SearchFindFiles(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
78 let IncludePattern = Arguments
79 .first()
80 .cloned()
81 .ok_or_else(|| "search:findFiles requires include pattern in slot 0".to_string())?;
82 let ExcludePattern = Arguments.get(1).cloned().filter(|V| !V.is_null());
83 let MaxResults = Arguments.get(2).and_then(|V| V.as_u64()).map(|N| N as usize);
84 let UseIgnoreFiles = Arguments.get(3).and_then(|V| V.as_bool()).unwrap_or(true);
85 let FollowSymlinks = Arguments.get(4).and_then(|V| V.as_bool()).unwrap_or(false);
86
87 dev_log!(
88 "search",
89 "search:fileSearch delegating to WorkspaceProvider::FindFilesInWorkspace (ignore={}, symlinks={})",
90 UseIgnoreFiles,
91 FollowSymlinks
92 );
93
94 let Urls = RunTime
95 .Environment
96 .FindFilesInWorkspace(IncludePattern, ExcludePattern, MaxResults, UseIgnoreFiles, FollowSymlinks)
97 .await
98 .map_err(|Error| Error.to_string())?;
99
100 Ok(json!(Urls.into_iter().map(|U| U.to_string()).collect::<Vec<_>>()))
101}