DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Vine/Server/Notification/ApplyTextEdits.rs
1//! Cocoon → Mountain `window.applyTextEdits` notification.
2//!
3//! Fired when an extension calls `editor.edit(editBuilder => { ... })`.
4//! Cocoon's TextEditor shim collects the edits and sends them here.
5//! Mountain emits `sky://editor/apply-text-edits` so Sky can apply them
6//! via `ICodeEditorService.listCodeEditors()` → `editor.executeEdits(...)`.
7//!
8//! Payload shape:
9//! ```json
10//! {
11//! "uri": "file:///path/to/file.ts",
12//! "edits": [
13//! { "range": { "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 10 }, "text": "replacement" },
14//! { "range": { ... }, "text": "" }
15//! ]
16//! }
17//! ```
18
19use serde_json::Value;
20use tauri::{AppHandle, Emitter};
21
22use crate::{Vine::Server::MountainVinegRPCService::MountainVinegRPCService, dev_log};
23
24pub async fn ApplyTextEdits(Service:&MountainVinegRPCService, Parameter:&Value) {
25 let Uri = Parameter.get("uri").and_then(Value::as_str).unwrap_or("").to_string();
26
27 let EditCount = Parameter.get("edits").and_then(Value::as_array).map(|A| A.len()).unwrap_or(0);
28
29 dev_log!("model", "[ApplyTextEdits] uri={} edits={}", Uri, EditCount);
30
31 if Uri.is_empty() || EditCount == 0 {
32 return;
33 }
34
35 if let Err(E) = Service.ApplicationHandle().emit("sky://editor/apply-text-edits", Parameter) {
36 dev_log!("sky-emit", "[ApplyTextEdits] emit failed: {}", E);
37 }
38}