Common/Diagnostic/
DiagnosticManager.rs

1// File: Common/Source/Diagnostic/DiagnosticManager.rs
2// Role: Defines the abstract service trait for managing diagnostic collections.
3// Responsibilities:
4//   - Provide a contract for setting, clearing, and retrieving diagnostics.
5//   - This trait is the central point of interaction for any component that
6//     needs to manage problem markers (errors, warnings, etc.) in the
7//     workspace.
8
9//! # DiagnosticManager Trait
10//!
11//! Defines the abstract service trait for managing diagnostic collections,
12
13//! which represent problems like errors and warnings in source code.
14
15use async_trait::async_trait;
16use serde_json::Value;
17
18use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
19
20/// An abstract service contract for an environment component that can manage
21/// diagnostic collections.
22///
23/// Diagnostics are problems detected in the workspace, such as compiler errors
24/// or linter warnings. They are typically owned by a source (e.g., a
25/// "typescript-linter") and associated with specific resource URIs.
26#[async_trait]
27pub trait DiagnosticManager: Environment + Send + Sync {
28	/// Sets or updates diagnostics for multiple resources from a specific
29	/// owner.
30	///
31	/// # Parameters
32	/// * `Owner`: A string identifying the source of the diagnostics (e.g.,
33
34	///   "cocoon-diag-0-typescript").
35	/// * `EntriesDTOValue`: A `serde_json::Value` that deserializes into an
36	///   array of tuples. Each tuple has the shape `[UriComponentsDTO,
37
38	///   Option<Vec<MarkerDataDTO>>]`. To clear diagnostics for a resource,
39
40	///   provide `None` or an empty vector for its entry.
41	async fn SetDiagnostics(&self, Owner:String, EntriesDTOValue:Value) -> Result<(), CommonError>;
42
43	/// Clears all diagnostics that were previously reported by a specific
44	/// owner.
45	///
46	/// # Parameters
47	/// * `Owner`: The identifier of the diagnostic source to clear.
48	async fn ClearDiagnostics(&self, Owner:String) -> Result<(), CommonError>;
49
50	/// Retrieves all diagnostics currently in the system, with an option to
51	/// filter by a specific resource URI.
52	///
53	/// # Parameters
54	/// * `ResourceURIFilterOption`: An optional `serde_json::Value`
55	///   representing a `UriComponents` DTO. If `Some`, only diagnostics for
56	///   that specific URI are returned. If `None`, all diagnostics are
57	///   returned.
58	///
59	/// # Returns
60	/// A `serde_json::Value` representing an array of tuples:
61	/// `Vec<[UriComponentsDTO, Vec<MarkerDataDTO>]>`.
62	async fn GetAllDiagnostics(&self, ResourceURIFilterOption:Option<Value>) -> Result<Value, CommonError>;
63}