Skip to main content

Mountain/IPC/WindServiceHandlers/FileSystem/Native/
FileUnwatch.rs

1//! `file:unwatch` - unregister a native filesystem watcher by its token.
2//!
3//! VS Code's `DiskFileSystemProvider` calls this when an extension disposes
4//! its `FileSystemWatcher` or when the workspace is closed.
5//!
6//! Arguments\[0\] = the numeric token string returned by `file:watch`.
7
8use std::sync::Arc;
9
10use CommonLibrary::FileSystem::FileWatcherProvider::FileWatcherProvider;
11use serde_json::Value;
12
13use crate::{RunTime::ApplicationRunTime::ApplicationRunTime, dev_log};
14
15pub async fn Fn(RunTime:Arc<ApplicationRunTime>, Arguments:Vec<Value>) -> Result<Value, String> {
16	let Token = Arguments
17		.first()
18		.and_then(|V| {
19			// Handle both numeric and string tokens.
20			V.as_str().map(str::to_owned).or_else(|| V.as_u64().map(|N| N.to_string()))
21		})
22		.unwrap_or_default();
23
24	if Token.is_empty() {
25		return Ok(Value::Null);
26	}
27
28	dev_log!("filewatcher", "file:unwatch handle={}", Token);
29
30	RunTime
31		.Environment
32		.UnregisterWatcher(Token)
33		.await
34		.map_err(|E| format!("file:unwatch: {E}"))?;
35
36	Ok(Value::Null)
37}