Skip to content

Commit e4f2d0e

Browse files
committed
Introduce SymbolKind::Derive
1 parent 642c1eb commit e4f2d0e

File tree

12 files changed

+125
-105
lines changed

12 files changed

+125
-105
lines changed

crates/ide/src/navigation_target.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,13 @@ impl TryToNav for hir::MacroDef {
363363
let mut res = NavigationTarget::from_named(
364364
db,
365365
src.as_ref().with_value(name_owner),
366-
SymbolKind::Macro,
366+
match self.kind() {
367+
hir::MacroKind::Declarative
368+
| hir::MacroKind::BuiltIn
369+
| hir::MacroKind::ProcMacro => SymbolKind::Macro,
370+
hir::MacroKind::Derive => SymbolKind::Derive,
371+
hir::MacroKind::Attr => SymbolKind::Attribute,
372+
},
367373
);
368374
res.docs = self.docs(db);
369375
Some(res)

crates/ide/src/syntax_highlighting/highlight.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,13 @@ fn highlight_def(
374374
) -> Highlight {
375375
let db = sema.db;
376376
let mut h = match def {
377-
Definition::Macro(_) => Highlight::new(HlTag::Symbol(SymbolKind::Macro)),
377+
Definition::Macro(m) => Highlight::new(HlTag::Symbol(match m.kind() {
378+
hir::MacroKind::Declarative | hir::MacroKind::BuiltIn | hir::MacroKind::ProcMacro => {
379+
SymbolKind::Macro
380+
}
381+
hir::MacroKind::Derive => SymbolKind::Derive,
382+
hir::MacroKind::Attr => SymbolKind::Attribute,
383+
})),
378384
Definition::Field(_) => Highlight::new(HlTag::Symbol(SymbolKind::Field)),
379385
Definition::Module(module) => {
380386
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Module));

crates/ide/src/syntax_highlighting/tags.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl HlTag {
128128
SymbolKind::BuiltinAttr => "builtin_attr",
129129
SymbolKind::Const => "constant",
130130
SymbolKind::ConstParam => "const_param",
131+
SymbolKind::Derive => "derive",
131132
SymbolKind::Enum => "enum",
132133
SymbolKind::Field => "field",
133134
SymbolKind::Function => "function",

crates/ide/src/syntax_highlighting/test_data/highlighting.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="brace">{</span><span class="brace">}</span>
4545

4646
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="builtin_attr attribute library">allow</span><span class="parenthesis attribute">(</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
47-
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="module attribute crate_root library">proc_macros</span><span class="operator attribute">::</span><span class="macro attribute library">identity</span><span class="attribute_bracket attribute">]</span>
47+
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="module attribute crate_root library">proc_macros</span><span class="operator attribute">::</span><span class="attribute attribute library">identity</span><span class="attribute_bracket attribute">]</span>
4848
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration public">ops</span> <span class="brace">{</span>
4949
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="builtin_attr attribute library">lang</span> <span class="operator attribute">=</span> <span class="string_literal attribute">"fn_once"</span><span class="attribute_bracket attribute">]</span>
5050
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnOnce</span><span class="angle">&lt;</span><span class="type_param declaration">Args</span><span class="angle">&gt;</span> <span class="brace">{</span><span class="brace">}</span>
@@ -87,7 +87,7 @@
8787
<span class="brace">}</span>
8888
<span class="brace">}</span>
8989

90-
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="macro attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="macro attribute default_library library">Copy</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
90+
<span class="attribute_bracket attribute">#</span><span class="attribute_bracket attribute">[</span><span class="attribute attribute default_library library">derive</span><span class="parenthesis attribute">(</span><span class="derive attribute default_library library">Copy</span><span class="parenthesis attribute">)</span><span class="attribute_bracket attribute">]</span>
9191
<span class="keyword">struct</span> <span class="struct declaration">FooCopy</span> <span class="brace">{</span>
9292
<span class="field declaration">x</span><span class="colon">:</span> <span class="builtin_type">u32</span><span class="comma">,</span>
9393
<span class="brace">}</span>

crates/ide_completion/src/completions/attribute/cfg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{completions::Completions, context::CompletionContext, CompletionItem
99

1010
pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
1111
let add_completion = |item: &str| {
12-
let mut completion = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), item);
12+
let mut completion = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), item);
1313
completion.insert_text(format!(r#""{}""#, item));
1414
acc.add(completion.build());
1515
};
@@ -32,7 +32,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
3232
krate.potential_cfg(ctx.db).get_cfg_values(&name).cloned().for_each(|s| {
3333
let insert_text = format!(r#""{}""#, s);
3434
let mut item =
35-
CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), s);
35+
CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), s);
3636
item.insert_text(insert_text);
3737

