Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/Vine/Server/Notification/
ApplyTextEdits.rs

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