internal: refactor unresolved macro call diagnostic

This commit is contained in:
Aleksey Kladov
2021-06-13 17:06:36 +03:00
parent 6d104de15a
commit fa9ed4e0ce
5 changed files with 94 additions and 95 deletions

View File

@@ -17,7 +17,7 @@ pub use crate::diagnostics_sink::{
};
macro_rules! diagnostics {
($($diag:ident),*) => {
($($diag:ident,)*) => {
pub enum AnyDiagnostic {$(
$diag(Box<$diag>),
)*}
@@ -32,7 +32,13 @@ macro_rules! diagnostics {
};
}
diagnostics![UnresolvedModule, UnresolvedExternCrate, UnresolvedImport, MissingFields];
diagnostics![
UnresolvedModule,
UnresolvedExternCrate,
UnresolvedImport,
UnresolvedMacroCall,
MissingFields,
];
#[derive(Debug)]
pub struct UnresolvedModule {
@@ -50,35 +56,12 @@ pub struct UnresolvedImport {
pub decl: InFile<AstPtr<ast::UseTree>>,
}
// Diagnostic: unresolved-macro-call
//
// This diagnostic is triggered if rust-analyzer is unable to resolve the path to a
// macro in a macro invocation.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct UnresolvedMacroCall {
pub file: HirFileId,
pub node: AstPtr<ast::MacroCall>,
pub macro_call: InFile<AstPtr<ast::MacroCall>>,
pub path: ModPath,
}
impl Diagnostic for UnresolvedMacroCall {
fn code(&self) -> DiagnosticCode {
DiagnosticCode("unresolved-macro-call")
}
fn message(&self) -> String {
format!("unresolved macro `{}!`", self.path)
}
fn display_source(&self) -> InFile<SyntaxNodePtr> {
InFile::new(self.file, self.node.clone().into())
}
fn as_any(&self) -> &(dyn Any + Send + 'static) {
self
}
fn is_experimental(&self) -> bool {
true
}
}
// Diagnostic: inactive-code
//
// This diagnostic is shown for code with inactive `#[cfg]` attributes.