aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/nameres.rs
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2020-11-26 19:09:54 +0000
committerJonas Schievink <[email protected]>2020-11-27 12:50:22 +0000
commit0432aa0ed7be3f41d41928499abc688a956214cf (patch)
tree64df76e5182412d9a95bc5e63ef3b1db03a5d430 /crates/hir_def/src/nameres.rs
parent1b2652097183b0a285891c02eea8a7d2af03e4b3 (diff)
Publish diagnostics for macro expansion errors
Diffstat (limited to 'crates/hir_def/src/nameres.rs')
-rw-r--r--crates/hir_def/src/nameres.rs52
1 files changed, 50 insertions, 2 deletions
diff --git a/crates/hir_def/src/nameres.rs b/crates/hir_def/src/nameres.rs
index 202a7dcb6..3d65a46bf 100644
--- a/crates/hir_def/src/nameres.rs
+++ b/crates/hir_def/src/nameres.rs
@@ -286,8 +286,8 @@ mod diagnostics {
286 use cfg::{CfgExpr, CfgOptions}; 286 use cfg::{CfgExpr, CfgOptions};
287 use hir_expand::diagnostics::DiagnosticSink; 287 use hir_expand::diagnostics::DiagnosticSink;
288 use hir_expand::hygiene::Hygiene; 288 use hir_expand::hygiene::Hygiene;
289 use hir_expand::InFile; 289 use hir_expand::{InFile, MacroCallKind};
290 use syntax::{ast, AstPtr}; 290 use syntax::{ast, AstPtr, SyntaxNodePtr};
291 291
292 use crate::path::ModPath; 292 use crate::path::ModPath;
293 use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId}; 293 use crate::{db::DefDatabase, diagnostics::*, nameres::LocalModuleId, AstId};
@@ -301,6 +301,10 @@ mod diagnostics {
301 UnresolvedImport { ast: AstId<ast::Use>, index: usize }, 301 UnresolvedImport { ast: AstId<ast::Use>, index: usize },
302 302
303 UnconfiguredCode { ast: AstId<ast::Item>, cfg: CfgExpr, opts: CfgOptions }, 303 UnconfiguredCode { ast: AstId<ast::Item>, cfg: CfgExpr, opts: CfgOptions },
304
305 UnresolvedProcMacro { ast: MacroCallKind },
306
307 MacroError { ast: MacroCallKind, message: String },
304 } 308 }
305 309
306 #[derive(Debug, PartialEq, Eq)] 310 #[derive(Debug, PartialEq, Eq)]
@@ -348,6 +352,18 @@ mod diagnostics {
348 Self { in_module: container, kind: DiagnosticKind::UnconfiguredCode { ast, cfg, opts } } 352 Self { in_module: container, kind: DiagnosticKind::UnconfiguredCode { ast, cfg, opts } }
349 } 353 }
350 354
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
351 pub(super) fn add_to( 367 pub(super) fn add_to(
352 &self, 368 &self,
353 db: &dyn DefDatabase, 369 db: &dyn DefDatabase,
@@ -407,6 +423,38 @@ mod diagnostics {
407 opts: opts.clone(), 423 opts: opts.clone(),
408 }); 424 });
409 } 425 }
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 }
410 } 458 }
411 } 459 }
412 } 460 }