Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-diagnostics/src/lib.rs')
-rw-r--r--crates/ide-diagnostics/src/lib.rs49
1 files changed, 27 insertions, 22 deletions
diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs
index e15d349578..5ce3336eb4 100644
--- a/crates/ide-diagnostics/src/lib.rs
+++ b/crates/ide-diagnostics/src/lib.rs
@@ -85,9 +85,10 @@ use hir::{
db::ExpandDatabase, diagnostics::AnyDiagnostic, Crate, DisplayTarget, HirFileId, InFile,
Semantics,
};
+use ide_db::base_db::salsa::AsDynDatabase;
use ide_db::{
assists::{Assist, AssistId, AssistKind, AssistResolveStrategy},
- base_db::{ReleaseChannel, SourceDatabase},
+ base_db::{ReleaseChannel, RootQueryDb as _},
generated::lints::{Lint, LintGroup, CLIPPY_LINT_GROUPS, DEFAULT_LINTS, DEFAULT_LINT_GROUPS},
imports::insert_use::InsertUseConfig,
label::Label,
@@ -319,12 +320,17 @@ pub fn syntax_diagnostics(
}
let sema = Semantics::new(db);
- let file_id = sema
+ let editioned_file_id = sema
.attach_first_edition(file_id)
.unwrap_or_else(|| EditionedFileId::current_edition(file_id));
+ let (file_id, _) = editioned_file_id.unpack();
+
+ let editioned_file_id_wrapper =
+ ide_db::base_db::EditionedFileId::new(db.as_dyn_database(), editioned_file_id);
+
// [#3434] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
- db.parse_errors(file_id)
+ db.parse_errors(editioned_file_id_wrapper)
.as_deref()
.into_iter()
.flatten()
@@ -333,7 +339,7 @@ pub fn syntax_diagnostics(
Diagnostic::new(
DiagnosticCode::SyntaxError,
format!("Syntax Error: {err}"),
- FileRange { file_id: file_id.into(), range: err.range() },
+ FileRange { file_id, range: err.range() },
)
})
.collect()
@@ -349,26 +355,31 @@ pub fn semantic_diagnostics(
) -> Vec<Diagnostic> {
let _p = tracing::info_span!("semantic_diagnostics").entered();
let sema = Semantics::new(db);
- let file_id = sema
+ let editioned_file_id = sema
.attach_first_edition(file_id)
.unwrap_or_else(|| EditionedFileId::current_edition(file_id));
+
+ let (file_id, edition) = editioned_file_id.unpack();
+ let editioned_file_id_wrapper =
+ ide_db::base_db::EditionedFileId::new(db.as_dyn_database(), editioned_file_id);
+
let mut res = Vec::new();
- let parse = sema.parse(file_id);
+ let parse = sema.parse(editioned_file_id_wrapper);
// FIXME: This iterates the entire file which is a rather expensive operation.
// We should implement these differently in some form?
// Salsa caching + incremental re-parse would be better here
for node in parse.syntax().descendants() {
- handlers::useless_braces::useless_braces(&mut res, file_id, &node);
- handlers::field_shorthand::field_shorthand(&mut res, file_id, &node);
+ handlers::useless_braces::useless_braces(&mut res, editioned_file_id, &node);
+ handlers::field_shorthand::field_shorthand(&mut res, editioned_file_id, &node);
handlers::json_is_not_rust::json_in_items(
&sema,
&mut res,
- file_id,
+ editioned_file_id,
&node,
config,
- file_id.edition(),
+ edition,
);
}
@@ -382,25 +393,19 @@ pub fn semantic_diagnostics(
(*db.crate_graph().crates_in_topological_order().last().unwrap()).into()
});
let display_target = krate.to_display_target(db);
- let ctx = DiagnosticsContext {
- config,
- sema,
- resolve,
- edition: file_id.edition(),
- is_nightly,
- display_target,
- };
+ let ctx = DiagnosticsContext { config, sema, resolve, edition, is_nightly, display_target };
let mut diags = Vec::new();
match module {
// A bunch of parse errors in a file indicate some bigger structural parse changes in the
// file, so we skip semantic diagnostics so we can show these faster.
Some(m) => {
- if db.parse_errors(file_id).as_deref().is_none_or(|es| es.len() < 16) {
+ if db.parse_errors(editioned_file_id_wrapper).as_deref().is_none_or(|es| es.len() < 16)
+ {
m.diagnostics(db, &mut diags, config.style_lints);
}
}
- None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, file_id.file_id()),
+ None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, editioned_file_id.file_id()),
}
for diag in diags {
@@ -517,7 +522,7 @@ pub fn semantic_diagnostics(
&mut FxHashMap::default(),
&mut lints,
&mut Vec::new(),
- file_id.edition(),
+ editioned_file_id.edition(),
);
res.retain(|d| d.severity != Severity::Allow);
@@ -559,7 +564,7 @@ fn handle_diag_from_macros(
let span_map = sema.db.expansion_span_map(macro_file);
let mut spans = span_map.spans_for_range(node.text_range());
if spans.any(|span| {
- sema.db.lookup_intern_syntax_context(span.ctx).outer_expn.is_some_and(|expansion| {
+ span.ctx.outer_expn(sema.db).is_some_and(|expansion| {
let macro_call =
sema.db.lookup_intern_macro_call(expansion.as_macro_file().macro_call_id);
// We don't want to show diagnostics for non-local macros at all, but proc macros authors