diff --git a/crates/completion/src/completions/fn_param.rs b/crates/completion/src/completions/fn_param.rs index 5505c35594..38e33a93e8 100644 --- a/crates/completion/src/completions/fn_param.rs +++ b/crates/completion/src/completions/fn_param.rs @@ -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) }); diff --git a/crates/completion/src/completions/mod_.rs b/crates/completion/src/completions/mod_.rs index 00e951ca95..352fc7c777 100644 --- a/crates/completion/src/completions/mod_.rs +++ b/crates/completion/src/completions/mod_.rs @@ -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) }); diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs index bb6354ded2..0a7927eb83 100644 --- a/crates/completion/src/completions/record.rs +++ b/crates/completion/src/completions/record.rs @@ -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(), ); } diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs index 135ae49dc1..f258ad9c3f 100644 --- a/crates/completion/src/completions/trait_impl.rs +++ b/crates/completion/src/completions/trait_impl.rs @@ -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); } diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index 809e1645ad..a289efc34e 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -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() { $0 }"#, expect![[r#" - tp C + cp C fn quux() fn quux() "#]], ); @@ -263,7 +263,7 @@ fn main() { check( r#"struct S { 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 "#]], diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 4147853e7f..d2e6a6aeb4 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs @@ -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) -> Builder { + self.kind = Some(kind.into()); self } pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder { diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index 4f622d28ae..fa594b5e52 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -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 [] "#]], ); } diff --git a/crates/completion/src/render/const_.rs b/crates/completion/src/render/const_.rs index e46452d4e4..5010b642a3 100644 --- a/crates/completion/src/render/const_.rs +++ b/crates/completion/src/render/const_.rs @@ -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_) diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs index 89fb49773d..adcddebd13 100644 --- a/crates/completion/src/render/enum_variant.rs +++ b/crates/completion/src/render/enum_variant.rs @@ -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) diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index 8f4c662114..2d616b1fb5 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs @@ -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() } } } diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index f893e420a2..a4535786f2 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs @@ -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) -> Option { 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) diff --git a/crates/completion/src/render/type_alias.rs b/crates/completion/src/render/type_alias.rs index 29287143a5..bd97c3692d 100644 --- a/crates/completion/src/render/type_alias.rs +++ b/crates/completion/src/render/type_alias.rs @@ -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) diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 9c568c90c3..16fa828ad3 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -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. /// diff --git a/crates/ide/src/file_structure.rs b/crates/ide/src/file_structure.rs index 32556dad33..26793bdb44 100644 --- a/crates/ide/src/file_structure.rs +++ b/crates/ide/src/file_structure.rs @@ -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, diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 567b8117eb..989e94a31f 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -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}, diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 975abf47f9..33170906d8 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -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)] diff --git a/crates/ide/src/syntax_highlighting.rs b/crates/ide/src/syntax_highlighting.rs index f2d4da78d0..a3d4e4f77a 100644 --- a/crates/ide/src/syntax_highlighting.rs +++ b/crates/ide/src/syntax_highlighting.rs @@ -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; diff --git a/crates/ide/src/syntax_highlighting/format.rs b/crates/ide/src/syntax_highlighting/format.rs index 8a9b5ca8c4..8c67a0863c 100644 --- a/crates/ide/src/syntax_highlighting/format.rs +++ b/crates/ide/src/syntax_highlighting/format.rs @@ -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, diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 8625ef5dfc..24fcbb5845 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -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, diff --git a/crates/ide/src/syntax_highlighting/tags.rs b/crates/ide/src/syntax_highlighting/tags.rs index 8dd05ac524..3c02fdb115 100644 --- a/crates/ide/src/syntax_highlighting/tags.rs +++ b/crates/ide/src/syntax_highlighting/tags.rs @@ -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 { diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs index 118c090d75..6eb34b06b7 100644 --- a/crates/ide_db/src/lib.rs +++ b/crates/ide_db/src/lib.rs @@ -134,3 +134,27 @@ fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc { 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, +} diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index 42451cd2d5..809452e6d0 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -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::{ diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs index 0e35500027..96f915f1ce 100644 --- a/crates/rust-analyzer/src/to_proto.rs +++ b/crates/rust-analyzer/src/to_proto.rs @@ -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, + }, } }