mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-26 11:55:04 +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; }
|
.keyword.unsafe { color: #BC8383; font-weight: bold; }
|
||||||
.control { font-style: italic; }
|
.control { font-style: italic; }
|
||||||
</style>
|
</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">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">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>,
|
<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
|
// 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 => {
|
NAME_REF => {
|
||||||
let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
|
let name_ref = element.into_node().and_then(ast::NameRef::cast).unwrap();
|
||||||
match classify_name_ref(sema, &name_ref) {
|
match classify_name_ref(sema, &name_ref) {
|
||||||
|
|
|
@ -45,8 +45,10 @@ pub enum HighlightTag {
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum HighlightModifier {
|
pub enum HighlightModifier {
|
||||||
|
/// Used to differentiate individual elements within attributes.
|
||||||
|
Attribute = 0,
|
||||||
/// Used with keywords like `if` and `break`.
|
/// 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
|
/// `foo` in `fn foo(x: i32)` is a definition, `foo` in `foo(90 + 2)` is
|
||||||
/// not.
|
/// not.
|
||||||
Definition,
|
Definition,
|
||||||
|
@ -95,6 +97,7 @@ impl fmt::Display for HighlightTag {
|
||||||
|
|
||||||
impl HighlightModifier {
|
impl HighlightModifier {
|
||||||
const ALL: &'static [HighlightModifier] = &[
|
const ALL: &'static [HighlightModifier] = &[
|
||||||
|
HighlightModifier::Attribute,
|
||||||
HighlightModifier::ControlFlow,
|
HighlightModifier::ControlFlow,
|
||||||
HighlightModifier::Definition,
|
HighlightModifier::Definition,
|
||||||
HighlightModifier::Mutable,
|
HighlightModifier::Mutable,
|
||||||
|
@ -103,6 +106,7 @@ impl HighlightModifier {
|
||||||
|
|
||||||
fn as_str(self) -> &'static str {
|
fn as_str(self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
HighlightModifier::Attribute => "attribute",
|
||||||
HighlightModifier::ControlFlow => "control",
|
HighlightModifier::ControlFlow => "control",
|
||||||
HighlightModifier::Definition => "declaration",
|
HighlightModifier::Definition => "declaration",
|
||||||
HighlightModifier::Mutable => "mutable",
|
HighlightModifier::Mutable => "mutable",
|
||||||
|
|
|
@ -67,6 +67,7 @@ define_semantic_token_modifiers![
|
||||||
(CONTROL_FLOW, "controlFlow"),
|
(CONTROL_FLOW, "controlFlow"),
|
||||||
(MUTABLE, "mutable"),
|
(MUTABLE, "mutable"),
|
||||||
(UNSAFE, "unsafe"),
|
(UNSAFE, "unsafe"),
|
||||||
|
(ATTRIBUTE_MODIFIER, "attribute"),
|
||||||
];
|
];
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
|
|
@ -307,6 +307,7 @@ fn semantic_token_type_and_modifiers(
|
||||||
|
|
||||||
for modifier in highlight.modifiers.iter() {
|
for modifier in highlight.modifiers.iter() {
|
||||||
let modifier = match modifier {
|
let modifier = match modifier {
|
||||||
|
HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER,
|
||||||
HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION,
|
HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION,
|
||||||
HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW,
|
HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW,
|
||||||
HighlightModifier::Mutable => semantic_tokens::MUTABLE,
|
HighlightModifier::Mutable => semantic_tokens::MUTABLE,
|
||||||
|
|
|
@ -610,6 +610,10 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"semanticTokenModifiers": [
|
"semanticTokenModifiers": [
|
||||||
|
{
|
||||||
|
"id": "attribute",
|
||||||
|
"description": "Style for elements within attributes"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "constant",
|
"id": "constant",
|
||||||
"description": "Style for compile-time constants"
|
"description": "Style for compile-time constants"
|
||||||
|
@ -637,6 +641,9 @@
|
||||||
"attribute": [
|
"attribute": [
|
||||||
"meta.attribute.rust"
|
"meta.attribute.rust"
|
||||||
],
|
],
|
||||||
|
"function.attribute": [
|
||||||
|
"entity.name.function.attribute.rust"
|
||||||
|
],
|
||||||
"builtinType": [
|
"builtinType": [
|
||||||
"support.type.primitive.rust"
|
"support.type.primitive.rust"
|
||||||
],
|
],
|
||||||
|
|
|
@ -75,8 +75,13 @@
|
||||||
{
|
{
|
||||||
"comment": "Attribute",
|
"comment": "Attribute",
|
||||||
"name": "meta.attribute.rust",
|
"name": "meta.attribute.rust",
|
||||||
"begin": "#\\!?\\[",
|
"begin": "#\\!?\\[(\\w*)",
|
||||||
"end": "\\]",
|
"end": "\\]",
|
||||||
|
"captures": {
|
||||||
|
"1": {
|
||||||
|
"name": "entity.name.function.attribute.rust"
|
||||||
|
}
|
||||||
|
},
|
||||||
"patterns": [
|
"patterns": [
|
||||||
{
|
{
|
||||||
"include": "#string_literal"
|
"include": "#string_literal"
|
||||||
|
|
Loading…
Reference in a new issue