Common/ExtensionManagement/ExtensionManagementService.rs
1// File: Common/Source/ExtensionManagement/ExtensionManagementService.rs
2// Role: Defines the abstract service trait for discovering and managing
3// extensions. Responsibilities:
4// - Provide a contract for scanning the file system for extensions.
5// - Provide a contract for retrieving information about installed extensions.
6
7//! # ExtensionManagementService Trait
8//!
9//! Defines the abstract service trait for discovering and managing extensions.
10
11use async_trait::async_trait;
12use serde_json::Value;
13
14use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
15
16/// An abstract service contract for an environment component that can discover,
17
18/// parse, and provide information about installed extensions.
19#[async_trait]
20pub trait ExtensionManagementService: Environment + Send + Sync {
21 /// Scans the predefined extension directories, parses the `package.json`
22 /// for each found extension, and populates the internal state with the
23 /// results.
24 ///
25 /// This is typically a long-running operation that should be performed
26 /// during application startup.
27 async fn ScanForExtensions(&self) -> Result<(), CommonError>;
28
29 /// Retrieves the metadata for all successfully scanned extensions.
30 ///
31 /// # Returns
32 ///
33 /// A `Result` containing a `Vec<Value>`, where each `Value` is a JSON
34 /// object representing an extension's `package.json` content.
35 async fn GetExtensions(&self) -> Result<Vec<Value>, CommonError>;
36
37 /// Retrieves the metadata for a single extension, identified by its ID
38 /// (e.g., "vscode.typescript-language-features").
39 ///
40 /// # Parameters
41 /// * `ExtensionID`: The unique identifier of the extension to retrieve.
42 ///
43 /// # Returns
44 ///
45 /// A `Result` containing an `Option<Value>`. `Some(Value)` if the extension
46 /// was found, `None` otherwise.
47 async fn GetExtension(&self, ExtensionID:String) -> Result<Option<Value>, CommonError>;
48}