diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index c0c2cc78182..cfa674cafa6 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -2028,7 +2028,7 @@ pub struct BuiltinAttr(usize); impl BuiltinAttr { pub(crate) fn by_name(name: &str) -> Option { - // TODO: def maps registered attrs? + // FIXME: def maps registered attrs? hir_def::builtin_attr::find_builtin_attr_idx(name).map(Self) } } @@ -2038,7 +2038,7 @@ pub struct Tool(usize); impl Tool { pub(crate) fn by_name(name: &str) -> Option { - // TODO: def maps registered tools + // FIXME: def maps registered tools hir_def::builtin_attr::TOOL_MODULES.iter().position(|&tool| tool == name).map(Self) } } diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index 8b613fde54d..118f8dd9be0 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -115,6 +115,7 @@ pub struct HlRange { // parameter:: Emitted for non-self function parameters. // property:: Emitted for struct and union fields. // selfKeyword:: Emitted for the self function parameter and self path-specifier. +// tool:: Emitted for tool modules. // typeParameter:: Emitted for type parameters. // unresolvedReference:: Emitted for unresolved references, names that rust-analyzer can't find the definition of. // variable:: Emitted for locals, constants and statics. diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 52e729ee68c..340168a90d0 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -208,22 +208,14 @@ fn node( }, // Highlight references like the definitions they resolve to ast::NameRef(name_ref) => { - if node.ancestors().any(|it| it.kind() == ATTR) { - - // FIXME: We highlight paths in attributes slightly differently to work around this module - // currently not knowing about tool attributes and rustc builtin attributes as - // we do not want to resolve those to functions that may be defined in scope. - highlight_name_ref_in_attr(sema, name_ref) - } else { - highlight_name_ref( - sema, - krate, - bindings_shadow_count, - &mut binding_hash, - syntactic_name_ref_highlighting, - name_ref, - ) - } + highlight_name_ref( + sema, + krate, + bindings_shadow_count, + &mut binding_hash, + syntactic_name_ref_highlighting, + name_ref, + ) }, ast::Lifetime(lifetime) => { match NameClass::classify_lifetime(sema, &lifetime) { @@ -243,28 +235,6 @@ fn node( Some((highlight, binding_hash)) } -fn highlight_name_ref_in_attr(sema: &Semantics, name_ref: ast::NameRef) -> Highlight { - match NameRefClass::classify(sema, &name_ref) { - Some(name_class) => match name_class { - NameRefClass::Definition(Definition::Module(_)) - if name_ref - .syntax() - .ancestors() - .find_map(ast::Path::cast) - .map_or(false, |it| it.parent_path().is_some()) => - { - HlTag::Symbol(SymbolKind::Module) - } - NameRefClass::Definition(Definition::Macro(m)) if m.kind() == hir::MacroKind::Attr => { - HlTag::Symbol(SymbolKind::Macro) - } - _ => HlTag::BuiltinAttr, - }, - None => HlTag::BuiltinAttr, - } - .into() -} - fn highlight_name_ref( sema: &Semantics, krate: Option, @@ -542,8 +512,8 @@ fn highlight_def( h } Definition::Label(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)), - Definition::BuiltinAttr(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)), // FIXME - Definition::Tool(_) => Highlight::new(HlTag::Symbol(SymbolKind::Label)), // FIXME + Definition::BuiltinAttr(_) => Highlight::new(HlTag::Symbol(SymbolKind::BuiltinAttr)), + Definition::Tool(_) => Highlight::new(HlTag::Symbol(SymbolKind::Tool)), }; let famous_defs = FamousDefs(sema, krate); diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index d4dba508344..50f74cdec1b 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -263,8 +263,8 @@ fn module_def_to_hl_tag(def: Definition) -> HlTag { hir::GenericParam::ConstParam(_) => SymbolKind::ConstParam, }, Definition::Label(_) => SymbolKind::Label, - Definition::BuiltinAttr(_) => SymbolKind::Label, // FIXME - Definition::Tool(_) => SymbolKind::Label, // FIXME + Definition::BuiltinAttr(_) => SymbolKind::BuiltinAttr, + Definition::Tool(_) => SymbolKind::Tool, }; HlTag::Symbol(symbol) } diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 92c7fcab76f..a19eee58172 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -20,7 +20,6 @@ pub enum HlTag { Attribute, BoolLiteral, - BuiltinAttr, BuiltinType, ByteLiteral, CharLiteral, @@ -125,30 +124,31 @@ impl HlTag { fn as_str(self) -> &'static str { match self { HlTag::Symbol(symbol) => match symbol { + SymbolKind::BuiltinAttr => "builtin_attr", SymbolKind::Const => "constant", - SymbolKind::Static => "static", + SymbolKind::ConstParam => "const_param", SymbolKind::Enum => "enum", - SymbolKind::Variant => "enum_variant", - SymbolKind::Struct => "struct", - SymbolKind::Union => "union", SymbolKind::Field => "field", - SymbolKind::Module => "module", - SymbolKind::Trait => "trait", SymbolKind::Function => "function", + SymbolKind::Impl => "self_type", + SymbolKind::Label => "label", + SymbolKind::LifetimeParam => "lifetime", + SymbolKind::Local => "variable", + SymbolKind::Macro => "macro", + SymbolKind::Module => "module", + SymbolKind::SelfParam => "self_keyword", + SymbolKind::Static => "static", + SymbolKind::Struct => "struct", + SymbolKind::Tool => "tool", + SymbolKind::Trait => "trait", SymbolKind::TypeAlias => "type_alias", SymbolKind::TypeParam => "type_param", - SymbolKind::ConstParam => "const_param", - SymbolKind::LifetimeParam => "lifetime", - SymbolKind::Macro => "macro", - SymbolKind::Local => "variable", - SymbolKind::Label => "label", + SymbolKind::Union => "union", SymbolKind::ValueParam => "value_param", - SymbolKind::SelfParam => "self_keyword", - SymbolKind::Impl => "self_type", + SymbolKind::Variant => "enum_variant", }, HlTag::Attribute => "attribute", HlTag::BoolLiteral => "bool_literal", - HlTag::BuiltinAttr => "builtin_attr", HlTag::BuiltinType => "builtin_type", HlTag::ByteLiteral => "byte_literal", HlTag::CharLiteral => "char_literal", 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 9c92bd3e742..1e778cc6194 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_doctest.html @@ -72,7 +72,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// # Examples /// /// ``` - /// # #![allow(unused_mut)] + /// # #![allow(unused_mut)] /// let mut foo: Foo = Foo::new(); /// ``` pub const fn new() -> Foo { @@ -143,12 +143,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd /// /// ``` /// loop {} -#[cfg_attr(not(feature = "false"), doc = "loop {}")] -#[doc = "loop {}"] +#[cfg_attr(not(feature = "false"), doc = "loop {}")] +#[doc = "loop {}"] /// ``` /// -#[cfg_attr(feature = "alloc", doc = "```rust")] -#[cfg_attr(not(feature = "alloc"), doc = "```ignore")] +#[cfg_attr(feature = "alloc", doc = "```rust")] +#[cfg_attr(not(feature = "alloc"), doc = "```ignore")] /// let _ = example(&alloc::vec![1, 2, 3]); /// ``` pub fn mix_and_match() {} diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html index 893094b24a4..b44fc817c78 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_strings.html @@ -45,14 +45,14 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd $crate::io::_print($crate::format_args_nl!($($arg)*)); }) } -#[rustc_builtin_macro] -#[macro_export] +#[rustc_builtin_macro] +#[macro_export] macro_rules! format_args {} -#[rustc_builtin_macro] -#[macro_export] +#[rustc_builtin_macro] +#[macro_export] macro_rules! const_format_args {} -#[rustc_builtin_macro] -#[macro_export] +#[rustc_builtin_macro] +#[macro_export] macro_rules! format_args_nl {} mod panic { @@ -77,12 +77,12 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd } } -#[rustc_builtin_macro(std_panic)] -#[macro_export] +#[rustc_builtin_macro(std_panic)] +#[macro_export] macro_rules! panic {} -#[rustc_builtin_macro] +#[rustc_builtin_macro] macro_rules! assert {} -#[rustc_builtin_macro] +#[rustc_builtin_macro] macro_rules! asm {} macro_rules! toho { diff --git a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html index 2b86340efd7..65dfbdf2119 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlight_unsafe.html @@ -54,7 +54,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd unsafe fn unsafe_method(&self) {} } -#[repr(packed)] +#[repr(packed)] struct Packed { a: u16, } diff --git a/crates/ide/src/syntax_highlighting/test_data/highlighting.html b/crates/ide/src/syntax_highlighting/test_data/highlighting.html index d8c9827b5e0..da607b51211 100644 --- a/crates/ide/src/syntax_highlighting/test_data/highlighting.html +++ b/crates/ide/src/syntax_highlighting/test_data/highlighting.html @@ -43,15 +43,15 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
use inner::{self as inner_mod};
 mod inner {}
 
-#[proc_macros::identity]
+#[proc_macros::identity]
 pub mod ops {
-    #[lang = "fn_once"]
+    #[lang = "fn_once"]
     pub trait FnOnce<Args> {}
 
-    #[lang = "fn_mut"]
+    #[lang = "fn_mut"]
     pub trait FnMut<Args>: FnOnce<Args> {}
 
-    #[lang = "fn"]
+    #[lang = "fn"]
     pub trait Fn<Args>: FnMut<Args> {}
 }
 
@@ -86,7 +86,7 @@ proc_macros::mirror! {
     }
 }
 
-#[derive(Copy)]
+#[derive(Copy)]
 struct FooCopy {
     x: u32,
 }
diff --git a/crates/ide_completion/src/item.rs b/crates/ide_completion/src/item.rs
index ebe227d260a..e80a8edd9cf 100644
--- a/crates/ide_completion/src/item.rs
+++ b/crates/ide_completion/src/item.rs
@@ -232,6 +232,7 @@ impl CompletionItemKind {
     pub(crate) fn tag(&self) -> &'static str {
         match self {
             CompletionItemKind::SymbolKind(kind) => match kind {
+                SymbolKind::BuiltinAttr => "ba",
                 SymbolKind::Const => "ct",
                 SymbolKind::ConstParam => "cp",
                 SymbolKind::Enum => "en",
@@ -246,6 +247,7 @@ impl CompletionItemKind {
                 SymbolKind::SelfParam => "sp",
                 SymbolKind::Static => "sc",
                 SymbolKind::Struct => "st",
+                SymbolKind::Tool => "tl",
                 SymbolKind::Trait => "tt",
                 SymbolKind::TypeAlias => "ta",
                 SymbolKind::TypeParam => "tp",
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs
index 1250008984e..6eaea53f5c1 100644
--- a/crates/ide_db/src/lib.rs
+++ b/crates/ide_db/src/lib.rs
@@ -145,6 +145,7 @@ fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc {
 
 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub enum SymbolKind {
+    BuiltinAttr,
     Const,
     ConstParam,
     Enum,
@@ -159,6 +160,7 @@ pub enum SymbolKind {
     SelfParam,
     Static,
     Struct,
+    Tool,
     Trait,
     TypeAlias,
     TypeParam,
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs
index 3117b757285..9d19482bee3 100644
--- a/crates/rust-analyzer/src/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/semantic_tokens.rs
@@ -65,6 +65,7 @@ define_semantic_token_types![
     (SELF_KEYWORD, "selfKeyword"),
     (SEMICOLON, "semicolon"),
     (TYPE_ALIAS, "typeAlias"),
+    (TOOL, "tool"),
     (UNION, "union"),
     (UNRESOLVED_REFERENCE, "unresolvedReference"),
 ];
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 8e77df95982..1dd4dabec4d 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -50,8 +50,8 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
         SymbolKind::Enum => lsp_types::SymbolKind::ENUM,
         SymbolKind::Variant => lsp_types::SymbolKind::ENUM_MEMBER,
         SymbolKind::Trait => lsp_types::SymbolKind::INTERFACE,
-        SymbolKind::Macro => lsp_types::SymbolKind::FUNCTION,
-        SymbolKind::Module => lsp_types::SymbolKind::MODULE,
+        SymbolKind::Macro | SymbolKind::BuiltinAttr => lsp_types::SymbolKind::FUNCTION,
+        SymbolKind::Module | SymbolKind::Tool => lsp_types::SymbolKind::MODULE,
         SymbolKind::TypeAlias | SymbolKind::TypeParam => lsp_types::SymbolKind::TYPE_PARAMETER,
         SymbolKind::Field => lsp_types::SymbolKind::FIELD,
         SymbolKind::Static => lsp_types::SymbolKind::CONSTANT,
@@ -128,6 +128,8 @@ pub(crate) fn completion_item_kind(
             SymbolKind::Union => lsp_types::CompletionItemKind::STRUCT,
             SymbolKind::ValueParam => lsp_types::CompletionItemKind::VALUE,
             SymbolKind::Variant => lsp_types::CompletionItemKind::ENUM_MEMBER,
+            SymbolKind::BuiltinAttr => lsp_types::CompletionItemKind::FUNCTION,
+            SymbolKind::Tool => lsp_types::CompletionItemKind::MODULE,
         },
     }
 }
@@ -499,10 +501,11 @@ fn semantic_token_type_and_modifiers(
             SymbolKind::TypeAlias => semantic_tokens::TYPE_ALIAS,
             SymbolKind::Trait => lsp_types::SemanticTokenType::INTERFACE,
             SymbolKind::Macro => lsp_types::SemanticTokenType::MACRO,
+            SymbolKind::BuiltinAttr => semantic_tokens::BUILTIN_ATTRIBUTE,
+            SymbolKind::Tool => semantic_tokens::TOOL,
         },
         HlTag::Attribute => semantic_tokens::ATTRIBUTE,
         HlTag::BoolLiteral => semantic_tokens::BOOLEAN,
-        HlTag::BuiltinAttr => semantic_tokens::BUILTIN_ATTRIBUTE,
         HlTag::BuiltinType => semantic_tokens::BUILTIN_TYPE,
         HlTag::ByteLiteral | HlTag::NumericLiteral => lsp_types::SemanticTokenType::NUMBER,
         HlTag::CharLiteral => semantic_tokens::CHAR,