diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index c6e11b9cbd..d580b3001c 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -703,7 +703,24 @@ fn highlight_name_ref_by_syntax( }; match parent.kind() { - EXTERN_CRATE => HlTag::Symbol(SymbolKind::Module).into(), + EXTERN_CRATE => { + let mut h: Highlight = HlTag::Symbol(SymbolKind::Module).into(); + let is_crate_root = if let Some(extern_crate) = ast::ExternCrate::cast(parent.clone()) { + if let Some(first_segment) = extern_crate.name_ref() { + first_segment.syntax().text() == name.syntax().text() + } else { + false + } + } else { + false + }; + + if is_crate_root { + h |= HlMod::CrateRoot; + } + + h | HlMod::Library + }, METHOD_CALL_EXPR => ast::MethodCallExpr::cast(parent) .and_then(|it| highlight_method_call(sema, krate, &it, edition)) .unwrap_or_else(|| SymbolKind::Method.into()), 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 2f7bc65d14..9a55f7d01b 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -51,7 +51,13 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd //! ``` //! ```rust -//! extern crate Krate; +//! extern crate self; +//! extern crate std; +//! extern crate core; +//! extern crate alloc; +//! extern crate proc_macro; +//! extern crate test; +//! extern crate Krate; //! ``` mod outline_module; diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index ad3d476391..364d090924 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -723,6 +723,12 @@ fn test_highlight_doc_comment() { //! ``` //! ```rust +//! extern crate self; +//! extern crate std; +//! extern crate core; +//! extern crate alloc; +//! extern crate proc_macro; +//! extern crate test; //! extern crate Krate; //! ``` mod outline_module;