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