add publish diagnostics to notifier trait

This commit is contained in:
Josh Thomas 2024-12-10 11:26:51 -06:00
parent 810a591420
commit 2f9fdd6ceb

View file

@ -1,7 +1,9 @@
use anyhow::Result;
use tower_lsp::async_trait;
use tower_lsp::lsp_types::Diagnostic;
use tower_lsp::lsp_types::MessageActionItem;
use tower_lsp::lsp_types::MessageType;
use tower_lsp::lsp_types::Url;
use tower_lsp::Client;
#[async_trait]
@ -14,6 +16,12 @@ pub trait Notifier: Send + Sync {
msg: &str,
actions: Option<Vec<MessageActionItem>>,
) -> Result<Option<MessageActionItem>>;
fn publish_diagnostics(
&self,
uri: Url,
diagnostics: Vec<Diagnostic>,
version: Option<i32>,
) -> Result<()>;
}
pub struct TowerLspNotifier {
@ -56,4 +64,17 @@ impl Notifier for TowerLspNotifier {
let msg = msg.to_string();
Ok(client.show_message_request(typ, msg, actions).await?)
}
fn publish_diagnostics(
&self,
uri: Url,
diagnostics: Vec<Diagnostic>,
version: Option<i32>,
) -> Result<()> {
let client = self.client.clone();
tokio::spawn(async move {
client.publish_diagnostics(uri, diagnostics, version).await;
});
Ok(())
}
}