Mountain/Environment/DocumentProvider/
mod.rs

1//! # DocumentProvider (Environment)
2//!
3//! Implements the `DocumentProvider` trait, managing the complete lifecycle of
4//! document operations including opening, saving, editing, and closing. It
5//! maintains document state, coordinates between the frontend (Sky), extension
6//! host (Cocoon), and filesystem, and handles both native file URIs and custom
7//! scheme URIs.
8//!
9//! ## Implementation Strategy
10//!
11//! The trait implementation is split across multiple helper modules for
12//! maintainability:
13//! - `OpenDocument`: Document opening and content resolution (file:// and
14//! custom schemes)
15//! - `SaveOperations`: SaveDocument, SaveDocumentAs, SaveAllDocuments
16//! - `ApplyChanges`: ApplyDocumentChanges (incremental text edits)
17//! - `Notifications`: NotifyModelAdded, NotifyModelChanged, NotifyModelSaved,
18//! NotifyModelRemoved
19//!
20//! The single `impl DocumentProvider for MountainEnvironment` block in this
21//! file delegates to those helper functions. This satisfies Rust's orphan rules
22//! while keeping code organized and atomic.
23
24use CommonLibrary::Document::DocumentProvider::DocumentProvider;
25use async_trait::async_trait;
26
27// Private helper modules (not re-exported)
28mod OpenDocument;
29mod SaveOperations;
30mod ApplyChanges;
31mod Notifications;
32
33#[async_trait]
34impl DocumentProvider for crate::Environment::MountainEnvironment::MountainEnvironment {
35	async fn OpenDocument(
36		&self,
37		URIComponentsDTO:serde_json::Value,
38		LanguageIdentifier:Option<String>,
39		Content:Option<String>,
40	) -> Result<url::Url, CommonLibrary::Error::CommonError::CommonError> {
41		OpenDocument::open_document(self, URIComponentsDTO, LanguageIdentifier, Content).await
42	}
43
44	async fn SaveDocument(&self, URI:url::Url) -> Result<bool, CommonLibrary::Error::CommonError::CommonError> {
45		SaveOperations::save_document(self, URI).await
46	}
47
48	async fn SaveDocumentAs(
49		&self,
50		OriginalURI:url::Url,
51		NewTargetURI:Option<url::Url>,
52	) -> Result<Option<url::Url>, CommonLibrary::Error::CommonError::CommonError> {
53		SaveOperations::save_document_as(self, OriginalURI, NewTargetURI).await
54	}
55
56	async fn SaveAllDocuments(
57		&self,
58		IncludeUntitled:bool,
59	) -> Result<Vec<bool>, CommonLibrary::Error::CommonError::CommonError> {
60		SaveOperations::save_all_documents(self, IncludeUntitled).await
61	}
62
63	async fn ApplyDocumentChanges(
64		&self,
65		URI:url::Url,
66		NewVersionIdentifier:i64,
67		ChangesDTOCollection:serde_json::Value,
68		_IsDirtyAfterChange:bool,
69		_IsUndoing:bool,
70		_IsRedoing:bool,
71	) -> Result<(), CommonLibrary::Error::CommonError::CommonError> {
72		ApplyChanges::apply_document_changes(
73			self,
74			URI,
75			NewVersionIdentifier,
76			ChangesDTOCollection,
77			_IsDirtyAfterChange,
78			_IsUndoing,
79			_IsRedoing,
80		)
81		.await
82	}
83}