]> git.lizzy.rs Git - rust.git/commitdiff
Color attribute functions
authorGeorge Fraser <george@fivetran.com>
Wed, 13 May 2020 04:58:51 +0000 (21:58 -0700)
committerGeorge Fraser <george@fivetran.com>
Tue, 19 May 2020 05:55:46 +0000 (22:55 -0700)
crates/ra_ide/src/snapshots/highlighting.html
crates/ra_ide/src/syntax_highlighting.rs
crates/ra_ide/src/syntax_highlighting/tags.rs
crates/rust-analyzer/src/semantic_tokens.rs
crates/rust-analyzer/src/to_proto.rs
editors/code/package.json
editors/code/rust.tmGrammar.json

index 635fe5cf9ddf54fc7d11ace1fca787cdfd56b341..2ceadf2fcbf75b2625927c079b97e04f8278be14 100644 (file)
@@ -27,7 +27,7 @@ pre                 { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
 .keyword.unsafe     { color: #BC8383; font-weight: bold; }
 .control            { font-style: italic; }
 </style>
-<pre><code><span class="attribute">#[derive(Clone, Debug)]</span>
+<pre><code><span class="attribute">#[</span><span class="function attribute">derive</span><span class="attribute">(Clone, Debug)]</span>
 <span class="keyword">struct</span> <span class="struct declaration">Foo</span> {
     <span class="keyword">pub</span> <span class="field declaration">x</span>: <span class="builtin_type">i32</span>,
     <span class="keyword">pub</span> <span class="field declaration">y</span>: <span class="builtin_type">i32</span>,
index be57eeb0abeab6eade3d82657cf876328e4bb563..b55cf748dc08ea7333f4f68f5b11c10a2b2cd1d1 100644 (file)
@@ -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) {
index be1a0f12b25bfaeb044e28f2d07ff4d4c0fbe80e..33e6619ec789d19a2c6b050ce649efbace44bd09 100644 (file)
@@ -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 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 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",
index 2dc5cb1196fc41e6f374185d731ac043c300ed3a..90a6257ee8e12470cec687dc804706d0228ac7bd 100644 (file)
@@ -67,6 +67,7 @@ macro_rules! define_semantic_token_modifiers {
     (CONTROL_FLOW, "controlFlow"),
     (MUTABLE, "mutable"),
     (UNSAFE, "unsafe"),
+    (ATTRIBUTE_MODIFIER, "attribute"),
 ];
 
 #[derive(Default)]
index a8e2e535f9ab17c86d0f71bac4d2ef8b40f3e4ee..09343f92517f75a5cb74525224bcc8fd628d3cb8 100644 (file)
@@ -296,6 +296,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,
index d899f60e333c64c66adc67aaeb69973c60ffa291..d078f74722012ef6ec7f7d98acc5603e140e2d50 100644 (file)
             }
         ],
         "semanticTokenModifiers": [
+            {
+                "id": "attribute",
+                "description": "Style for elements within attributes"
+            },
             {
                 "id": "constant",
                 "description": "Style for compile-time constants"
                     "attribute": [
                         "meta.attribute.rust"
                     ],
+                    "function.attribute": [
+                        "entity.name.function.attribute.rust"
+                    ],
                     "builtinType": [
                         "support.type.primitive.rust"
                     ],
index aa0811326a0e801bd606e7d370454857632c8950..cdcd557dc173426bf6fc635f6430d951766e71b8 100644 (file)
                {
                        "comment": "Attribute",
                        "name": "meta.attribute.rust",
-                       "begin": "#\\!?\\[",
+                       "begin": "#\\!?\\[(\\w*)",
                        "end": "\\]",
+                       "captures": {
+                               "1": {
+                                       "name": "entity.name.function.attribute.rust"
+                               }
+                       },
                        "patterns": [
                                {
                                        "include": "#string_literal"