3838
acc.add(item.build());
@@ -42,7 +42,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
4242
None => {
4343
if let Some(krate) = ctx.krate {
4444
krate.potential_cfg(ctx.db).get_cfg_keys().cloned().for_each(|s| {
45-
let item = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), s);
45+
let item = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), s);
4646
acc.add(item.build());
4747
})
4848
}

crates/ide_completion/src/completions/attribute/derive.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub(super) fn complete_derive(
5757
_ => (name, None),
5858
};
5959

60-
let mut item = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), label);
60+
let mut item = CompletionItem::new(SymbolKind::Derive, ctx.source_range(), label);
6161
if let Some(docs) = mac.docs(ctx.db) {
6262
item.documentation(docs);
6363
}
@@ -67,7 +67,7 @@ pub(super) fn complete_derive(
6767
item.add_to(acc);
6868
}
6969

70-
flyimport_attribute(acc, ctx);
70+
flyimport_derive(acc, ctx);
7171
}
7272

7373
fn get_derives_in_scope(ctx: &CompletionContext) -> Vec<(hir::Name, MacroDef)> {
@@ -82,7 +82,7 @@ fn get_derives_in_scope(ctx: &CompletionContext) -> Vec<(hir::Name, MacroDef)> {
8282
result
8383
}
8484

85-
fn flyimport_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
85+
fn flyimport_derive(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
8686
if ctx.token.kind() != SyntaxKind::IDENT {
8787
return None;
8888
};
@@ -106,13 +106,14 @@ fn flyimport_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option
106106
hir::ItemInNs::Macros(mac) => Some((import, mac)),
107107
_ => None,
108108
})
109+
.filter(|&(_, mac)| mac.kind() == MacroKind::Derive)
109110
.filter(|&(_, mac)| !ctx.is_item_hidden(&hir::ItemInNs::Macros(mac)))
110111
.sorted_by_key(|(import, _)| {
111112
compute_fuzzy_completion_order_key(&import.import_path, &user_input_lowercased)
112113
})
113114
.filter_map(|(import, mac)| {
114115
let mut item = CompletionItem::new(
115-
SymbolKind::Attribute,
116+
SymbolKind::Derive,
116117
ctx.source_range(),
117118
mac.name(ctx.db)?.to_smol_str(),
118119
);

crates/ide_completion/src/completions/attribute/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(super) fn complete_repr(acc: &mut Completions, ctx: &CompletionContext, inpu
2626
continue;
2727
}
2828

29-
let mut item = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), label);
29+
let mut item = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), label);
3030
if let Some(lookup) = lookup {
3131
item.lookup_by(lookup);
3232
}

