Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Model/
ModelGet.rs

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