Skip to main content

Mountain/Command/TreeView/
RevealTreeViewItem.rs

1
2//! Tauri command - focus / scroll-into-view a specific tree item.
3//! `Options` carries the LSP-shaped `select`, `focus`, `expand`
4//! booleans (matches `vscode.TreeView.reveal`).
5
6use std::sync::Arc;
7
8use CommonLibrary::TreeView::TreeViewProvider::TreeViewProvider;
9use serde_json::{Value, json};
10use tauri::{AppHandle, Manager, State, Wry, command};
11
12use crate::{
13	ApplicationState::State::ApplicationState::ApplicationState,
14	Environment::MountainEnvironment::MountainEnvironment,
15	RunTime::ApplicationRunTime::ApplicationRunTime,
16	dev_log,
17};
18
19#[command]
20pub async fn RevealTreeViewItem(
21	ApplicationHandle:AppHandle<Wry>,
22
23	_State:State<'_, Arc<ApplicationState>>,
24
25	ViewId:String,
26
27	ItemHandle:String,
28
29	Options:Option<Value>,
30) -> Result<Value, String> {
31	dev_log!("commands", "revealing item '{}' in view '{}'", ItemHandle, ViewId);
32
33	let RunTime = ApplicationHandle.state::<Arc<ApplicationRunTime>>().inner().clone();
34
35	let Environment:Arc<MountainEnvironment> = RunTime.Environment.clone();
36
37	let OptionsValue = Options.unwrap_or(json!({}));
38
39	match Environment.RevealTreeItem(ViewId.clone(), ItemHandle, OptionsValue).await {
40		Ok(_) => Ok(json!({ "success": true })),
41
42		Err(Error) => {
43			let ErrorMessage = format!("Failed to reveal tree item in view '{}': {}", ViewId, Error);
44
45			dev_log!("commands", "error: {}", ErrorMessage);
46
47			Err(ErrorMessage)
48		},
49	}
50}