From c1a2955b505e79f20fa97f1e9846592cfe58e06d Mon Sep 17 00:00:00 2001 From: Lukas Wirth <lukastw97@gmail.com> Date: Wed, 18 Dec 2024 15:14:23 +0100 Subject: [PATCH] internal: Set `result_id` for pull diagnostics --- crates/rust-analyzer/src/handlers/request.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/crates/rust-analyzer/src/handlers/request.rs b/crates/rust-analyzer/src/handlers/request.rs index fa78be5cb6..277d3db529 100644 --- a/crates/rust-analyzer/src/handlers/request.rs +++ b/crates/rust-analyzer/src/handlers/request.rs @@ -481,27 +481,28 @@ pub(crate) fn handle_document_diagnostics( snap: GlobalStateSnapshot, params: lsp_types::DocumentDiagnosticParams, ) -> anyhow::Result<lsp_types::DocumentDiagnosticReportResult> { - const EMPTY: lsp_types::DocumentDiagnosticReportResult = + let empty = || { lsp_types::DocumentDiagnosticReportResult::Report( lsp_types::DocumentDiagnosticReport::Full( lsp_types::RelatedFullDocumentDiagnosticReport { related_documents: None, full_document_diagnostic_report: lsp_types::FullDocumentDiagnosticReport { - result_id: None, + result_id: Some("rust-analyzer".to_owned()), items: vec![], }, }, ), - ); + ) + }; let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?; let source_root = snap.analysis.source_root_id(file_id)?; if !snap.analysis.is_local_source_root(source_root)? { - return Ok(EMPTY); + return Ok(empty()); } let config = snap.config.diagnostics(Some(source_root)); if !config.enabled { - return Ok(EMPTY); + return Ok(empty()); } let line_index = snap.file_line_index(file_id)?; let supports_related = snap.config.text_document_diagnostic_related_document_support(); @@ -529,7 +530,7 @@ pub(crate) fn handle_document_diagnostics( Ok(lsp_types::DocumentDiagnosticReportResult::Report( lsp_types::DocumentDiagnosticReport::Full(lsp_types::RelatedFullDocumentDiagnosticReport { full_document_diagnostic_report: lsp_types::FullDocumentDiagnosticReport { - result_id: None, + result_id: Some("rust-analyzer".to_owned()), items: diagnostics.collect(), }, related_documents: related_documents.is_empty().not().then(|| { @@ -539,7 +540,10 @@ pub(crate) fn handle_document_diagnostics( ( to_proto::url(&snap, id), lsp_types::DocumentDiagnosticReportKind::Full( - lsp_types::FullDocumentDiagnosticReport { result_id: None, items }, + lsp_types::FullDocumentDiagnosticReport { + result_id: Some("rust-analyzer".to_owned()), + items, + }, ), ) })