Common/CustomEditor/CustomEditorProvider.rs
1// File: Common/Source/CustomEditor/CustomEditorProvider.rs
2// Role: Defines the abstract service trait for managing custom editors.
3// Responsibilities:
4// - Provide a contract for registering and unregistering custom editor
5// providers.
6// - Define the communication protocol for saving and resolving custom editor
7// content between the host (Mountain) and extension host (Cocoon).
8
9//! # CustomEditorProvider Trait
10//!
11//! Defines the abstract service trait for managing custom editors.
12
13use async_trait::async_trait;
14use serde_json::Value;
15use url::Url;
16
17use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
18
19/// An abstract service contract for an environment component that can manage
20/// the registration and resolution of custom, WebView-based editors.
21#[async_trait]
22pub trait CustomEditorProvider: Environment + Send + Sync {
23 /// Registers a new custom editor provider from an extension.
24 ///
25 /// # Parameters
26 /// * `ViewType`: A unique identifier for the custom editor.
27 /// * `OptionsValue`: A DTO containing options, including file patterns and
28 /// webview options.
29 async fn RegisterCustomEditorProvider(&self, ViewType:String, OptionsValue:Value) -> Result<(), CommonError>;
30
31 /// Unregisters a previously registered custom editor provider.
32 ///
33 /// # Parameters
34 /// * `ViewType`: The identifier of the provider to unregister.
35 async fn UnregisterCustomEditorProvider(&self, ViewType:String) -> Result<(), CommonError>;
36
37 /// A notification sent from the extension host (`Cocoon`) to the main host
38 /// (`Mountain`) when a custom document is saved by the user in the UI.
39 ///
40 /// # Parameters
41 /// * `ViewType`: The identifier of the custom editor.
42 /// * `ResourceURI`: The URI of the document being saved.
43 async fn OnSaveCustomDocument(&self, ViewType:String, ResourceURI:Url) -> Result<(), CommonError>;
44
45 /// A request sent from the main host (`Mountain`) to the extension host
46 /// (`Cocoon`) to resolve the content for a custom editor.
47 ///
48 /// # Parameters
49 /// * `ViewType`: The identifier of the custom editor.
50 /// * `ResourceURI`: The URI of the document to resolve.
51 /// * `WebViewPanelHandle`: The unique handle for the webview panel hosting
52 /// the editor.
53 async fn ResolveCustomEditor(
54 &self,
55
56 ViewType:String,
57
58 ResourceURI:Url,
59
60 WebViewPanelHandle:String,
61 ) -> Result<(), CommonError>;
62}