Common/Diagnostic/SetDiagnostics.rs
1//! # SetDiagnostics Effect
2//!
3//! Defines the `ActionEffect` for setting or updating diagnostics for a given
4//! owner.
5
6use std::sync::Arc;
7
8use serde_json::Value;
9
10use super::DiagnosticManager::DiagnosticManager;
11use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
12
13/// Creates an effect that, when executed, will set or update diagnostics for a
14/// given owner. This is the primary way extensions report problems to the host.
15///
16/// It uses the `DiagnosticManager` capability from the environment to perform
17/// the operation, which involves updating the central diagnostic store.
18///
19/// # Parameters
20/// * `Owner`: A string identifying the source of the diagnostics (e.g.,
21
22/// 'typescript-linter').
23/// * `EntriesDTOValue`: A `serde_json::Value` representing an array of entries.
24/// Each entry is a tuple: `[UriComponentsValue,
25
26/// Option<Vec<MarkerDataDTOAsValue>>]`.
27///
28/// # Returns
29/// An `ActionEffect` that resolves to `()` on success.
30pub fn SetDiagnostics(
31 Owner:String,
32
33 EntriesDTOValue:Value,
34) -> ActionEffect<Arc<dyn DiagnosticManager>, CommonError, ()> {
35 ActionEffect::New(Arc::new(move |Manager:Arc<dyn DiagnosticManager>| {
36 let OwnerClone = Owner.clone();
37
38 let EntriesClone = EntriesDTOValue.clone();
39
40 Box::pin(async move { Manager.SetDiagnostics(OwnerClone, EntriesClone).await })
41 }))
42}