Skip to main content

Mountain/IPC/WindServiceHandlers/FileSystem/Native/
FileRealpath.rs

1//! Wire method `file:realpath`. Emits a VS Code `UriComponents` (`$mid: 1`)
2//! so the renderer reviver promotes it to a real `URI` with `.fsPath` /
3//! `.with`. Plain string would be treated as a relative path.
4
5use serde_json::Value;
6
7use crate::IPC::{
8	UriComponents::FromFilePath::Fn as UriFromFilePath,
9	WindServiceHandlers::Utilities::PathExtraction::Fn as extract_path_from_arg,
10};
11
12pub async fn Fn(Arguments:Vec<Value>) -> Result<Value, String> {
13	let Path = extract_path_from_arg(Arguments.get(0).ok_or("Missing path")?)?;
14
15	let Canonical = tokio::fs::canonicalize(&Path)
16		.await
17		.map_err(|E| format!("Failed to realpath: {} ({})", Path, E))?;
18
19	Ok(UriFromFilePath(Canonical.to_string_lossy()))
20}