mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Merge #7353
7353: Add LifetimeParam and ConstParam to CompletionItemKind r=matklad a=Veykril Adds `LifetimeParam` and `ConstParam` to `CompletionItemKind` and maps them both to `TypeParam` in the protocol conversion as there are no equivalents, so nothing really changes there. `ConstParam` could be mapped to `Const` I guess but I'm split on whether that would be better? Additions were solely inspired by (the single) test output for const params. Also sorts the variants of `CompletionItemKind` and its to_proto match. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
0c37b3a0fc
23 changed files with 227 additions and 166 deletions
|
@ -6,7 +6,7 @@ use syntax::{
|
|||
match_ast, AstNode,
|
||||
};
|
||||
|
||||
use crate::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
||||
use crate::{CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions};
|
||||
|
||||
/// Complete repeated parameters, both name and type. For example, if all
|
||||
/// functions in a file have a `spam: &mut Spam` parameter, a completion with
|
||||
|
@ -58,7 +58,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
|||
})
|
||||
.for_each(|(label, lookup)| {
|
||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
||||
.kind(crate::CompletionItemKind::Binding)
|
||||
.kind(CompletionItemKind::Binding)
|
||||
.lookup_by(lookup)
|
||||
.add_to(acc)
|
||||
});
|
||||
|
|
|
@ -3,11 +3,13 @@
|
|||
use std::iter;
|
||||
|
||||
use hir::{Module, ModuleSource};
|
||||
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{
|
||||
base_db::{SourceDatabaseExt, VfsPath},
|
||||
RootDatabase, SymbolKind,
|
||||
};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{CompletionItem, CompletionItemKind};
|
||||
use crate::CompletionItem;
|
||||
|
||||
use crate::{context::CompletionContext, item::CompletionKind, Completions};
|
||||
|
||||
|
@ -79,7 +81,7 @@ pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
|
|||
label.push(';');
|
||||
}
|
||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
|
||||
.kind(CompletionItemKind::Module)
|
||||
.kind(SymbolKind::Module)
|
||||
.add_to(acc)
|
||||
});
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
//! Complete fields in record literals and patterns.
|
||||
use ide_db::helpers::FamousDefs;
|
||||
use ide_db::{helpers::FamousDefs, SymbolKind};
|
||||
use syntax::ast::Expr;
|
||||
|
||||
use crate::{
|
||||
item::CompletionKind, CompletionContext, CompletionItem, CompletionItemKind, Completions,
|
||||
};
|
||||
use crate::{item::CompletionKind, CompletionContext, CompletionItem, Completions};
|
||||
|
||||
pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||
let missing_fields = match (ctx.record_pat_syntax.as_ref(), ctx.record_lit_syntax.as_ref()) {
|
||||
|
@ -31,7 +29,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
|
|||
"..Default::default()",
|
||||
)
|
||||
.insert_text(completion_text)
|
||||
.kind(CompletionItemKind::Field)
|
||||
.kind(SymbolKind::Field)
|
||||
.build(),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
//! ```
|
||||
|
||||
use hir::{self, HasAttrs, HasSource};
|
||||
use ide_db::traits::get_missing_assoc_items;
|
||||
use ide_db::{traits::get_missing_assoc_items, SymbolKind};
|
||||
use syntax::{
|
||||
ast::{self, edit, Impl},
|
||||
display::function_declaration,
|
||||
|
@ -152,7 +152,7 @@ fn add_function_impl(
|
|||
let completion_kind = if func.self_param(ctx.db).is_some() {
|
||||
CompletionItemKind::Method
|
||||
} else {
|
||||
CompletionItemKind::Function
|
||||
CompletionItemKind::SymbolKind(SymbolKind::Function)
|
||||
};
|
||||
let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
|
||||
|
||||
|
@ -188,7 +188,7 @@ fn add_type_alias_impl(
|
|||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
||||
.text_edit(TextEdit::replace(range, snippet))
|
||||
.lookup_by(alias_name)
|
||||
.kind(CompletionItemKind::TypeAlias)
|
||||
.kind(SymbolKind::TypeAlias)
|
||||
.set_documentation(type_alias.docs(ctx.db))
|
||||
.add_to(acc);
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ fn add_const_impl(
|
|||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
||||
.text_edit(TextEdit::replace(range, snippet))
|
||||
.lookup_by(const_name)
|
||||
.kind(CompletionItemKind::Const)
|
||||
.kind(SymbolKind::Const)
|
||||
.set_documentation(const_.docs(ctx.db))
|
||||
.add_to(acc);
|
||||
}
|
||||
|
|
|
@ -165,8 +165,8 @@ fn quux(x: i32) {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
bn y i32
|
||||
bn x i32
|
||||
lc y i32
|
||||
lc x i32
|
||||
fn quux(…) fn quux(x: i32)
|
||||
"#]],
|
||||
);
|
||||
|
@ -187,8 +187,8 @@ fn quux() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
bn b i32
|
||||
bn a
|
||||
lc b i32
|
||||
lc a
|
||||
fn quux() fn quux()
|
||||
"#]],
|
||||
);
|
||||
|
@ -203,7 +203,7 @@ fn quux() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
bn x
|
||||
lc x
|
||||
fn quux() fn quux()
|
||||
"#]],
|
||||
);
|
||||
|
@ -241,7 +241,7 @@ fn main() {
|
|||
check(
|
||||
r#"fn quux<const C: usize>() { $0 }"#,
|
||||
expect![[r#"
|
||||
tp C
|
||||
cp C
|
||||
fn quux() fn quux<const C: usize>()
|
||||
"#]],
|
||||
);
|
||||
|
@ -263,7 +263,7 @@ fn main() {
|
|||
check(
|
||||
r#"struct S<T> { x: $0}"#,
|
||||
expect![[r#"
|
||||
tp Self
|
||||
sp Self
|
||||
tp T
|
||||
st S<…>
|
||||
"#]],
|
||||
|
@ -275,7 +275,7 @@ fn main() {
|
|||
check(
|
||||
r#"enum X { Y($0) }"#,
|
||||
expect![[r#"
|
||||
tp Self
|
||||
sp Self
|
||||
en X
|
||||
"#]],
|
||||
);
|
||||
|
@ -378,8 +378,8 @@ fn foo() {
|
|||
"#,
|
||||
// FIXME: should be only one bar here
|
||||
expect![[r#"
|
||||
bn bar i32
|
||||
bn bar i32
|
||||
lc bar i32
|
||||
lc bar i32
|
||||
fn foo() fn foo()
|
||||
"#]],
|
||||
);
|
||||
|
@ -390,8 +390,8 @@ fn foo() {
|
|||
check(
|
||||
r#"impl S { fn foo(&self) { $0 } }"#,
|
||||
expect![[r#"
|
||||
bn self &{unknown}
|
||||
tp Self
|
||||
lc self &{unknown}
|
||||
sp Self
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -575,8 +575,8 @@ fn quux(x: i32) {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
bn y i32
|
||||
bn x i32
|
||||
lc y i32
|
||||
lc x i32
|
||||
fn quux(…) fn quux(x: i32)
|
||||
ma m!(…) macro_rules! m
|
||||
"#]],
|
||||
|
@ -594,8 +594,8 @@ fn quux(x: i32) {
|
|||
}
|
||||
",
|
||||
expect![[r#"
|
||||
bn y i32
|
||||
bn x i32
|
||||
lc y i32
|
||||
lc x i32
|
||||
fn quux(…) fn quux(x: i32)
|
||||
ma m!(…) macro_rules! m
|
||||
"#]],
|
||||
|
@ -613,8 +613,8 @@ fn quux(x: i32) {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
bn y i32
|
||||
bn x i32
|
||||
lc y i32
|
||||
lc x i32
|
||||
fn quux(…) fn quux(x: i32)
|
||||
ma m!(…) macro_rules! m
|
||||
"#]],
|
||||
|
@ -750,7 +750,7 @@ struct MyStruct {}
|
|||
impl My$0
|
||||
"#,
|
||||
expect![[r#"
|
||||
tp Self
|
||||
sp Self
|
||||
tt MyTrait
|
||||
st MyStruct
|
||||
"#]],
|
||||
|
|
|
@ -3,11 +3,14 @@
|
|||
use std::fmt;
|
||||
|
||||
use hir::{Documentation, ModPath, Mutability};
|
||||
use ide_db::helpers::{
|
||||
insert_use::{self, ImportScope, MergeBehavior},
|
||||
mod_path_to_ast, SnippetCap,
|
||||
use ide_db::{
|
||||
helpers::{
|
||||
insert_use::{self, ImportScope, MergeBehavior},
|
||||
mod_path_to_ast, SnippetCap,
|
||||
},
|
||||
SymbolKind,
|
||||
};
|
||||
use stdx::assert_never;
|
||||
use stdx::{assert_never, impl_from};
|
||||
use syntax::{algo, TextRange};
|
||||
use text_edit::TextEdit;
|
||||
|
||||
|
@ -117,49 +120,50 @@ pub enum CompletionScore {
|
|||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CompletionItemKind {
|
||||
Snippet,
|
||||
Keyword,
|
||||
Module,
|
||||
Function,
|
||||
BuiltinType,
|
||||
Struct,
|
||||
Enum,
|
||||
EnumVariant,
|
||||
Binding,
|
||||
Field,
|
||||
Static,
|
||||
Const,
|
||||
Trait,
|
||||
TypeAlias,
|
||||
Method,
|
||||
TypeParam,
|
||||
Macro,
|
||||
SymbolKind(SymbolKind),
|
||||
Attribute,
|
||||
Binding,
|
||||
BuiltinType,
|
||||
Keyword,
|
||||
Method,
|
||||
Snippet,
|
||||
UnresolvedReference,
|
||||
}
|
||||
|
||||
impl_from!(SymbolKind for CompletionItemKind);
|
||||
|
||||
impl CompletionItemKind {
|
||||
#[cfg(test)]
|
||||
pub(crate) fn tag(&self) -> &'static str {
|
||||
match self {
|
||||
CompletionItemKind::SymbolKind(kind) => match kind {
|
||||
SymbolKind::Const => "ct",
|
||||
SymbolKind::ConstParam => "cp",
|
||||
SymbolKind::Enum => "en",
|
||||
SymbolKind::Field => "fd",
|
||||
SymbolKind::Function => "fn",
|
||||
SymbolKind::Impl => "im",
|
||||
SymbolKind::Label => "lb",
|
||||
SymbolKind::LifetimeParam => "lt",
|
||||
SymbolKind::Local => "lc",
|
||||
SymbolKind::Macro => "ma",
|
||||
SymbolKind::Module => "md",
|
||||
SymbolKind::SelfParam => "sp",
|
||||
SymbolKind::Static => "sc",
|
||||
SymbolKind::Struct => "st",
|
||||
SymbolKind::Trait => "tt",
|
||||
SymbolKind::TypeAlias => "ta",
|
||||
SymbolKind::TypeParam => "tp",
|
||||
SymbolKind::Union => "un",
|
||||
SymbolKind::ValueParam => "vp",
|
||||
SymbolKind::Variant => "ev",
|
||||
},
|
||||
CompletionItemKind::Attribute => "at",
|
||||
CompletionItemKind::Binding => "bn",
|
||||
CompletionItemKind::BuiltinType => "bt",
|
||||
CompletionItemKind::Const => "ct",
|
||||
CompletionItemKind::Enum => "en",
|
||||
CompletionItemKind::EnumVariant => "ev",
|
||||
CompletionItemKind::Field => "fd",
|
||||
CompletionItemKind::Function => "fn",
|
||||
CompletionItemKind::Keyword => "kw",
|
||||
CompletionItemKind::Macro => "ma",
|
||||
CompletionItemKind::Method => "me",
|
||||
CompletionItemKind::Module => "md",
|
||||
CompletionItemKind::Snippet => "sn",
|
||||
CompletionItemKind::Static => "sc",
|
||||
CompletionItemKind::Struct => "st",
|
||||
CompletionItemKind::Trait => "tt",
|
||||
CompletionItemKind::TypeAlias => "ta",
|
||||
CompletionItemKind::TypeParam => "tp",
|
||||
CompletionItemKind::UnresolvedReference => "??",
|
||||
}
|
||||
}
|
||||
|
@ -382,8 +386,8 @@ impl Builder {
|
|||
self.insert_text_format = InsertTextFormat::Snippet;
|
||||
self.insert_text(snippet)
|
||||
}
|
||||
pub(crate) fn kind(mut self, kind: CompletionItemKind) -> Builder {
|
||||
self.kind = Some(kind);
|
||||
pub(crate) fn kind(mut self, kind: impl Into<CompletionItemKind>) -> Builder {
|
||||
self.kind = Some(kind.into());
|
||||
self
|
||||
}
|
||||
pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder {
|
||||
|
|
|
@ -13,7 +13,7 @@ mod builder_ext;
|
|||
use hir::{
|
||||
AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
|
||||
};
|
||||
use ide_db::{helpers::SnippetCap, RootDatabase};
|
||||
use ide_db::{helpers::SnippetCap, RootDatabase, SymbolKind};
|
||||
use syntax::TextRange;
|
||||
use test_utils::mark;
|
||||
|
||||
|
@ -146,7 +146,7 @@ impl<'a> Render<'a> {
|
|||
self.ctx.source_range(),
|
||||
name.to_string(),
|
||||
)
|
||||
.kind(CompletionItemKind::Field)
|
||||
.kind(SymbolKind::Field)
|
||||
.detail(ty.display(self.ctx.db()).to_string())
|
||||
.set_documentation(field.docs(self.ctx.db()))
|
||||
.set_deprecated(is_deprecated);
|
||||
|
@ -160,7 +160,7 @@ impl<'a> Render<'a> {
|
|||
|
||||
fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem {
|
||||
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), field.to_string())
|
||||
.kind(CompletionItemKind::Field)
|
||||
.kind(SymbolKind::Field)
|
||||
.detail(ty.display(self.ctx.db()).to_string())
|
||||
.build()
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ impl<'a> Render<'a> {
|
|||
if self.ctx.completion.is_pat_binding_or_const
|
||||
| self.ctx.completion.is_irrefutable_pat_binding =>
|
||||
{
|
||||
CompletionItemKind::EnumVariant
|
||||
CompletionItemKind::SymbolKind(SymbolKind::Variant)
|
||||
}
|
||||
ScopeDef::ModuleDef(Variant(var)) => {
|
||||
let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None);
|
||||
|
@ -198,20 +198,29 @@ impl<'a> Render<'a> {
|
|||
return item;
|
||||
}
|
||||
|
||||
ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::Module,
|
||||
ScopeDef::ModuleDef(Adt(hir::Adt::Struct(_))) => CompletionItemKind::Struct,
|
||||
// FIXME: add CompletionItemKind::Union
|
||||
ScopeDef::ModuleDef(Adt(hir::Adt::Union(_))) => CompletionItemKind::Struct,
|
||||
ScopeDef::ModuleDef(Adt(hir::Adt::Enum(_))) => CompletionItemKind::Enum,
|
||||
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::Const,
|
||||
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::Static,
|
||||
ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::Trait,
|
||||
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias,
|
||||
ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module),
|
||||
ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt {
|
||||
hir::Adt::Struct(_) => SymbolKind::Struct,
|
||||
// FIXME: add CompletionItemKind::Union
|
||||
hir::Adt::Union(_) => SymbolKind::Struct,
|
||||
hir::Adt::Enum(_) => SymbolKind::Enum,
|
||||
}),
|
||||
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const),
|
||||
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::SymbolKind(SymbolKind::Static),
|
||||
ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::SymbolKind(SymbolKind::Trait),
|
||||
ScopeDef::ModuleDef(TypeAlias(..)) => {
|
||||
CompletionItemKind::SymbolKind(SymbolKind::TypeAlias)
|
||||
}
|
||||
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
||||
ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam,
|
||||
ScopeDef::Local(..) => CompletionItemKind::Binding,
|
||||
// (does this need its own kind?)
|
||||
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
|
||||
ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param {
|
||||
hir::GenericParam::TypeParam(_) => SymbolKind::TypeParam,
|
||||
hir::GenericParam::LifetimeParam(_) => SymbolKind::LifetimeParam,
|
||||
hir::GenericParam::ConstParam(_) => SymbolKind::ConstParam,
|
||||
}),
|
||||
ScopeDef::Local(..) => CompletionItemKind::SymbolKind(SymbolKind::Local),
|
||||
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => {
|
||||
CompletionItemKind::SymbolKind(SymbolKind::SelfParam)
|
||||
}
|
||||
ScopeDef::Unknown => {
|
||||
let item = CompletionItem::new(
|
||||
CompletionKind::Reference,
|
||||
|
@ -400,7 +409,9 @@ fn main() { Foo::Fo$0 }
|
|||
source_range: 54..56,
|
||||
delete: 54..56,
|
||||
insert: "Foo",
|
||||
kind: EnumVariant,
|
||||
kind: SymbolKind(
|
||||
Variant,
|
||||
),
|
||||
detail: "{ x: i32, y: i32 }",
|
||||
},
|
||||
]
|
||||
|
@ -423,7 +434,9 @@ fn main() { Foo::Fo$0 }
|
|||
source_range: 46..48,
|
||||
delete: 46..48,
|
||||
insert: "Foo($0)",
|
||||
kind: EnumVariant,
|
||||
kind: SymbolKind(
|
||||
Variant,
|
||||
),
|
||||
lookup: "Foo",
|
||||
detail: "(i32, i32)",
|
||||
trigger_call_info: true,
|
||||
|
@ -448,7 +461,9 @@ fn main() { Foo::Fo$0 }
|
|||
source_range: 35..37,
|
||||
delete: 35..37,
|
||||
insert: "Foo",
|
||||
kind: EnumVariant,
|
||||
kind: SymbolKind(
|
||||
Variant,
|
||||
),
|
||||
detail: "()",
|
||||
},
|
||||
]
|
||||
|
@ -472,7 +487,9 @@ fn main() { let _: m::Spam = S$0 }
|
|||
source_range: 75..76,
|
||||
delete: 75..76,
|
||||
insert: "Spam::Bar($0)",
|
||||
kind: EnumVariant,
|
||||
kind: SymbolKind(
|
||||
Variant,
|
||||
),
|
||||
lookup: "Spam::Bar",
|
||||
detail: "(i32)",
|
||||
trigger_call_info: true,
|
||||
|
@ -482,14 +499,18 @@ fn main() { let _: m::Spam = S$0 }
|
|||
source_range: 75..76,
|
||||
delete: 75..76,
|
||||
insert: "m",
|
||||
kind: Module,
|
||||
kind: SymbolKind(
|
||||
Module,
|
||||
),
|
||||
},
|
||||
CompletionItem {
|
||||
label: "m::Spam::Foo",
|
||||
source_range: 75..76,
|
||||
delete: 75..76,
|
||||
insert: "m::Spam::Foo",
|
||||
kind: EnumVariant,
|
||||
kind: SymbolKind(
|
||||
Variant,
|
||||
),
|
||||
lookup: "Spam::Foo",
|
||||
detail: "()",
|
||||
},
|
||||
|
@ -498,7 +519,9 @@ fn main() { let _: m::Spam = S$0 }
|
|||
source_range: 75..76,
|
||||
delete: 75..76,
|
||||
insert: "main()$0",
|
||||
kind: Function,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
lookup: "main",
|
||||
detail: "fn main()",
|
||||
},
|
||||
|
@ -525,7 +548,9 @@ fn main() { som$0 }
|
|||
source_range: 127..130,
|
||||
delete: 127..130,
|
||||
insert: "main()$0",
|
||||
kind: Function,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
lookup: "main",
|
||||
detail: "fn main()",
|
||||
},
|
||||
|
@ -534,7 +559,9 @@ fn main() { som$0 }
|
|||
source_range: 127..130,
|
||||
delete: 127..130,
|
||||
insert: "something_deprecated()$0",
|
||||
kind: Function,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
lookup: "something_deprecated",
|
||||
detail: "fn something_deprecated()",
|
||||
deprecated: true,
|
||||
|
@ -544,7 +571,9 @@ fn main() { som$0 }
|
|||
source_range: 127..130,
|
||||
delete: 127..130,
|
||||
insert: "something_else_deprecated()$0",
|
||||
kind: Function,
|
||||
kind: SymbolKind(
|
||||
Function,
|
||||
),
|
||||
lookup: "something_else_deprecated",
|
||||
detail: "fn something_else_deprecated()",
|
||||
deprecated: true,
|
||||
|
@ -565,7 +594,9 @@ fn foo() { A { the$0 } }
|
|||
source_range: 57..60,
|
||||
delete: 57..60,
|
||||
insert: "the_field",
|
||||
kind: Field,
|
||||
kind: SymbolKind(
|
||||
Field,
|
||||
),
|
||||
detail: "u32",
|
||||
deprecated: true,
|
||||
},
|
||||
|
@ -605,7 +636,9 @@ impl S {
|
|||
source_range: 94..94,
|
||||
delete: 94..94,
|
||||
insert: "foo",
|
||||
kind: Field,
|
||||
kind: SymbolKind(
|
||||
Field,
|
||||
),
|
||||
detail: "{unknown}",
|
||||
documentation: Documentation(
|
||||
"Field docs",
|
||||
|
@ -636,7 +669,9 @@ use self::E::*;
|
|||
source_range: 10..12,
|
||||
delete: 10..12,
|
||||
insert: "E",
|
||||
kind: Enum,
|
||||
kind: SymbolKind(
|
||||
Enum,
|
||||
),
|
||||
documentation: Documentation(
|
||||
"enum docs",
|
||||
),
|
||||
|
@ -646,7 +681,9 @@ use self::E::*;
|
|||
source_range: 10..12,
|
||||
delete: 10..12,
|
||||
insert: "V",
|
||||
kind: EnumVariant,
|
||||
kind: SymbolKind(
|
||||
Variant,
|
||||
),
|
||||
detail: "()",
|
||||
documentation: Documentation(
|
||||
"variant docs",
|
||||
|
@ -657,7 +694,9 @@ use self::E::*;
|
|||
source_range: 10..12,
|
||||
delete: 10..12,
|
||||
insert: "my",
|
||||
kind: Module,
|
||||
kind: SymbolKind(
|
||||
Module,
|
||||
),
|
||||
documentation: Documentation(
|
||||
"mod docs",
|
||||
),
|
||||
|
@ -883,7 +922,7 @@ struct WorldSnapshot { _f: () };
|
|||
fn go(world: &WorldSnapshot) { go(w$0) }
|
||||
"#,
|
||||
expect![[r#"
|
||||
bn world [type+name]
|
||||
lc world [type+name]
|
||||
st WorldSnapshot []
|
||||
fn go(…) []
|
||||
"#]],
|
||||
|
@ -900,7 +939,7 @@ fn f(foo: &Foo) { f(foo, w$0) }
|
|||
expect![[r#"
|
||||
st Foo []
|
||||
fn f(…) []
|
||||
bn foo []
|
||||
lc foo []
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
//! Renderer for `const` fields.
|
||||
|
||||
use hir::HasSource;
|
||||
use ide_db::SymbolKind;
|
||||
use syntax::{
|
||||
ast::{Const, NameOwner},
|
||||
display::const_label,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
||||
item::{CompletionItem, CompletionKind},
|
||||
render::RenderContext,
|
||||
};
|
||||
|
||||
|
@ -36,7 +37,7 @@ impl<'a> ConstRender<'a> {
|
|||
let detail = self.detail();
|
||||
|
||||
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
||||
.kind(CompletionItemKind::Const)
|
||||
.kind(SymbolKind::Const)
|
||||
.set_documentation(self.ctx.docs(self.const_))
|
||||
.set_deprecated(
|
||||
self.ctx.is_deprecated(self.const_)
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
//! Renderer for `enum` variants.
|
||||
|
||||
use hir::{HasAttrs, HirDisplay, ModPath, StructKind};
|
||||
use ide_db::SymbolKind;
|
||||
use itertools::Itertools;
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit},
|
||||
item::{CompletionItem, CompletionKind, ImportEdit},
|
||||
render::{builder_ext::Params, RenderContext},
|
||||
};
|
||||
|
||||
|
@ -60,7 +61,7 @@ impl<'a> EnumRender<'a> {
|
|||
self.ctx.source_range(),
|
||||
self.qualified_name.clone(),
|
||||
)
|
||||
.kind(CompletionItemKind::EnumVariant)
|
||||
.kind(SymbolKind::Variant)
|
||||
.set_documentation(self.variant.docs(self.ctx.db()))
|
||||
.set_deprecated(self.ctx.is_deprecated(self.variant))
|
||||
.add_import(import_to_add)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
//! Renderer for function calls.
|
||||
|
||||
use hir::{HasSource, Type};
|
||||
use ide_db::SymbolKind;
|
||||
use syntax::{ast::Fn, display::function_declaration};
|
||||
use test_utils::mark;
|
||||
|
||||
|
@ -105,7 +106,7 @@ impl<'a> FunctionRender<'a> {
|
|||
if self.func.self_param(self.ctx.db()).is_some() {
|
||||
CompletionItemKind::Method
|
||||
} else {
|
||||
CompletionItemKind::Function
|
||||
SymbolKind::Function.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
//! Renderer for macro invocations.
|
||||
|
||||
use hir::{Documentation, HasSource};
|
||||
use ide_db::SymbolKind;
|
||||
use syntax::display::macro_label;
|
||||
use test_utils::mark;
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit},
|
||||
item::{CompletionItem, CompletionKind, ImportEdit},
|
||||
render::RenderContext,
|
||||
};
|
||||
|
||||
|
@ -41,7 +42,7 @@ impl<'a> MacroRender<'a> {
|
|||
fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> {
|
||||
let mut builder =
|
||||
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label())
|
||||
.kind(CompletionItemKind::Macro)
|
||||
.kind(SymbolKind::Macro)
|
||||
.set_documentation(self.docs.clone())
|
||||
.set_deprecated(self.ctx.is_deprecated(self.macro_))
|
||||
.add_import(import_to_add)
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
//! Renderer for type aliases.
|
||||
|
||||
use hir::HasSource;
|
||||
use ide_db::SymbolKind;
|
||||
use syntax::{
|
||||
ast::{NameOwner, TypeAlias},
|
||||
display::type_label,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
||||
item::{CompletionItem, CompletionKind},
|
||||
render::RenderContext,
|
||||
};
|
||||
|
||||
|
@ -36,7 +37,7 @@ impl<'a> TypeAliasRender<'a> {
|
|||
let detail = self.detail();
|
||||
|
||||
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
||||
.kind(CompletionItemKind::TypeAlias)
|
||||
.kind(SymbolKind::TypeAlias)
|
||||
.set_documentation(self.ctx.docs(self.type_alias))
|
||||
.set_deprecated(
|
||||
self.ctx.is_deprecated(self.type_alias)
|
||||
|
|
|
@ -7,6 +7,7 @@ use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, Mo
|
|||
use ide_db::{
|
||||
base_db::{FileId, FileRange, SourceDatabase},
|
||||
symbol_index::FileSymbolKind,
|
||||
SymbolKind,
|
||||
};
|
||||
use ide_db::{defs::Definition, RootDatabase};
|
||||
use syntax::{
|
||||
|
@ -18,30 +19,6 @@ use crate::FileSymbol;
|
|||
|
||||
use super::short_label::ShortLabel;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum SymbolKind {
|
||||
Module,
|
||||
Impl,
|
||||
Field,
|
||||
TypeParam,
|
||||
ConstParam,
|
||||
LifetimeParam,
|
||||
ValueParam,
|
||||
SelfParam,
|
||||
Local,
|
||||
Label,
|
||||
Function,
|
||||
Const,
|
||||
Static,
|
||||
Struct,
|
||||
Enum,
|
||||
Variant,
|
||||
Union,
|
||||
TypeAlias,
|
||||
Trait,
|
||||
Macro,
|
||||
}
|
||||
|
||||
/// `NavigationTarget` represents and element in the editor's UI which you can
|
||||
/// click on to navigate to a particular piece of code.
|
||||
///
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use ide_db::SymbolKind;
|
||||
use syntax::{
|
||||
ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
|
||||
match_ast, AstNode, SourceFile, SyntaxNode, TextRange, WalkEvent,
|
||||
};
|
||||
|
||||
use crate::SymbolKind;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StructureNode {
|
||||
pub parent: Option<usize>,
|
||||
|
|
|
@ -65,7 +65,7 @@ use crate::display::ToNav;
|
|||
pub use crate::{
|
||||
call_hierarchy::CallItem,
|
||||
diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
|
||||
display::navigation_target::{NavigationTarget, SymbolKind},
|
||||
display::navigation_target::NavigationTarget,
|
||||
expand_macro::ExpandedMacro,
|
||||
file_structure::StructureNode,
|
||||
folding_ranges::{Fold, FoldKind},
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt;
|
|||
use assists::utils::test_related_attribute;
|
||||
use cfg::CfgExpr;
|
||||
use hir::{AsAssocItem, HasAttrs, HasSource, Semantics};
|
||||
use ide_db::{defs::Definition, RootDatabase};
|
||||
use ide_db::{defs::Definition, RootDatabase, SymbolKind};
|
||||
use itertools::Itertools;
|
||||
use syntax::{
|
||||
ast::{self, AstNode, AttrsOwner},
|
||||
|
@ -13,7 +13,7 @@ use test_utils::mark;
|
|||
|
||||
use crate::{
|
||||
display::{ToNav, TryToNav},
|
||||
FileId, NavigationTarget, SymbolKind,
|
||||
FileId, NavigationTarget,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
@ -13,7 +13,7 @@ mod html;
|
|||
mod tests;
|
||||
|
||||
use hir::{Name, Semantics};
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::{RootDatabase, SymbolKind};
|
||||
use rustc_hash::FxHashMap;
|
||||
use syntax::{
|
||||
ast::{self, HasFormatSpecifier},
|
||||
|
@ -27,7 +27,7 @@ use crate::{
|
|||
format::highlight_format_string, highlights::Highlights,
|
||||
macro_rules::MacroRulesHighlighter, tags::Highlight,
|
||||
},
|
||||
FileId, HlMod, HlTag, SymbolKind,
|
||||
FileId, HlMod, HlTag,
|
||||
};
|
||||
|
||||
pub(crate) use html::highlight_as_html;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
//! Syntax highlighting for format macro strings.
|
||||
use ide_db::SymbolKind;
|
||||
use syntax::{
|
||||
ast::{self, FormatSpecifier, HasFormatSpecifier},
|
||||
AstNode, AstToken, TextRange,
|
||||
};
|
||||
|
||||
use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag, SymbolKind};
|
||||
use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag};
|
||||
|
||||
pub(super) fn highlight_format_string(
|
||||
stack: &mut Highlights,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use hir::{AsAssocItem, Semantics, VariantDef};
|
||||
use ide_db::{
|
||||
defs::{Definition, NameClass, NameRefClass},
|
||||
RootDatabase,
|
||||
RootDatabase, SymbolKind,
|
||||
};
|
||||
use rustc_hash::FxHashMap;
|
||||
use syntax::{
|
||||
|
@ -12,7 +12,7 @@ use syntax::{
|
|||
SyntaxNode, SyntaxToken, T,
|
||||
};
|
||||
|
||||
use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag, SymbolKind};
|
||||
use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag};
|
||||
|
||||
pub(super) fn element(
|
||||
sema: &Semantics<RootDatabase>,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
use std::{fmt, ops};
|
||||
|
||||
use crate::SymbolKind;
|
||||
use ide_db::SymbolKind;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct Highlight {
|
||||
|
|
|
@ -134,3 +134,27 @@ fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
|
|||
let text = db.file_text(file_id);
|
||||
Arc::new(LineIndex::new(&*text))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub enum SymbolKind {
|
||||
Const,
|
||||
ConstParam,
|
||||
Enum,
|
||||
Field,
|
||||
Function,
|
||||
Impl,
|
||||
Label,
|
||||
LifetimeParam,
|
||||
Local,
|
||||
Macro,
|
||||
Module,
|
||||
SelfParam,
|
||||
Static,
|
||||
Struct,
|
||||
Trait,
|
||||
TypeAlias,
|
||||
TypeParam,
|
||||
Union,
|
||||
ValueParam,
|
||||
Variant,
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ use std::{
|
|||
|
||||
use ide::{
|
||||
FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, LineIndex, NavigationTarget,
|
||||
Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, SymbolKind, TextEdit,
|
||||
Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit,
|
||||
};
|
||||
use ide_db::SymbolKind;
|
||||
use itertools::Itertools;
|
||||
use lsp_server::ErrorCode;
|
||||
use lsp_types::{
|
||||
|
|
|
@ -8,8 +8,9 @@ use ide::{
|
|||
Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
|
||||
FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel,
|
||||
InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess,
|
||||
RenameError, Runnable, Severity, SourceChange, SymbolKind, TextEdit, TextRange, TextSize,
|
||||
RenameError, Runnable, Severity, SourceChange, TextEdit, TextRange, TextSize,
|
||||
};
|
||||
use ide_db::SymbolKind;
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
|
@ -87,25 +88,35 @@ pub(crate) fn completion_item_kind(
|
|||
completion_item_kind: CompletionItemKind,
|
||||
) -> lsp_types::CompletionItemKind {
|
||||
match completion_item_kind {
|
||||
CompletionItemKind::Keyword => lsp_types::CompletionItemKind::Keyword,
|
||||
CompletionItemKind::Snippet => lsp_types::CompletionItemKind::Snippet,
|
||||
CompletionItemKind::Module => lsp_types::CompletionItemKind::Module,
|
||||
CompletionItemKind::Function => lsp_types::CompletionItemKind::Function,
|
||||
CompletionItemKind::Struct => lsp_types::CompletionItemKind::Struct,
|
||||
CompletionItemKind::Enum => lsp_types::CompletionItemKind::Enum,
|
||||
CompletionItemKind::EnumVariant => lsp_types::CompletionItemKind::EnumMember,
|
||||
CompletionItemKind::BuiltinType => lsp_types::CompletionItemKind::Struct,
|
||||
CompletionItemKind::Binding => lsp_types::CompletionItemKind::Variable,
|
||||
CompletionItemKind::Field => lsp_types::CompletionItemKind::Field,
|
||||
CompletionItemKind::Trait => lsp_types::CompletionItemKind::Interface,
|
||||
CompletionItemKind::TypeAlias => lsp_types::CompletionItemKind::Struct,
|
||||
CompletionItemKind::Const => lsp_types::CompletionItemKind::Constant,
|
||||
CompletionItemKind::Static => lsp_types::CompletionItemKind::Value,
|
||||
CompletionItemKind::Method => lsp_types::CompletionItemKind::Method,
|
||||
CompletionItemKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||
CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method,
|
||||
CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember,
|
||||
CompletionItemKind::Binding => lsp_types::CompletionItemKind::Variable,
|
||||
CompletionItemKind::BuiltinType => lsp_types::CompletionItemKind::Struct,
|
||||
CompletionItemKind::Keyword => lsp_types::CompletionItemKind::Keyword,
|
||||
CompletionItemKind::Method => lsp_types::CompletionItemKind::Method,
|
||||
CompletionItemKind::Snippet => lsp_types::CompletionItemKind::Snippet,
|
||||
CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::Reference,
|
||||
CompletionItemKind::SymbolKind(symbol) => match symbol {
|
||||
SymbolKind::Const => lsp_types::CompletionItemKind::Constant,
|
||||
SymbolKind::ConstParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||
SymbolKind::Enum => lsp_types::CompletionItemKind::Enum,
|
||||
SymbolKind::Field => lsp_types::CompletionItemKind::Field,
|
||||
SymbolKind::Function => lsp_types::CompletionItemKind::Function,
|
||||
SymbolKind::Impl => lsp_types::CompletionItemKind::Text,
|
||||
SymbolKind::Label => lsp_types::CompletionItemKind::Variable,
|
||||
SymbolKind::LifetimeParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||
SymbolKind::Local => lsp_types::CompletionItemKind::Variable,
|
||||
SymbolKind::Macro => lsp_types::CompletionItemKind::Method,
|
||||
SymbolKind::Module => lsp_types::CompletionItemKind::Module,
|
||||
SymbolKind::SelfParam => lsp_types::CompletionItemKind::Value,
|
||||
SymbolKind::Static => lsp_types::CompletionItemKind::Value,
|
||||
SymbolKind::Struct => lsp_types::CompletionItemKind::Struct,
|
||||
SymbolKind::Trait => lsp_types::CompletionItemKind::Interface,
|
||||
SymbolKind::TypeAlias => lsp_types::CompletionItemKind::Struct,
|
||||
SymbolKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||
SymbolKind::Union => lsp_types::CompletionItemKind::Struct,
|
||||
SymbolKind::ValueParam => lsp_types::CompletionItemKind::Value,
|
||||
SymbolKind::Variant => lsp_types::CompletionItemKind::EnumMember,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue