Skip to main content

DevelopmentNodeEnvironment_MicrosoftVSCodeDependency_22NodeVersion_Bundle_Clean_Debug_ElectronProfile_EsbuildCompiler_Mountain/IPC/WindServiceHandlers/Model/
TextfileRead.rs

1//! Read a text file from disk verbatim. Distinct from
2//! `ModelOpen` - this returns the bytes without registering a
3//! `DocumentStateDTO`. Used by tooling paths that want raw
4//! content (e.g. import resolvers, settings inspectors).
5
6use std::sync::Arc;
7
8use serde_json::Value;
9
10use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
11
12pub async fn Fn(_runtime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
13	let Path = Arguments
14		.first()
15		.and_then(|V| V.as_str())
16		.ok_or_else(|| "textFile:read requires path as first argument".to_string())?;
17
18	tokio::fs::read_to_string(Path)
19		.await
20		.map(Value::String)
21		.map_err(|Error| format!("textFile:read failed: {}", Error))
22}