internal: refactor unimplemented builtin macro diagnostic
This commit is contained in:
parent
dec207f56a
commit
d3621eeb02
@ -32,14 +32,15 @@ fn from(d: $diag) -> AnyDiagnostic {
|
||||
}
|
||||
|
||||
diagnostics![
|
||||
UnresolvedModule,
|
||||
InactiveCode,
|
||||
MacroError,
|
||||
MissingFields,
|
||||
UnimplementedBuiltinMacro,
|
||||
UnresolvedExternCrate,
|
||||
UnresolvedImport,
|
||||
UnresolvedMacroCall,
|
||||
UnresolvedModule,
|
||||
UnresolvedProcMacro,
|
||||
MacroError,
|
||||
MissingFields,
|
||||
InactiveCode,
|
||||
];
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -88,26 +89,7 @@ pub struct MacroError {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UnimplementedBuiltinMacro {
|
||||
pub file: HirFileId,
|
||||
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
|
||||
}
|
||||
pub node: InFile<SyntaxNodePtr>,
|
||||
}
|
||||
|
||||
// Diagnostic: no-such-field
|
||||
|
@ -606,8 +606,12 @@ pub fn diagnostics(
|
||||
let node = ast.to_node(db.upcast());
|
||||
// Must have a name, otherwise we wouldn't emit it.
|
||||
let name = node.name().expect("unimplemented builtin macro with no name");
|
||||
let ptr = SyntaxNodePtr::from(AstPtr::new(&name));
|
||||
sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr });
|
||||
acc.push(
|
||||
UnimplementedBuiltinMacro {
|
||||
node: ast.with_value(SyntaxNodePtr::from(AstPtr::new(&name))),
|
||||
}
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
mod unresolved_import;
|
||||
mod unresolved_macro_call;
|
||||
mod unresolved_proc_macro;
|
||||
mod unimplemented_builtin_macro;
|
||||
mod macro_error;
|
||||
mod inactive_code;
|
||||
mod missing_fields;
|
||||
@ -185,11 +186,6 @@ pub(crate) fn diagnostics(
|
||||
.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.
|
||||
.filter(|diag| !(diag.is_experimental() && config.disable_experimental))
|
||||
.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::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&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::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…
Reference in New Issue
Block a user