Skip to content

Commit 1097ef9

Browse files
plugin: dispac call for hooks
Signed-off-by: Vincenzo Palazzo <[email protected]>
1 parent b79651d commit 1097ef9

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

plugin/src/plugin.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,21 @@ impl<'a, T: 'a + Clone> Plugin<T> {
191191
name: &str,
192192
params: serde_json::Value,
193193
) -> Result<serde_json::Value, PluginError> {
194-
let command = self.rpc_method.get(name).unwrap().clone();
195-
command.call(self, params)
194+
let Some(command) = self.rpc_method.get(name) else {
195+
return self.call_hook(name, params);
196+
};
197+
command.clone().call(self, params)
198+
}
199+
200+
fn call_hook(
201+
&mut self,
202+
name: &str,
203+
params: serde_json::Value,
204+
) -> Result<serde_json::Value, PluginError> {
205+
let Some(command) = self.rpc_hook.get(name) else {
206+
return Err(crate::error!("callback for method/hook `{name}` not found"));
207+
};
208+
command.clone().call(self, params)
196209
}
197210

198211
fn handle_notification(&'a mut self, name: &str, params: serde_json::Value) {

0 commit comments

Comments
 (0)