Skip to main content

Mountain/IPC/WindServiceHandlers/Model/
ModelGet.rs

1
2//! Snapshot a single open text model. Returns
3//! `{ uri, content, version, languageId }` or `null` when the
4//! URI isn't currently open. `content` is rejoined from
5//! `Lines` using the document's EOL so the wire shape matches
6//! VS Code's `TextDocument.getText()`.
7
8use std::sync::Arc;
9
10use serde_json::{Value, json};
11
12use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
13
14pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
15	let Uri = Arguments
16		.first()
17		.and_then(|V| V.as_str())
18		.ok_or("model:get requires uri".to_string())?;
19
20	match RunTime.Environment.ApplicationState.Feature.Documents.Get(Uri) {
21		None => Ok(Value::Null),
22
23		Some(Document) => {
24			Ok(json!({
25				"uri": Uri,
26				"content": Document.Lines.join(&Document.EOL),
27				"version": Document.Version,
28				"languageId": Document.LanguageIdentifier,
29			}))
30		},
31	}
32}