@@ -286,8 +286,8 @@ mod diagnostics {
286286 use cfg:: { CfgExpr , CfgOptions } ;
287287 use hir_expand:: diagnostics:: DiagnosticSink ;
288288 use hir_expand:: hygiene:: Hygiene ;
289- use hir_expand:: InFile ;
290- use syntax:: { ast, AstPtr } ;
289+ use hir_expand:: { InFile , MacroCallKind } ;
290+ use syntax:: { ast, AstPtr , SyntaxNodePtr } ;
291291
292292 use crate :: path:: ModPath ;
293293 use crate :: { db:: DefDatabase , diagnostics:: * , nameres:: LocalModuleId , AstId } ;
@@ -301,6 +301,10 @@ mod diagnostics {
301301 UnresolvedImport { ast : AstId < ast:: Use > , index : usize } ,
302302
303303 UnconfiguredCode { ast : AstId < ast:: Item > , cfg : CfgExpr , opts : CfgOptions } ,
304+
305+ UnresolvedProcMacro { ast : MacroCallKind } ,
306+
307+ MacroError { ast : MacroCallKind , message : String } ,
304308 }
305309
306310 #[ derive( Debug , PartialEq , Eq ) ]
@@ -348,6 +352,18 @@ mod diagnostics {
348352 Self { in_module : container, kind : DiagnosticKind :: UnconfiguredCode { ast, cfg, opts } }
349353 }
350354
355+ pub ( super ) fn unresolved_proc_macro ( container : LocalModuleId , ast : MacroCallKind ) -> Self {
356+ Self { in_module : container, kind : DiagnosticKind :: UnresolvedProcMacro { ast } }
357+ }
358+
359+ pub ( super ) fn macro_error (
360+ container : LocalModuleId ,
361+ ast : MacroCallKind ,
362+ message : String ,
363+ ) -> Self {
364+ Self { in_module : container, kind : DiagnosticKind :: MacroError { ast, message } }
365+ }
366+
351367 pub ( super ) fn add_to (
352368 & self ,
353369 db : & dyn DefDatabase ,
@@ -407,6 +423,38 @@ mod diagnostics {
407423 opts : opts. clone ( ) ,
408424 } ) ;
409425 }
426+
427+ DiagnosticKind :: UnresolvedProcMacro { ast } => {
428+ let ( file, ast, name) = match ast {
429+ MacroCallKind :: FnLike ( ast) => {
430+ let node = ast. to_node ( db. upcast ( ) ) ;
431+ ( ast. file_id , SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) , None )
432+ }
433+ MacroCallKind :: Attr ( ast, name) => {
434+ let node = ast. to_node ( db. upcast ( ) ) ;
435+ (
436+ ast. file_id ,
437+ SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) ,
438+ Some ( name. to_string ( ) ) ,
439+ )
440+ }
441+ } ;
442+ sink. push ( UnresolvedProcMacro { file, node : ast, macro_name : name } ) ;
443+ }
444+
445+ DiagnosticKind :: MacroError { ast, message } => {
446+ let ( file, ast) = match ast {
447+ MacroCallKind :: FnLike ( ast) => {
448+ let node = ast. to_node ( db. upcast ( ) ) ;
449+ ( ast. file_id , SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) )
450+ }
451+ MacroCallKind :: Attr ( ast, _) => {
452+ let node = ast. to_node ( db. upcast ( ) ) ;
453+ ( ast. file_id , SyntaxNodePtr :: from ( AstPtr :: new ( & node) ) )
454+ }
455+ } ;
456+ sink. push ( MacroError { file, node : ast, message : message. clone ( ) } ) ;
457+ }
410458 }
411459 }
412460 }
0 commit comments