Skip to main content

Mountain/IPC/WindServiceHandlers/Navigation/
LabelGetWorkspace.rs

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