Merge pull request #18717 from Veykril/push-pomxnvxotwlr

internal: Set `result_id` for pull diagnostics
This commit is contained in:
Lukas Wirth 2024-12-19 15:38:32 +00:00 committed by GitHub
commit fe027d79d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -481,27 +481,28 @@ pub(crate) fn handle_document_diagnostics(
snap: GlobalStateSnapshot, snap: GlobalStateSnapshot,
params: lsp_types::DocumentDiagnosticParams, params: lsp_types::DocumentDiagnosticParams,
) -> anyhow::Result<lsp_types::DocumentDiagnosticReportResult> { ) -> anyhow::Result<lsp_types::DocumentDiagnosticReportResult> {
const EMPTY: lsp_types::DocumentDiagnosticReportResult = let empty = || {
lsp_types::DocumentDiagnosticReportResult::Report( lsp_types::DocumentDiagnosticReportResult::Report(
lsp_types::DocumentDiagnosticReport::Full( lsp_types::DocumentDiagnosticReport::Full(
lsp_types::RelatedFullDocumentDiagnosticReport { lsp_types::RelatedFullDocumentDiagnosticReport {
related_documents: None, related_documents: None,
full_document_diagnostic_report: lsp_types::FullDocumentDiagnosticReport { full_document_diagnostic_report: lsp_types::FullDocumentDiagnosticReport {
result_id: None, result_id: Some("rust-analyzer".to_owned()),
items: vec![], items: vec![],
}, },
}, },
), ),
); )
};
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?; let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
let source_root = snap.analysis.source_root_id(file_id)?; let source_root = snap.analysis.source_root_id(file_id)?;
if !snap.analysis.is_local_source_root(source_root)? { if !snap.analysis.is_local_source_root(source_root)? {
return Ok(EMPTY); return Ok(empty());
} }
let config = snap.config.diagnostics(Some(source_root)); let config = snap.config.diagnostics(Some(source_root));
if !config.enabled { if !config.enabled {
return Ok(EMPTY); return Ok(empty());
} }
let line_index = snap.file_line_index(file_id)?; let line_index = snap.file_line_index(file_id)?;
let supports_related = snap.config.text_document_diagnostic_related_document_support(); 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( Ok(lsp_types::DocumentDiagnosticReportResult::Report(
lsp_types::DocumentDiagnosticReport::Full(lsp_types::RelatedFullDocumentDiagnosticReport { lsp_types::DocumentDiagnosticReport::Full(lsp_types::RelatedFullDocumentDiagnosticReport {
full_document_diagnostic_report: lsp_types::FullDocumentDiagnosticReport { full_document_diagnostic_report: lsp_types::FullDocumentDiagnosticReport {
result_id: None, result_id: Some("rust-analyzer".to_owned()),
items: diagnostics.collect(), items: diagnostics.collect(),
}, },
related_documents: related_documents.is_empty().not().then(|| { related_documents: related_documents.is_empty().not().then(|| {
@ -539,7 +540,10 @@ pub(crate) fn handle_document_diagnostics(
( (
to_proto::url(&snap, id), to_proto::url(&snap, id),
lsp_types::DocumentDiagnosticReportKind::Full( lsp_types::DocumentDiagnosticReportKind::Full(
lsp_types::FullDocumentDiagnosticReport { result_id: None, items }, lsp_types::FullDocumentDiagnosticReport {
result_id: Some("rust-analyzer".to_owned()),
items,
},
), ),
) )
}) })