mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
internal: refactor unimplemented builtin macro diagnostic
This commit is contained in:
parent
dec207f56a
commit
d3621eeb02
4 changed files with 33 additions and 31 deletions
|
@ -32,14 +32,15 @@ macro_rules! diagnostics {
|
||||||
}
|
}
|
||||||
|
|
||||||
diagnostics![
|
diagnostics![
|
||||||
UnresolvedModule,
|
InactiveCode,
|
||||||
|
MacroError,
|
||||||
|
MissingFields,
|
||||||
|
UnimplementedBuiltinMacro,
|
||||||
UnresolvedExternCrate,
|
UnresolvedExternCrate,
|
||||||
UnresolvedImport,
|
UnresolvedImport,
|
||||||
UnresolvedMacroCall,
|
UnresolvedMacroCall,
|
||||||
|
UnresolvedModule,
|
||||||
UnresolvedProcMacro,
|
UnresolvedProcMacro,
|
||||||
MacroError,
|
|
||||||
MissingFields,
|
|
||||||
InactiveCode,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -88,26 +89,7 @@ pub struct MacroError {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct UnimplementedBuiltinMacro {
|
pub struct UnimplementedBuiltinMacro {
|
||||||
pub file: HirFileId,
|
pub node: InFile<SyntaxNodePtr>,
|
||||||
pub node: SyntaxNodePtr,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Diagnostic for UnimplementedBuiltinMacro {
|
|
||||||
fn code(&self) -> DiagnosticCode {
|
|
||||||
DiagnosticCode("unimplemented-builtin-macro")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn message(&self) -> String {
|
|
||||||
"unimplemented built-in macro".to_string()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
|
||||||
InFile::new(self.file, self.node.clone())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Diagnostic: no-such-field
|
// Diagnostic: no-such-field
|
||||||
|
|
|
@ -606,8 +606,12 @@ impl Module {
|
||||||
let node = ast.to_node(db.upcast());
|
let node = ast.to_node(db.upcast());
|
||||||
// Must have a name, otherwise we wouldn't emit it.
|
// Must have a name, otherwise we wouldn't emit it.
|
||||||
let name = node.name().expect("unimplemented builtin macro with no name");
|
let name = node.name().expect("unimplemented builtin macro with no name");
|
||||||
let ptr = SyntaxNodePtr::from(AstPtr::new(&name));
|
acc.push(
|
||||||
sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr });
|
UnimplementedBuiltinMacro {
|
||||||
|
node: ast.with_value(SyntaxNodePtr::from(AstPtr::new(&name))),
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ mod unresolved_extern_crate;
|
||||||
mod unresolved_import;
|
mod unresolved_import;
|
||||||
mod unresolved_macro_call;
|
mod unresolved_macro_call;
|
||||||
mod unresolved_proc_macro;
|
mod unresolved_proc_macro;
|
||||||
|
mod unimplemented_builtin_macro;
|
||||||
mod macro_error;
|
mod macro_error;
|
||||||
mod inactive_code;
|
mod inactive_code;
|
||||||
mod missing_fields;
|
mod missing_fields;
|
||||||
|
@ -185,11 +186,6 @@ pub(crate) fn diagnostics(
|
||||||
.with_code(Some(d.code())),
|
.with_code(Some(d.code())),
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| {
|
|
||||||
let display_range = sema.diagnostics_display_range(d.display_source()).range;
|
|
||||||
res.borrow_mut()
|
|
||||||
.push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code())));
|
|
||||||
})
|
|
||||||
// Only collect experimental diagnostics when they're enabled.
|
// Only collect experimental diagnostics when they're enabled.
|
||||||
.filter(|diag| !(diag.is_experimental() && config.disable_experimental))
|
.filter(|diag| !(diag.is_experimental() && config.disable_experimental))
|
||||||
.filter(|diag| !config.disabled.contains(diag.code().as_str()));
|
.filter(|diag| !config.disabled.contains(diag.code().as_str()));
|
||||||
|
@ -229,6 +225,7 @@ pub(crate) fn diagnostics(
|
||||||
AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
|
AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
|
||||||
AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d),
|
AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d),
|
||||||
AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d),
|
AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d),
|
||||||
|
AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
|
||||||
AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
|
AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
|
||||||
AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d),
|
AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d),
|
||||||
|
|
||||||
|
|
19
crates/ide/src/diagnostics/unimplemented_builtin_macro.rs
Normal file
19
crates/ide/src/diagnostics/unimplemented_builtin_macro.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
use crate::{
|
||||||
|
diagnostics::{Diagnostic, DiagnosticsContext},
|
||||||
|
Severity,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Diagnostic: unimplemented-builtin-macro
|
||||||
|
//
|
||||||
|
// This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer
|
||||||
|
pub(super) fn unimplemented_builtin_macro(
|
||||||
|
ctx: &DiagnosticsContext<'_>,
|
||||||
|
d: &hir::UnimplementedBuiltinMacro,
|
||||||
|
) -> Diagnostic {
|
||||||
|
Diagnostic::new(
|
||||||
|
"unimplemented-builtin-macro",
|
||||||
|
"unimplemented built-in macro".to_string(),
|
||||||
|
ctx.sema.diagnostics_display_range(d.node.clone()).range,
|
||||||
|
)
|
||||||
|
.severity(Severity::WeakWarning)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue