.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>,
}
// 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) {
#[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,
impl HighlightModifier {
const ALL: &'static [HighlightModifier] = &[
+ HighlightModifier::Attribute,
HighlightModifier::ControlFlow,
HighlightModifier::Definition,
HighlightModifier::Mutable,
fn as_str(self) -> &'static str {
match self {
+ HighlightModifier::Attribute => "attribute",
HighlightModifier::ControlFlow => "control",
HighlightModifier::Definition => "declaration",
HighlightModifier::Mutable => "mutable",
(CONTROL_FLOW, "controlFlow"),
(MUTABLE, "mutable"),
(UNSAFE, "unsafe"),
+ (ATTRIBUTE_MODIFIER, "attribute"),
];
#[derive(Default)]
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,
}
],
"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"
],
{
"comment": "Attribute",
"name": "meta.attribute.rust",
- "begin": "#\\!?\\[",
+ "begin": "#\\!?\\[(\\w*)",
"end": "\\]",
+ "captures": {
+ "1": {
+ "name": "entity.name.function.attribute.rust"
+ }
+ },
"patterns": [
{
"include": "#string_literal"