Common/WorkSpace/
FindFilesInWorkSpace.rs

1//! # FindFilesInWorkSpace Effect
2//!
3//! Defines the `ActionEffect` for finding files within the workspace that
4//! match given glob patterns.
5
6use std::sync::Arc;
7
8use serde_json::Value;
9use url::Url;
10
11use super::WorkSpaceProvider::WorkSpaceProvider;
12use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
13
14/// Creates an effect that, when executed, will find files within the workspace
15/// based on include and exclude glob patterns.
16///
17/// It uses the `WorkSpaceProvider` capability from the environment to perform
18/// the search.
19///
20/// # Parameters
21/// * `IncludePatternDTO`: A `serde_json::Value` representing the glob pattern
22///   to include.
23/// * `ExcludePatternDTO`: An optional `serde_json::Value` for files/folders to
24///   exclude.
25/// * `MaxResults`: An optional limit on the number of results to return.
26/// * `UseIgnoreFiles`: Whether to respect `.gitignore`-style ignore files.
27/// * `FollowSymlinks`: Whether to follow symbolic links during the search.
28///
29/// # Returns
30/// An `ActionEffect` that resolves with a `Vec<Url>` of the matching file URIs.
31pub fn FindFilesInWorkSpace(
32	IncludePatternDTO:Value,
33
34	ExcludePatternDTO:Option<Value>,
35
36	MaxResults:Option<usize>,
37
38	UseIgnoreFiles:bool,
39
40	FollowSymlinks:bool,
41) -> ActionEffect<Arc<dyn WorkSpaceProvider>, CommonError, Vec<Url>> {
42	ActionEffect::New(Arc::new(move |Provider:Arc<dyn WorkSpaceProvider>| {
43		let IncludeClone = IncludePatternDTO.clone();
44
45		let ExcludeClone = ExcludePatternDTO.clone();
46
47		Box::pin(async move {
48			Provider
49				.FindFilesInWorkSpace(IncludeClone, ExcludeClone, MaxResults, UseIgnoreFiles, FollowSymlinks)
50				.await
51		})
52	}))
53}