Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1613548

Browse files
committed
Don't compute diagnostics for non local files
1 parent c5a1bd9 commit 1613548

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/dispatch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ impl RequestDispatcher<'_> {
121121
}
122122

123123
/// Dispatches a non-latency-sensitive request onto the thread pool. When the VFS is marked not
124-
/// ready this will return a default constructed [`R::Result`].
125-
pub(crate) fn on_or<const ALLOW_RETRYING: bool, R>(
124+
/// ready this will return a `default` constructed [`R::Result`].
125+
pub(crate) fn on_with<const ALLOW_RETRYING: bool, R>(
126126
&mut self,
127127
f: fn(GlobalStateSnapshot, R::Params) -> anyhow::Result<R::Result>,
128128
default: impl FnOnce() -> R::Result,

src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,8 @@ pub(crate) fn handle_document_diagnostics(
479479
snap: GlobalStateSnapshot,
480480
params: lsp_types::DocumentDiagnosticParams,
481481
) -> anyhow::Result<lsp_types::DocumentDiagnosticReportResult> {
482-
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
483-
let source_root = snap.analysis.source_root_id(file_id)?;
484-
let line_index = snap.file_line_index(file_id)?;
485-
let config = snap.config.diagnostics(Some(source_root));
486-
if !config.enabled {
487-
return Ok(lsp_types::DocumentDiagnosticReportResult::Report(
482+
const EMPTY: lsp_types::DocumentDiagnosticReportResult =
483+
lsp_types::DocumentDiagnosticReportResult::Report(
488484
lsp_types::DocumentDiagnosticReport::Full(
489485
lsp_types::RelatedFullDocumentDiagnosticReport {
490486
related_documents: None,
@@ -494,8 +490,18 @@ pub(crate) fn handle_document_diagnostics(
494490
},
495491
},
496492
),
497-
));
493+
);
494+
495+
let file_id = from_proto::file_id(&snap, &params.text_document.uri)?;
496+
let source_root = snap.analysis.source_root_id(file_id)?;
497+
if !snap.analysis.is_local_source_root(source_root)? {
498+
return Ok(EMPTY);
499+
}
500+
let config = snap.config.diagnostics(Some(source_root));
501+
if !config.enabled {
502+
return Ok(EMPTY);
498503
}
504+
let line_index = snap.file_line_index(file_id)?;
499505
let supports_related = snap.config.text_document_diagnostic_related_document_support();
500506

501507
let mut related_documents = FxHashMap::default();

src/tools/rust-analyzer/crates/rust-analyzer/src/main_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ impl GlobalState {
10921092
.on_latency_sensitive::<NO_RETRY, lsp_request::SemanticTokensRangeRequest>(handlers::handle_semantic_tokens_range)
10931093
// FIXME: Some of these NO_RETRY could be retries if the file they are interested didn't change.
10941094
// All other request handlers
1095-
.on_or::<NO_RETRY, lsp_request::DocumentDiagnosticRequest>(handlers::handle_document_diagnostics, || lsp_types::DocumentDiagnosticReportResult::Report(
1095+
.on_with::<NO_RETRY, lsp_request::DocumentDiagnosticRequest>(handlers::handle_document_diagnostics, || lsp_types::DocumentDiagnosticReportResult::Report(
10961096
lsp_types::DocumentDiagnosticReport::Full(
10971097
lsp_types::RelatedFullDocumentDiagnosticReport {
10981098
related_documents: None,

0 commit comments

Comments
 (0)