+ macro_rules! threadsafe_function {
+ (
+ $js_namespace_name:literal: $module_name:ident {
+ $(
+ $function_js_name:literal: $function_module_name:ident(
+ $(
+ $argument_type:ty
+ ),+
+ ) -> $return_type:ty;
+ )*
+ }
+ ) => {
+ pub mod $module_name {
+ $(
+ pub mod $function_module_name {
+ use napi::bindgen_prelude::JsObjectValue;
+
+ pub type Arguments = napi::bindgen_prelude::FnArgs<($($argument_type,)*)>;
+ pub type Return = $return_type;
+
+ pub type Prototype = napi::threadsafe_function::ThreadsafeFunction<
+ Arguments,
+ Return,
+ Arguments,
+ napi::Status,
+ false,
+ false,
+ 0,
+ >;
+
+ pub fn get(env: &napi::Env) -> Result<Prototype, napi::Error> {
+ let vscode_object = crate::vscode_sys::VscodeContext::vscode(env)?;
+ let namespace: napi::bindgen_prelude::Object = vscode_object.get_named_property($js_namespace_name)?;
+
+ namespace.get_named_property($function_js_name)
+ }
+ }
+ )*
+ }
+ };
+ }
+
+ pub(crate) use threadsafe_function;