|
| 1 | +use crate::language_client::LanguageClient; |
| 2 | +use crate::types::{VIM_SERVER_STATUS, VIM_SERVER_STATUS_MESSAGE}; |
| 3 | +use crate::utils::escape_single_quote; |
| 4 | +use anyhow::Result; |
| 5 | +use jsonrpc_core::Value; |
| 6 | +use serde::{Deserialize, Serialize}; |
| 7 | + |
| 8 | +pub mod notification { |
| 9 | + pub const WINDOW_PROGRESS: &str = "window/progress"; |
| 10 | + pub const RUST_DOCUMENT_BEGIN_BUILD: &str = "rustDocument/beginBuild"; |
| 11 | + pub const RUST_DOCUMENT_DIAGNOSTICS_BEGIN: &str = "rustDocument/diagnosticsBegin"; |
| 12 | + pub const RUST_DOCUMENT_DIAGNOSTICS_END: &str = "rustDocument/diagnosticsEnd"; |
| 13 | +} |
| 14 | + |
| 15 | +#[derive(Debug, Serialize, Deserialize)] |
| 16 | +pub struct WindowProgressParams { |
| 17 | + pub title: Option<String>, |
| 18 | + pub message: Option<String>, |
| 19 | + pub percentage: Option<f64>, |
| 20 | + pub done: Option<bool>, |
| 21 | +} |
| 22 | + |
| 23 | +impl LanguageClient { |
| 24 | + #[tracing::instrument(level = "info", skip(self))] |
| 25 | + pub fn rls_window_progress(&self, params: &Value) -> Result<()> { |
| 26 | + let params = WindowProgressParams::deserialize(params)?; |
| 27 | + |
| 28 | + let done = params.done.unwrap_or(false); |
| 29 | + |
| 30 | + let mut buf = "LS: ".to_owned(); |
| 31 | + |
| 32 | + if done { |
| 33 | + buf += "Idle"; |
| 34 | + } else { |
| 35 | + // For RLS this can be "Build" or "Diagnostics" or "Indexing". |
| 36 | + buf += params.title.as_ref().map(AsRef::as_ref).unwrap_or("Busy"); |
| 37 | + |
| 38 | + // For RLS this is the crate name, present only if the progress isn't known. |
| 39 | + if let Some(message) = params.message { |
| 40 | + buf += &format!(" ({})", &message); |
| 41 | + } |
| 42 | + // For RLS this is the progress percentage, present only if the it's known. |
| 43 | + if let Some(percentage) = params.percentage { |
| 44 | + buf += &format!(" ({:.1}% done)", percentage); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + self.vim()?.command(vec![ |
| 49 | + format!("let {}={}", VIM_SERVER_STATUS, if done { 0 } else { 1 }), |
| 50 | + format!( |
| 51 | + "let {}='{}'", |
| 52 | + VIM_SERVER_STATUS_MESSAGE, |
| 53 | + &escape_single_quote(buf) |
| 54 | + ), |
| 55 | + ])?; |
| 56 | + Ok(()) |
| 57 | + } |
| 58 | + |
| 59 | + #[tracing::instrument(level = "info", skip(self))] |
| 60 | + pub fn rls_handle_begin_build(&self, _params: &Value) -> Result<()> { |
| 61 | + self.vim()?.command(vec![ |
| 62 | + format!("let {}=1", VIM_SERVER_STATUS), |
| 63 | + format!("let {}='Rust: build begin'", VIM_SERVER_STATUS_MESSAGE), |
| 64 | + ])?; |
| 65 | + Ok(()) |
| 66 | + } |
| 67 | + |
| 68 | + #[tracing::instrument(level = "info", skip(self))] |
| 69 | + pub fn rls_handle_diagnostics_begin(&self, _params: &Value) -> Result<()> { |
| 70 | + self.vim()?.command(vec![ |
| 71 | + format!("let {}=1", VIM_SERVER_STATUS), |
| 72 | + format!( |
| 73 | + "let {}='Rust: diagnostics begin'", |
| 74 | + VIM_SERVER_STATUS_MESSAGE |
| 75 | + ), |
| 76 | + ])?; |
| 77 | + Ok(()) |
| 78 | + } |
| 79 | + |
| 80 | + #[tracing::instrument(level = "info", skip(self))] |
| 81 | + pub fn rls_handle_diagnostics_end(&self, _params: &Value) -> Result<()> { |
| 82 | + self.vim()?.command(vec![ |
| 83 | + format!("let {}=0", VIM_SERVER_STATUS), |
| 84 | + format!("let {}='Rust: diagnostics end'", VIM_SERVER_STATUS_MESSAGE), |
| 85 | + ])?; |
| 86 | + Ok(()) |
| 87 | + } |
| 88 | +} |
0 commit comments