mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
Introduce SymbolKind::Derive
This commit is contained in:
parent
642c1eb720
commit
e4f2d0e3a8
@ -363,7 +363,13 @@ impl TryToNav for hir::MacroDef {
|
||||
let mut res = NavigationTarget::from_named(
|
||||
db,
|
||||
src.as_ref().with_value(name_owner),
|
||||
SymbolKind::Macro,
|
||||
match self.kind() {
|
||||
hir::MacroKind::Declarative
|
||||
| hir::MacroKind::BuiltIn
|
||||
| hir::MacroKind::ProcMacro => SymbolKind::Macro,
|
||||
hir::MacroKind::Derive => SymbolKind::Derive,
|
||||
hir::MacroKind::Attr => SymbolKind::Attribute,
|
||||
},
|
||||
);
|
||||
res.docs = self.docs(db);
|
||||
Some(res)
|
||||
|
@ -374,7 +374,13 @@ fn highlight_def(
|
||||
) -> Highlight {
|
||||
let db = sema.db;
|
||||
let mut h = match def {
|
||||
Definition::Macro(_) => Highlight::new(HlTag::Symbol(SymbolKind::Macro)),
|
||||
Definition::Macro(m) => Highlight::new(HlTag::Symbol(match m.kind() {
|
||||
hir::MacroKind::Declarative | hir::MacroKind::BuiltIn | hir::MacroKind::ProcMacro => {
|
||||
SymbolKind::Macro
|
||||
}
|
||||
hir::MacroKind::Derive => SymbolKind::Derive,
|
||||
hir::MacroKind::Attr => SymbolKind::Attribute,
|
||||
})),
|
||||
Definition::Field(_) => Highlight::new(HlTag::Symbol(SymbolKind::Field)),
|
||||
Definition::Module(module) => {
|
||||
let mut h = Highlight::new(HlTag::Symbol(SymbolKind::Module));
|
||||
|
@ -128,6 +128,7 @@ impl HlTag {
|
||||
SymbolKind::BuiltinAttr => "builtin_attr",
|
||||
SymbolKind::Const => "constant",
|
||||
SymbolKind::ConstParam => "const_param",
|
||||
SymbolKind::Derive => "derive",
|
||||
SymbolKind::Enum => "enum",
|
||||
SymbolKind::Field => "field",
|
||||
SymbolKind::Function => "function",
|
||||
|
@ -44,7 +44,7 @@ pre { color: #DCDCCC; background: #3F3F3F; font-size: 22px; padd
|
||||
<span class="keyword">mod</span> <span class="module declaration">inner</span> <span class="brace">{</span><span class="brace">}</span>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<span class="keyword">pub</span> <span class="keyword">mod</span> <span class="module declaration public">ops</span> <span class="brace">{</span>
|
||||
<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>
|
||||
<span class="keyword">pub</span> <span class="keyword">trait</span> <span class="trait declaration public">FnOnce</span><span class="angle"><</span><span class="type_param declaration">Args</span><span class="angle">></span> <span class="brace">{</span><span class="brace">}</span>
|
||||
@ -87,7 +87,7 @@ proc_macros::<span class="macro">mirror!</span> <span class="brace">{</span>
|
||||
<span class="brace">}</span>
|
||||
<span class="brace">}</span>
|
||||
|
||||
<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>
|
||||
<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>
|
||||
<span class="keyword">struct</span> <span class="struct declaration">FooCopy</span> <span class="brace">{</span>
|
||||
<span class="field declaration">x</span><span class="colon">:</span> <span class="builtin_type">u32</span><span class="comma">,</span>
|
||||
<span class="brace">}</span>
|
||||
|
@ -9,7 +9,7 @@ use crate::{completions::Completions, context::CompletionContext, CompletionItem
|
||||
|
||||
pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
let add_completion = |item: &str| {
|
||||
let mut completion = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), item);
|
||||
let mut completion = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), item);
|
||||
completion.insert_text(format!(r#""{}""#, item));
|
||||
acc.add(completion.build());
|
||||
};
|
||||
@ -32,7 +32,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
krate.potential_cfg(ctx.db).get_cfg_values(&name).cloned().for_each(|s| {
|
||||
let insert_text = format!(r#""{}""#, s);
|
||||
let mut item =
|
||||
CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), s);
|
||||
CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), s);
|
||||
item.insert_text(insert_text);
|
||||
|
||||
acc.add(item.build());
|
||||
@ -42,7 +42,7 @@ pub(crate) fn complete_cfg(acc: &mut Completions, ctx: &CompletionContext) {
|
||||
None => {
|
||||
if let Some(krate) = ctx.krate {
|
||||
krate.potential_cfg(ctx.db).get_cfg_keys().cloned().for_each(|s| {
|
||||
let item = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), s);
|
||||
let item = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), s);
|
||||
acc.add(item.build());
|
||||
})
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ pub(super) fn complete_derive(
|
||||
_ => (name, None),
|
||||
};
|
||||
|
||||
let mut item = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), label);
|
||||
let mut item = CompletionItem::new(SymbolKind::Derive, ctx.source_range(), label);
|
||||
if let Some(docs) = mac.docs(ctx.db) {
|
||||
item.documentation(docs);
|
||||
}
|
||||
@ -67,7 +67,7 @@ pub(super) fn complete_derive(
|
||||
item.add_to(acc);
|
||||
}
|
||||
|
||||
flyimport_attribute(acc, ctx);
|
||||
flyimport_derive(acc, ctx);
|
||||
}
|
||||
|
||||
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)> {
|
||||
result
|
||||
}
|
||||
|
||||
fn flyimport_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
fn flyimport_derive(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
if ctx.token.kind() != SyntaxKind::IDENT {
|
||||
return None;
|
||||
};
|
||||
@ -106,13 +106,14 @@ fn flyimport_attribute(acc: &mut Completions, ctx: &CompletionContext) -> Option
|
||||
hir::ItemInNs::Macros(mac) => Some((import, mac)),
|
||||
_ => None,
|
||||
})
|
||||
.filter(|&(_, mac)| mac.kind() == MacroKind::Derive)
|
||||
.filter(|&(_, mac)| !ctx.is_item_hidden(&hir::ItemInNs::Macros(mac)))
|
||||
.sorted_by_key(|(import, _)| {
|
||||
compute_fuzzy_completion_order_key(&import.import_path, &user_input_lowercased)
|
||||
})
|
||||
.filter_map(|(import, mac)| {
|
||||
let mut item = CompletionItem::new(
|
||||
SymbolKind::Attribute,
|
||||
SymbolKind::Derive,
|
||||
ctx.source_range(),
|
||||
mac.name(ctx.db)?.to_smol_str(),
|
||||
);
|
||||
|
@ -26,7 +26,7 @@ pub(super) fn complete_repr(acc: &mut Completions, ctx: &CompletionContext, inpu
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut item = CompletionItem::new(SymbolKind::Attribute, ctx.source_range(), label);
|
||||
let mut item = CompletionItem::new(SymbolKind::BuiltinAttr, ctx.source_range(), label);
|
||||
if let Some(lookup) = lookup {
|
||||
item.lookup_by(lookup);
|
||||
}
|
||||
|
@ -235,6 +235,7 @@ impl CompletionItemKind {
|
||||
SymbolKind::BuiltinAttr => "ba",
|
||||
SymbolKind::Const => "ct",
|
||||
SymbolKind::ConstParam => "cp",
|
||||
SymbolKind::Derive => "de",
|
||||
SymbolKind::Enum => "en",
|
||||
SymbolKind::Field => "fd",
|
||||
SymbolKind::Function => "fn",
|
||||
|
@ -560,9 +560,9 @@ mod cfg {
|
||||
check(
|
||||
r#"#[cfg(target_endian = $0"#,
|
||||
expect![[r#"
|
||||
at little
|
||||
at big
|
||||
"#]],
|
||||
ba little
|
||||
ba big
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -594,13 +594,13 @@ mod derive {
|
||||
#[derive($0)] struct Test;
|
||||
"#,
|
||||
expect![[r#"
|
||||
at Default
|
||||
at Clone, Copy
|
||||
at PartialEq
|
||||
at PartialEq, Eq
|
||||
at PartialEq, Eq, PartialOrd, Ord
|
||||
at Clone
|
||||
at PartialEq, PartialOrd
|
||||
de Default
|
||||
de Clone, Copy
|
||||
de PartialEq
|
||||
de PartialEq, Eq
|
||||
de PartialEq, Eq, PartialOrd, Ord
|
||||
de Clone
|
||||
de PartialEq, PartialOrd
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
@ -613,12 +613,12 @@ mod derive {
|
||||
#[derive(serde::Serialize, PartialEq, $0)] struct Test;
|
||||
"#,
|
||||
expect![[r#"
|
||||
at Default
|
||||
at Clone, Copy
|
||||
at Eq
|
||||
at Eq, PartialOrd, Ord
|
||||
at Clone
|
||||
at PartialOrd
|
||||
de Default
|
||||
de Clone, Copy
|
||||
de Eq
|
||||
de Eq, PartialOrd, Ord
|
||||
de Clone
|
||||
de PartialOrd
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
@ -631,12 +631,12 @@ mod derive {
|
||||
#[derive($0 serde::Serialize, PartialEq)] struct Test;
|
||||
"#,
|
||||
expect![[r#"
|
||||
at Default
|
||||
at Clone, Copy
|
||||
at Eq
|
||||
at Eq, PartialOrd, Ord
|
||||
at Clone
|
||||
at PartialOrd
|
||||
de Default
|
||||
de Clone, Copy
|
||||
de Eq
|
||||
de Eq, PartialOrd, Ord
|
||||
de Clone
|
||||
de PartialOrd
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
@ -649,7 +649,7 @@ mod derive {
|
||||
#[derive(der$0)] struct Test;
|
||||
"#,
|
||||
expect![[r#"
|
||||
at DeriveIdentity (use proc_macros::DeriveIdentity)
|
||||
de DeriveIdentity (use proc_macros::DeriveIdentity)
|
||||
"#]],
|
||||
);
|
||||
check_derive(
|
||||
@ -659,7 +659,7 @@ use proc_macros::DeriveIdentity;
|
||||
#[derive(der$0)] struct Test;
|
||||
"#,
|
||||
expect![[r#"
|
||||
at DeriveIdentity
|
||||
de DeriveIdentity
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
@ -775,23 +775,23 @@ mod repr {
|
||||
check_repr(
|
||||
r#"#[repr($0)] struct Test;"#,
|
||||
expect![[r#"
|
||||
at align($0)
|
||||
at packed
|
||||
at transparent
|
||||
at C
|
||||
at u8
|
||||
at u16
|
||||
at u32
|
||||
at u64
|
||||
at u128
|
||||
at usize
|
||||
at i8
|
||||
at i16
|
||||
at i32
|
||||
at i64
|
||||
at i28
|
||||
at isize
|
||||
"#]],
|
||||
ba align($0)
|
||||
ba packed
|
||||
ba transparent
|
||||
ba C
|
||||
ba u8
|
||||
ba u16
|
||||
ba u32
|
||||
ba u64
|
||||
ba u128
|
||||
ba usize
|
||||
ba i8
|
||||
ba i16
|
||||
ba i32
|
||||
ba i64
|
||||
ba i28
|
||||
ba isize
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -805,21 +805,21 @@ mod repr {
|
||||
check_repr(
|
||||
r#"#[repr(align(1), $0)] struct Test;"#,
|
||||
expect![[r#"
|
||||
at transparent
|
||||
at C
|
||||
at u8
|
||||
at u16
|
||||
at u32
|
||||
at u64
|
||||
at u128
|
||||
at usize
|
||||
at i8
|
||||
at i16
|
||||
at i32
|
||||
at i64
|
||||
at i28
|
||||
at isize
|
||||
"#]],
|
||||
ba transparent
|
||||
ba C
|
||||
ba u8
|
||||
ba u16
|
||||
ba u32
|
||||
ba u64
|
||||
ba u128
|
||||
ba usize
|
||||
ba i8
|
||||
ba i16
|
||||
ba i32
|
||||
ba i64
|
||||
ba i28
|
||||
ba isize
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -828,21 +828,21 @@ mod repr {
|
||||
check_repr(
|
||||
r#"#[repr(packed, $0)] struct Test;"#,
|
||||
expect![[r#"
|
||||
at transparent
|
||||
at C
|
||||
at u8
|
||||
at u16
|
||||
at u32
|
||||
at u64
|
||||
at u128
|
||||
at usize
|
||||
at i8
|
||||
at i16
|
||||
at i32
|
||||
at i64
|
||||
at i28
|
||||
at isize
|
||||
"#]],
|
||||
ba transparent
|
||||
ba C
|
||||
ba u8
|
||||
ba u16
|
||||
ba u32
|
||||
ba u64
|
||||
ba u128
|
||||
ba usize
|
||||
ba i8
|
||||
ba i16
|
||||
ba i32
|
||||
ba i64
|
||||
ba i28
|
||||
ba isize
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -851,21 +851,21 @@ mod repr {
|
||||
check_repr(
|
||||
r#"#[repr(C, $0)] struct Test;"#,
|
||||
expect![[r#"
|
||||
at align($0)
|
||||
at packed
|
||||
at u8
|
||||
at u16
|
||||
at u32
|
||||
at u64
|
||||
at u128
|
||||
at usize
|
||||
at i8
|
||||
at i16
|
||||
at i32
|
||||
at i64
|
||||
at i28
|
||||
at isize
|
||||
"#]],
|
||||
ba align($0)
|
||||
ba packed
|
||||
ba u8
|
||||
ba u16
|
||||
ba u32
|
||||
ba u64
|
||||
ba u128
|
||||
ba usize
|
||||
ba i8
|
||||
ba i16
|
||||
ba i32
|
||||
ba i64
|
||||
ba i28
|
||||
ba isize
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -874,10 +874,10 @@ mod repr {
|
||||
check_repr(
|
||||
r#"#[repr(usize, $0)] struct Test;"#,
|
||||
expect![[r#"
|
||||
at align($0)
|
||||
at packed
|
||||
at C
|
||||
"#]],
|
||||
ba align($0)
|
||||
ba packed
|
||||
ba C
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,7 @@ pub enum SymbolKind {
|
||||
BuiltinAttr,
|
||||
Const,
|
||||
ConstParam,
|
||||
Derive,
|
||||
Enum,
|
||||
Field,
|
||||
Function,
|
||||
|
@ -53,6 +53,7 @@ define_semantic_token_types![
|
||||
(COMMA, "comma"),
|
||||
(COMPARISON, "comparison"),
|
||||
(CONST_PARAMETER, "constParameter"),
|
||||
(DERIVE, "derive"),
|
||||
(DOT, "dot"),
|
||||
(ESCAPE_SEQUENCE, "escapeSequence"),
|
||||
(FORMAT_SPECIFIER, "formatSpecifier"),
|
||||
|
@ -50,9 +50,10 @@ pub(crate) fn symbol_kind(symbol_kind: SymbolKind) -> lsp_types::SymbolKind {
|
||||
SymbolKind::Enum => lsp_types::SymbolKind::ENUM,
|
||||
SymbolKind::Variant => lsp_types::SymbolKind::ENUM_MEMBER,
|
||||
SymbolKind::Trait => lsp_types::SymbolKind::INTERFACE,
|
||||
SymbolKind::Macro | SymbolKind::BuiltinAttr | SymbolKind::Attribute => {
|
||||
lsp_types::SymbolKind::FUNCTION
|
||||
}
|
||||
SymbolKind::Macro
|
||||
| SymbolKind::BuiltinAttr
|
||||
| SymbolKind::Attribute
|
||||
| SymbolKind::Derive => lsp_types::SymbolKind::FUNCTION,
|
||||
SymbolKind::Module | SymbolKind::ToolModule => lsp_types::SymbolKind::MODULE,
|
||||
SymbolKind::TypeAlias | SymbolKind::TypeParam => lsp_types::SymbolKind::TYPE_PARAMETER,
|
||||
SymbolKind::Field => lsp_types::SymbolKind::FIELD,
|
||||
@ -112,6 +113,7 @@ pub(crate) fn completion_item_kind(
|
||||
SymbolKind::Attribute => lsp_types::CompletionItemKind::FUNCTION,
|
||||
SymbolKind::Const => lsp_types::CompletionItemKind::CONSTANT,
|
||||
SymbolKind::ConstParam => lsp_types::CompletionItemKind::TYPE_PARAMETER,
|
||||
SymbolKind::Derive => lsp_types::CompletionItemKind::FUNCTION,
|
||||
SymbolKind::Enum => lsp_types::CompletionItemKind::ENUM,
|
||||
SymbolKind::Field => lsp_types::CompletionItemKind::FIELD,
|
||||
SymbolKind::Function => lsp_types::CompletionItemKind::FUNCTION,
|
||||
@ -471,6 +473,7 @@ fn semantic_token_type_and_modifiers(
|
||||
let type_ = match highlight.tag {
|
||||
HlTag::Symbol(symbol) => match symbol {
|
||||
SymbolKind::Attribute => semantic_tokens::ATTRIBUTE,
|
||||
SymbolKind::Derive => semantic_tokens::DERIVE,
|
||||
SymbolKind::Module => lsp_types::SemanticTokenType::NAMESPACE,
|
||||
SymbolKind::Impl => semantic_tokens::TYPE_ALIAS,
|
||||
SymbolKind::Field => lsp_types::SemanticTokenType::PROPERTY,
|
||||
|
Loading…
Reference in New Issue
Block a user