diff --git a/crates/ra_ide/src/snapshots/highlighting.html b/crates/ra_ide/src/snapshots/highlighting.html index 635fe5cf9d..2ceadf2fcb 100644 --- a/crates/ra_ide/src/snapshots/highlighting.html +++ b/crates/ra_ide/src/snapshots/highlighting.html @@ -27,7 +27,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd .keyword.unsafe { color: #BC8383; font-weight: bold; } .control { font-style: italic; } -
#[derive(Clone, Debug)]
+#[derive(Clone, Debug)]
struct Foo {
pub x: i32,
pub y: i32,
diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs
index be57eeb0ab..b55cf748dc 100644
--- a/crates/ra_ide/src/syntax_highlighting.rs
+++ b/crates/ra_ide/src/syntax_highlighting.rs
@@ -361,7 +361,9 @@ fn highlight_element(
}
// Highlight references like the definitions they resolve to
- NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => return None,
+ NAME_REF if element.ancestors().any(|it| it.kind() == ATTR) => {
+ Highlight::from(HighlightTag::Function) | HighlightModifier::Attribute
+ }
NAME_REF => {
let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
match classify_name_ref(sema, &name_ref) {
diff --git a/crates/ra_ide/src/syntax_highlighting/tags.rs b/crates/ra_ide/src/syntax_highlighting/tags.rs
index be1a0f12b2..33e6619ec7 100644
--- a/crates/ra_ide/src/syntax_highlighting/tags.rs
+++ b/crates/ra_ide/src/syntax_highlighting/tags.rs
@@ -45,8 +45,10 @@ pub enum HighlightTag {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(u8)]
pub enum HighlightModifier {
+ /// Used to differentiate individual elements within attributes.
+ Attribute = 0,
/// Used with keywords like `if` and `break`.
- ControlFlow = 0,
+ ControlFlow,
/// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is
/// not.
Definition,
@@ -95,6 +97,7 @@ impl fmt::Display for HighlightTag {
impl HighlightModifier {
const ALL: &'static [HighlightModifier] = &[
+ HighlightModifier::Attribute,
HighlightModifier::ControlFlow,
HighlightModifier::Definition,
HighlightModifier::Mutable,
@@ -103,6 +106,7 @@ impl HighlightModifier {
fn as_str(self) -> &'static str {
match self {
+ HighlightModifier::Attribute => "attribute",
HighlightModifier::ControlFlow => "control",
HighlightModifier::Definition => "declaration",
HighlightModifier::Mutable => "mutable",
diff --git a/crates/rust-analyzer/src/semantic_tokens.rs b/crates/rust-analyzer/src/semantic_tokens.rs
index 2dc5cb1196..90a6257ee8 100644
--- a/crates/rust-analyzer/src/semantic_tokens.rs
+++ b/crates/rust-analyzer/src/semantic_tokens.rs
@@ -67,6 +67,7 @@ define_semantic_token_modifiers![
(CONTROL_FLOW, "controlFlow"),
(MUTABLE, "mutable"),
(UNSAFE, "unsafe"),
+ (ATTRIBUTE_MODIFIER, "attribute"),
];
#[derive(Default)]
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 7dd7d9416f..672e47e41c 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -307,6 +307,7 @@ fn semantic_token_type_and_modifiers(
for modifier in highlight.modifiers.iter() {
let modifier = match modifier {
+ HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER,
HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION,
HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW,
HighlightModifier::Mutable => semantic_tokens::MUTABLE,
diff --git a/editors/code/package.json b/editors/code/package.json
index 1eebe06082..3aa90cd66d 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -610,6 +610,10 @@
}
],
"semanticTokenModifiers": [
+ {
+ "id": "attribute",
+ "description": "Style for elements within attributes"
+ },
{
"id": "constant",
"description": "Style for compile-time constants"
@@ -637,6 +641,9 @@
"attribute": [
"meta.attribute.rust"
],
+ "function.attribute": [
+ "entity.name.function.attribute.rust"
+ ],
"builtinType": [
"support.type.primitive.rust"
],
diff --git a/editors/code/rust.tmGrammar.json b/editors/code/rust.tmGrammar.json
index aa0811326a..cdcd557dc1 100644
--- a/editors/code/rust.tmGrammar.json
+++ b/editors/code/rust.tmGrammar.json
@@ -75,8 +75,13 @@
{
"comment": "Attribute",
"name": "meta.attribute.rust",
- "begin": "#\\!?\\[",
+ "begin": "#\\!?\\[(\\w*)",
"end": "\\]",
+ "captures": {
+ "1": {
+ "name": "entity.name.function.attribute.rust"
+ }
+ },
"patterns": [
{
"include": "#string_literal"