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