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