lapce-plugin-rust icon indicating copy to clipboard operation
lapce-plugin-rust copied to clipboard

Function to send notification to client editor

Open MinusGix opened this issue 2 years ago • 0 comments

There should be a function to easily send a notification to the client from a plugin. This can currently be achieved via object_to_stdout, but in a somewhat unpleasant manner and makes the plugin authors have to figure out the details of the LSP/PSP api for sending information. (I think that function should also be hidden, and plugin authors using the library should just deal with functions for sending notifications/requests)
We can use lsp-types/psp-types Notification trait to make things more type-safe, like:

pub fn send_notification<T: Notification>(params: T::Params) {
    // Having them give the `T` ensures that they can't give us the wrong method name or the wrong params
    // They can still do custom notifications (like editor-specific notifs) via making a custom structure and implementing Notification on it
    let method: &'static str = T::METHOD;
    // We could just have send_host_notification take `impl Serialize`?
    send_host_notification(method, json!(params));
}

MinusGix avatar Sep 13 '22 12:09 MinusGix