mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: refactor unresolved import diagnostic
This commit is contained in:
parent
39f190b72c
commit
6d104de15a
6 changed files with 127 additions and 92 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
mod unresolved_module;
|
||||
mod unresolved_extern_crate;
|
||||
mod unresolved_import;
|
||||
mod missing_fields;
|
||||
|
||||
mod fixes;
|
||||
|
@ -43,17 +44,39 @@ pub struct Diagnostic {
|
|||
pub fixes: Option<Vec<Assist>>,
|
||||
pub unused: bool,
|
||||
pub code: Option<DiagnosticCode>,
|
||||
pub experimental: bool,
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
fn new(code: &'static str, message: impl Into<String>, range: TextRange) -> Diagnostic {
|
||||
let message = message.into();
|
||||
let code = Some(DiagnosticCode(code));
|
||||
Self { message, range, severity: Severity::Error, fixes: None, unused: false, code }
|
||||
Self {
|
||||
message,
|
||||
range,
|
||||
severity: Severity::Error,
|
||||
fixes: None,
|
||||
unused: false,
|
||||
code,
|
||||
experimental: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn experimental(mut self) -> Diagnostic {
|
||||
self.experimental = true;
|
||||
self
|
||||
}
|
||||
|
||||
fn error(range: TextRange, message: String) -> Self {
|
||||
Self { message, range, severity: Severity::Error, fixes: None, unused: false, code: None }
|
||||
Self {
|
||||
message,
|
||||
range,
|
||||
severity: Severity::Error,
|
||||
fixes: None,
|
||||
unused: false,
|
||||
code: None,
|
||||
experimental: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn hint(range: TextRange, message: String) -> Self {
|
||||
|
@ -64,6 +87,7 @@ impl Diagnostic {
|
|||
fixes: None,
|
||||
unused: false,
|
||||
code: None,
|
||||
experimental: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,6 +258,7 @@ pub(crate) fn diagnostics(
|
|||
let d = match diag {
|
||||
AnyDiagnostic::UnresolvedModule(d) => unresolved_module::unresolved_module(&ctx, &d),
|
||||
AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
|
||||
AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
|
||||
AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
|
||||
};
|
||||
if let Some(code) = d.code {
|
||||
|
@ -241,6 +266,9 @@ pub(crate) fn diagnostics(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
if ctx.config.disable_experimental && d.experimental {
|
||||
continue;
|
||||
}
|
||||
res.push(d)
|
||||
}
|
||||
|
||||
|
@ -462,33 +490,6 @@ foo::bar!(92);
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unresolved_import_in_use_tree() {
|
||||
// Only the relevant part of a nested `use` item should be highlighted.
|
||||
check_diagnostics(
|
||||
r#"
|
||||
use does_exist::{Exists, DoesntExist};
|
||||
//^^^^^^^^^^^ unresolved import
|
||||
|
||||
use {does_not_exist::*, does_exist};
|
||||
//^^^^^^^^^^^^^^^^^ unresolved import
|
||||
|
||||
use does_not_exist::{
|
||||
a,
|
||||
//^ unresolved import
|
||||
b,
|
||||
//^ unresolved import
|
||||
c,
|
||||
//^ unresolved import
|
||||
};
|
||||
|
||||
mod does_exist {
|
||||
pub struct Exists;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn range_mapping_out_of_macros() {
|
||||
// FIXME: this is very wrong, but somewhat tricky to fix.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue