diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 54b4bcf7c36..3b322bd525e 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -665,21 +665,27 @@ fn highlight_name_ref_by_syntax( } } PATH_SEGMENT => { + let name_based_fallback = || { + if name.text().chars().next().unwrap_or_default().is_uppercase() { + SymbolKind::Struct.into() + } else { + SymbolKind::Module.into() + } + }; let path = match parent.parent().and_then(ast::Path::cast) { Some(it) => it, - _ => return default.into(), + _ => return name_based_fallback(), }; - let expr = match path.syntax().parent().and_then(ast::PathExpr::cast) { - Some(it) => it, - _ => { - // within path, decide whether it is module or adt by checking for uppercase name - return if name.text().chars().next().unwrap_or_default().is_uppercase() { - SymbolKind::Struct - } else { - SymbolKind::Module + let expr = match path.syntax().parent() { + Some(parent) => match_ast! { + match parent { + ast::PathExpr(path) => path, + ast::MacroCall(_) => return SymbolKind::Macro.into(), + _ => return name_based_fallback(), } - .into(); - } + }, + // within path, decide whether it is module or adt by checking for uppercase name + None => return name_based_fallback(), }; let parent = match expr.syntax().parent() { Some(it) => it, diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html index a3f3b4d6b82..7dae4a1a14d 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -89,7 +89,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// let foo = Foo::new(); /// /// // calls bar on foo - /// assert!(foo.bar()); + /// assert!(foo.bar()); /// /// let bar = foo.bar || Foo::bar; /// @@ -149,7 +149,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// #[cfg_attr(feature = "alloc", doc = "```rust")] #[cfg_attr(not(feature = "alloc"), doc = "```ignore")] -/// let _ = example(&alloc::vec![1, 2, 3]); +/// let _ = example(&alloc::vec![1, 2, 3]); /// ``` pub fn mix_and_match() {}