diff --git a/src/controller/diagnostic.rs b/src/controller/diagnostic.rs index 91ff2c9..9764528 100644 --- a/src/controller/diagnostic.rs +++ b/src/controller/diagnostic.rs @@ -50,9 +50,7 @@ impl DiagnosticController { let rev = self.rev.entry(uri.clone()).or_insert(0); *rev += 1; let diags: Vec = diags_map.values().cloned().collect(); - self.client - .publish_diagnostics(uri.clone(), diags, Some(*rev)) - .await; + publish(&self.client, uri, diags).await; } pub async fn add_parse_diagnostic(&mut self, uri: &Uri, id: &str, diag: Diagnostic) { @@ -66,9 +64,7 @@ impl DiagnosticController { let diags_map = self.diagnostics.get(uri).unwrap(); // Update the revision number for the given URI let diags: Vec = diags_map.values().cloned().collect(); - self.client - .publish_diagnostics(uri.clone(), diags, None) - .await; + publish(&self.client, uri, diags).await; } pub async fn clear_cargo_diagnostics(&mut self, uri: &Uri) { @@ -77,9 +73,7 @@ impl DiagnosticController { // Update diagnostics display let diags: Vec = diags_map.values().cloned().collect(); - self.client - .publish_diagnostics(uri.clone(), diags, None) - .await; + publish(&self.client, uri, diags).await; } } @@ -89,9 +83,7 @@ impl DiagnosticController { // Update diagnostics display let diags: Vec = diags_map.values().cloned().collect(); - self.client - .publish_diagnostics(uri.clone(), diags, None) - .await; + publish(&self.client, uri, diags).await; } } @@ -106,9 +98,7 @@ impl DiagnosticController { let diags_map = self.diagnostics.get(uri).unwrap(); // Update the revision number for the given URI let diags: Vec = diags_map.values().cloned().collect(); - self.client - .publish_diagnostics(uri.clone(), diags, None) - .await; + publish(&self.client, uri, diags).await; } pub async fn clear_audit_diagnostics(&mut self) { @@ -117,9 +107,13 @@ impl DiagnosticController { // Update diagnostics display let diags: Vec = diags_map.values().cloned().collect(); - self.client - .publish_diagnostics(uri.clone(), diags, None) - .await; + publish(&self.client, uri, diags).await; } } } + +async fn publish(client: &Client, uri: &Uri, diags: Vec) { + if !diags.is_empty() { + client.publish_diagnostics(uri.clone(), diags, None).await + } +} diff --git a/src/decoration/inlay_hint.rs b/src/decoration/inlay_hint.rs index 4c2dc9e..ba7b4f7 100644 --- a/src/decoration/inlay_hint.rs +++ b/src/decoration/inlay_hint.rs @@ -6,6 +6,7 @@ use tower_lsp::{ lsp_types::{InlayHint, InlayHintLabel, InlayHintLabelPart, Position, Uri}, Client, }; +use tracing::error; use crate::config::GLOBAL_CONFIG; @@ -146,7 +147,9 @@ impl InlayHintDecoration { inlay_hint_decoration_state::update_range(&state, &uri, &id, range); } } - client.inlay_hint_refresh().await.unwrap(); + if let Err(e) = client.inlay_hint_refresh().await { + error!("inlay hint refresh error: {}", e); + } } }); render_tx diff --git a/src/main.rs b/src/main.rs index 6728401..9ec57be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,23 +80,6 @@ impl LanguageServer for CargoAppraiser { file_operations: None, }), inlay_hint_provider: Some(OneOf::Left(true)), - diagnostic_provider: Some(DiagnosticServerCapabilities::RegistrationOptions( - DiagnosticRegistrationOptions { - text_document_registration_options: TextDocumentRegistrationOptions { - document_selector: Some(vec![DocumentFilter { - language: Some("toml".to_string()), - pattern: Some("**/Cargo.toml".to_string()), - scheme: None, - }]), - }, - diagnostic_options: DiagnosticOptions { - workspace_diagnostics: false, - inter_file_dependencies: false, - ..Default::default() - }, - ..Default::default() - }, - )), ..Default::default() }, ..Default::default() @@ -107,17 +90,6 @@ impl LanguageServer for CargoAppraiser { info!("cargo-appraiser server initialized!"); } - async fn diagnostic( - &self, - _: DocumentDiagnosticParams, - ) -> Result { - Ok(DocumentDiagnosticReportResult::Partial( - DocumentDiagnosticReportPartialResult { - related_documents: None, - }, - )) - } - async fn goto_definition( &self, params: GotoDefinitionParams,