Common/WorkSpace/
WorkSpaceProvider.rs

1//! # WorkSpaceProvider Trait
2//!
3//! Defines the abstract service trait for querying and managing the
4//! application's workspace.
5
6use std::path::PathBuf;
7
8use async_trait::async_trait;
9use serde_json::Value;
10use url::Url;
11
12use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
13
14/// An abstract service contract for an environment component that can provide
15/// information about the current workspace.
16///
17/// This trait is the primary interface for interacting with workspace folders,
18
19/// configuration paths, trust settings, and for performing workspace-wide
20/// operations like finding files.
21#[async_trait]
22pub trait WorkSpaceProvider: Environment + Send + Sync {
23	/// Retrieves information about all currently open workspace folders.
24	///
25	/// # Returns
26	/// A `Result` containing a vector of tuples, where each tuple is
27	/// `(FolderURI, FolderName, FolderIndex)`.
28	async fn GetWorkSpaceFoldersInfo(&self) -> Result<Vec<(Url, String, usize)>, CommonError>;
29
30	/// Retrieves information for the specific workspace folder that contains
31	/// the given URI.
32	///
33	/// # Parameters
34	/// * `URIToMatch`: The URI to find the containing folder for.
35	async fn GetWorkSpaceFolderInfo(&self, URIToMatch:Url) -> Result<Option<(Url, String, usize)>, CommonError>;
36
37	/// Gets the name of the current workspace.
38	async fn GetWorkSpaceName(&self) -> Result<Option<String>, CommonError>;
39
40	/// Gets the path to the workspace configuration file (e.g., a
41	/// `.code-workspace` file), if one exists.
42	async fn GetWorkSpaceConfigurationPath(&self) -> Result<Option<PathBuf>, CommonError>;
43
44	/// Checks if the current workspace is trusted by the user.
45	async fn IsWorkSpaceTrusted(&self) -> Result<bool, CommonError>;
46
47	/// Prompts the user to grant or deny trust to the current workspace.
48	///
49	/// # Parameters
50	/// * `Options`: Optional DTO with further information for the trust prompt.
51	async fn RequestWorkSpaceTrust(&self, Options:Option<Value>) -> Result<bool, CommonError>;
52
53	/// Finds files within the workspace matching the given criteria.
54	///
55	/// # Parameters
56	/// * `IncludePatternDTO`: A DTO representing the glob pattern to include.
57	/// * `ExcludePatternDTO`: An optional DTO for files/folders to exclude.
58	/// * `MaxResults`: An optional limit on the number of results to return.
59	/// * `UseIgnoreFiles`: Whether to respect `.gitignore`-style ignore files.
60	/// * `FollowSymlinks`: Whether to follow symbolic links during the search.
61	async fn FindFilesInWorkSpace(
62		&self,
63
64		IncludePatternDTO:Value,
65
66		ExcludePatternDTO:Option<Value>,
67
68		MaxResults:Option<usize>,
69
70		UseIgnoreFiles:bool,
71
72		FollowSymlinks:bool,
73	) -> Result<Vec<Url>, CommonError>;
74
75	/// Requests that the host application open the specified file path in an
76	/// editor.
77	async fn OpenFile(&self, Path:PathBuf) -> Result<(), CommonError>;
78}