crates/ide_completion/src/item.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ impl CompletionItemKind {
235235
SymbolKind::BuiltinAttr => "ba",
236236
SymbolKind::Const => "ct",
237237
SymbolKind::ConstParam => "cp",
238+
SymbolKind::Derive => "de",
238239
SymbolKind::Enum => "en",
239240
SymbolKind::Field => "fd",
240241
SymbolKind::Function => "fn",

crates/ide_completion/src/tests/attribute.rs

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,9 @@ mod cfg {
560560
check(
561561
r#"#[cfg(target_endian = $0"#,
562562
expect![[r#"
563-
at little
564-
at big
565-
"#]],
563+
ba little
564+
ba big
565+
"#]],
566566
);
567567
}
568568
}
@@ -594,13 +594,13 @@ mod derive {
594594
#[derive($0)] struct Test;
595595
"#,
596596
expect![[r#"
597-
at Default
598-
at Clone, Copy
599-
at PartialEq
600-
at PartialEq, Eq
601-
at PartialEq, Eq, PartialOrd, Ord
602-
at Clone
603-
at PartialEq, PartialOrd
597+
de Default
598+
de Clone, Copy
599+
de PartialEq
600+
de PartialEq, Eq
601+
de PartialEq, Eq, PartialOrd, Ord
602+
de Clone
603+
de PartialEq, PartialOrd
604604
"#]],
605605
);
606606
}
@@ -613,12 +613,12 @@ mod derive {
613613
#[derive(serde::Serialize, PartialEq, $0)] struct Test;
614614
"#,
615615
expect![[r#"
616-
at Default
617-
at Clone, Copy
618-
at Eq
619-
at Eq, PartialOrd, Ord
620-
at Clone
621-
at PartialOrd
616+
de Default
617+
de Clone, Copy
618+
de Eq
619+
de Eq, PartialOrd, Ord
620+
de Clone
621+
de PartialOrd
622622
"#]],
623623
)
624624
}
@@ -631,12 +631,12 @@ mod derive {
631631
#[derive($0 serde::Serialize, PartialEq)] struct Test;
632632
"#,
633633
expect![[r#"
634-
at Default
635-
at Clone, Copy
636-
at Eq
637-
at Eq, PartialOrd, Ord
638-
at Clone
639-
at PartialOrd
634+
de Default
635+
de Clone, Copy
636+
de Eq
637+
de Eq, PartialOrd, Ord
638+
de Clone
639+
de PartialOrd
640640
"#]],
641641
)
642642
}
@@ -649,7 +649,7 @@ mod derive {
649649
#[derive(der$0)] struct Test;
650650
"#,
651651
expect![[r#"
652-
at DeriveIdentity (use proc_macros::DeriveIdentity)
652+
de DeriveIdentity (use proc_macros::DeriveIdentity)
653653
"#]],
654654
);
655655
check_derive(
@@ -659,7 +659,7 @@ use proc_macros::DeriveIdentity;
659659
#[derive(der$0)] struct Test;
660660
"#,
661661
expect![[r#"
662-
at DeriveIdentity
662+
de DeriveIdentity
663663
"#]],
664664
);
665665
}
@@ -775,23 +775,23 @@ mod repr {
775775
check_repr(
776776
r#"#[repr($0)] struct Test;"#,
777777
expect![[r#"
778-
at align($0)
779-
at packed
780-
at transparent
781-
at C
782-
at u8
783-
at u16
784-
at u32
785-
at u64
786-
at u128
787-
at usize
788-
at i8
789-
at i16
790-
at i32
791-
at i64
792-
at i28
793-
at isize
794-
"#]],
778+
ba align($0)
779+
ba packed
780+
ba transparent
781+
ba C
782+
ba u8
783+
ba u16
784+
ba u32
785+
ba u64
786+
ba u128
787+
ba usize
788+
ba i8
789+
ba i16
790+
ba i32
791+
ba i64
792+
ba i28
793+
ba isize
794+
"#]],
795795
);
796796
}
797797

@@ -805,21 +805,21 @@ mod repr {
805805
check_repr(
806806
r#"#[repr(align(1), $0)] struct Test;"#,
807807
expect![[r#"
808-
at transparent
809-
at C
810-
at u8
811-
at u16
812-
at u32
813-
at u64
814-
at u128
815-
at usize
816-
at i8
817-
at i16
818-
at i32
819-
at i64
820-
at i28
821-
at isize
822-
"#]],
808+
ba transparent
809+
ba C
810+
ba u8
811+
ba u16
812+
ba u32
813+
ba u64
814+
ba u128
815+
ba usize
816+
ba i8
817+
ba i16
818+
ba i32
819+
ba i64
820+
ba i28
821+
ba isize
822+
"#]],
823823
);
824824
}
825825

@@ -828,21 +828,21 @@ mod repr {
828828
check_repr(
829829
r#"#[repr(packed, $0)] struct Test;"#,
830830
expect![[r#"
831-
at transparent
832-
at C
833-
at u8
834-
at u16
835-
at u32
836-
at u64
837-
at u128
838-
at usize
839-
at i8
840-
at i16
841-
at i32
842-
at i64
843-
at i28
844-
at isize
845-
"#]],
831+
ba transparent
832+
ba C
833+
ba u8
834+
ba u16
835+
ba u32
836+
ba u64
837+
ba u128
838+
ba usize
839+
ba i8
840+
ba i16
841+
ba i32
842+
ba i64
843+
ba i28
844+
ba isize
845+
"#]],
846846
);
847847
}
848848

@@ -851,21 +851,21 @@ mod repr {
851851
check_repr(
852852
r#"#[repr(C, $0)] struct Test;"#,
853853
expect![[r#"
854-
at align($0)
855-
at packed
856-
at u8
857-
at u16
858-
at u32
859-
at u64
860-
at u128
861-
at usize
862-
at i8
863-
at i16
864-
at i32
865-
at i64
866-
at i28
867-
at isize
868-
"#]],
854+
ba align($0)
855+
ba packed
856+
ba u8
857+
ba u16
858+
ba u32
859+
ba u64
860+
ba u128
861+
ba usize
862+
ba i8
863+
ba i16
864+
ba i32
865+
ba i64
866+
ba i28
867+
ba isize
868+
"#]],
869869
);
870870
}
871871

@@ -874,10 +874,10 @@ mod repr {
874874
check_repr(
875875
r#"#[repr(usize, $0)] struct Test;"#,
876876
expect![[r#"
877-
at align($0)
878-
at packed
879-
at C
880-
"#]],
877+
ba align($0)
878+
ba packed
879+
ba C
880+
"#]],
881881
);
882882
}
883883
}

0 commit comments

Comments
 (0)