Mountain/IPC/WindServiceHandlers/Navigation/LabelGetWorkspace.rs
1
2//! Display label for the current workspace's root folder.
3//! Prefers the explicit `Name` if the user set one
4//! (`.code-workspace`'s `name` field); otherwise falls back to
5//! the trailing path segment of the URI.
6
7use std::sync::Arc;
8
9use serde_json::Value;
10
11use crate::RunTime::ApplicationRunTime::ApplicationRunTime;
12
13pub async fn Fn(RunTime:Arc<ApplicationRunTime>) -> Result<Value, String> {
14 let Label = RunTime
15 .Environment
16 .ApplicationState
17 .Workspace
18 .GetWorkspaceFolders()
19 .into_iter()
20 .next()
21 .map(|F| {
22 if !F.Name.is_empty() {
23 F.Name
24 } else {
25 F.URI
26 .path_segments()
27 .and_then(|mut S| S.next_back())
28 .map(|S| S.to_owned())
29 .unwrap_or_else(|| F.URI.to_string())
30 }
31 })
32 .unwrap_or_default();
33
34 Ok(Value::String(Label))
35}