Skip to main content

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;
29
30mod SaveOperations;
31
32mod ApplyChanges;
33
34mod Notifications;
35
36#[async_trait]
37impl DocumentProvider for crate::Environment::MountainEnvironment::MountainEnvironment {
38	async fn OpenDocument(
39		&self,
40
41		URIComponentsDTO:serde_json::Value,
42
43		LanguageIdentifier:Option<String>,
44
45		Content:Option<String>,
46	) -> Result<url::Url, CommonLibrary::Error::CommonError::CommonError> {
47		OpenDocument::open_document(self, URIComponentsDTO, LanguageIdentifier, Content).await
48	}
49
50	async fn SaveDocument(&self, URI:url::Url) -> Result<bool, CommonLibrary::Error::CommonError::CommonError> {
51		SaveOperations::save_document(self, URI).await
52	}
53
54	async fn SaveDocumentAs(
55		&self,
56
57		OriginalURI:url::Url,
58
59		NewTargetURI:Option<url::Url>,
60	) -> Result<Option<url::Url>, CommonLibrary::Error::CommonError::CommonError> {
61		SaveOperations::save_document_as(self, OriginalURI, NewTargetURI).await
62	}
63
64	async fn SaveAllDocuments(
65		&self,
66
67		IncludeUntitled:bool,
68	) -> Result<Vec<bool>, CommonLibrary::Error::CommonError::CommonError> {
69		SaveOperations::save_all_documents(self, IncludeUntitled).await
70	}
71
72	async fn ApplyDocumentChanges(
73		&self,
74
75		URI:url::Url,
76
77		NewVersionIdentifier:i64,
78
79		ChangesDTOCollection:serde_json::Value,
80
81		_IsDirtyAfterChange:bool,
82
83		_IsUndoing:bool,
84
85		_IsRedoing:bool,
86	) -> Result<(), CommonLibrary::Error::CommonError::CommonError> {
87		ApplyChanges::apply_document_changes(
88			self,
89			URI,
90			NewVersionIdentifier,
91			ChangesDTOCollection,
92			_IsDirtyAfterChange,
93			_IsUndoing,
94			_IsRedoing,
95		)
96		.await
97	}
98}