mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-12 21:28:51 +00:00
Merge pull request #4474 from georgewfraser/color_attrs
Color attribute functions
This commit is contained in:
commit
ce7144a93d
7 changed files with 24 additions and 4 deletions
|
@ -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>,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -67,6 +67,7 @@ define_semantic_token_modifiers![
|
|||
(CONTROL_FLOW, "controlFlow"),
|
||||
(MUTABLE, "mutable"),
|
||||
(UNSAFE, "unsafe"),
|
||||
(ATTRIBUTE_MODIFIER, "attribute"),
|
||||
];
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
],
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue