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.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/ide-diagnostics/src/lib.rs b/crates/ide-diagnostics/src/lib.rs
index 0c6953419f..09c9f8eab0 100644
--- a/crates/ide-diagnostics/src/lib.rs
+++ b/crates/ide-diagnostics/src/lib.rs
@@ -96,7 +96,7 @@ use hir::{
use ide_db::{
FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, Severity, SnippetCap,
assists::{Assist, AssistId, AssistResolveStrategy, ExprFillDefaultMode},
- base_db::{ReleaseChannel, RootQueryDb as _},
+ base_db::{ReleaseChannel, all_crates, toolchain_channel},
generated::lints::{CLIPPY_LINT_GROUPS, DEFAULT_LINT_GROUPS, DEFAULT_LINTS, Lint, LintGroup},
imports::insert_use::InsertUseConfig,
label::Label,
@@ -285,6 +285,12 @@ struct DiagnosticsContext<'a> {
is_nightly: bool,
}
+impl<'a> DiagnosticsContext<'a> {
+ fn db(&self) -> &'a RootDatabase {
+ self.sema.db
+ }
+}
+
/// Request parser level diagnostics for the given [`FileId`].
pub fn syntax_diagnostics(
db: &RootDatabase,
@@ -303,7 +309,8 @@ pub fn syntax_diagnostics(
let (file_id, _) = editioned_file_id.unpack(db);
// [#3434] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
- db.parse_errors(editioned_file_id)
+ editioned_file_id
+ .parse_errors(db)
.into_iter()
.flatten()
.take(128)
@@ -353,14 +360,14 @@ pub fn semantic_diagnostics(
let module = sema.file_to_module_def(file_id);
let is_nightly = matches!(
- module.and_then(|m| db.toolchain_channel(m.krate(db).into())),
+ module.and_then(|m| toolchain_channel(db, m.krate(db).into())),
Some(ReleaseChannel::Nightly) | None
);
let krate = match module {
Some(module) => module.krate(db),
None => {
- match db.all_crates().last() {
+ match all_crates(db).last() {
Some(last) => (*last).into(),
// short-circuit, return an empty vec of diagnostics
None => return vec![],
@@ -375,7 +382,7 @@ pub fn semantic_diagnostics(
// 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(editioned_file_id).is_none_or(|es| es.len() < 16) {
+ if editioned_file_id.parse_errors(db).is_none_or(|es| es.len() < 16) {
m.diagnostics(db, &mut diags, config.style_lints);
}
}
@@ -430,7 +437,10 @@ pub fn semantic_diagnostics(
AnyDiagnostic::TraitImplRedundantAssocItems(d) => handlers::trait_impl_redundant_assoc_item::trait_impl_redundant_assoc_item(&ctx, &d),
AnyDiagnostic::TraitImplOrphan(d) => handlers::trait_impl_orphan::trait_impl_orphan(&ctx, &d),
AnyDiagnostic::TypedHole(d) => handlers::typed_hole::typed_hole(&ctx, &d),
- AnyDiagnostic::TypeMismatch(d) => handlers::type_mismatch::type_mismatch(&ctx, &d),
+ AnyDiagnostic::TypeMismatch(d) => match handlers::type_mismatch::type_mismatch(&ctx, &d) {
+ Some(diag) => diag,
+ None => continue,
+ },
AnyDiagnostic::UndeclaredLabel(d) => handlers::undeclared_label::undeclared_label(&ctx, &d),
AnyDiagnostic::UnimplementedBuiltinMacro(d) => handlers::unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
AnyDiagnostic::UnreachableLabel(d) => handlers::unreachable_label::unreachable_label(&ctx, &d),