Skip to main content

Mountain/IPC/WindServiceHandlers/Model/
ModelGet.rs

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