From dc3848a6a3e659004ba4f2160503be28ea0f9051 Mon Sep 17 00:00:00 2001 From: Martin Asquino Date: Fri, 1 Nov 2019 23:52:59 -0300 Subject: Set `deprecated` field on `CompletionItem`s --- crates/ra_ide_api/src/completion/complete_dot.rs | 11 +++ .../completion/complete_macro_in_item_position.rs | 4 ++ crates/ra_ide_api/src/completion/complete_path.rs | 17 +++++ .../src/completion/complete_record_literal.rs | 32 +++++++++ .../src/completion/complete_record_pattern.rs | 3 + crates/ra_ide_api/src/completion/complete_scope.rs | 19 +++++ .../ra_ide_api/src/completion/completion_item.rs | 17 +++++ crates/ra_ide_api/src/completion/presentation.rs | 83 +++++++++++++++++++++- 8 files changed, 185 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index b4df6ee2a..9c0abd590 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -96,6 +96,7 @@ mod tests { ⋮ insert: "the_field", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "### @@ -128,6 +129,7 @@ mod tests { kind: Method, lookup: "foo", detail: "fn foo(self)", + deprecated: false, }, CompletionItem { label: "the_field", @@ -139,6 +141,7 @@ mod tests { documentation: Documentation( "This is the_field", ), + deprecated: false, }, ] "### @@ -168,6 +171,7 @@ mod tests { kind: Method, lookup: "foo", detail: "fn foo(&self)", + deprecated: false, }, CompletionItem { label: "the_field", @@ -176,6 +180,7 @@ mod tests { insert: "the_field", kind: Field, detail: "(u32, i32)", + deprecated: false, }, ] "### @@ -221,6 +226,7 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", + deprecated: false, }, ] "### @@ -250,6 +256,7 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", + deprecated: false, }, ] "### @@ -279,6 +286,7 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", + deprecated: false, }, ] "### @@ -331,6 +339,7 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", + deprecated: false, }, ] "### @@ -401,6 +410,7 @@ mod tests { kind: Method, lookup: "blah", detail: "pub fn blah(&self)", + deprecated: false, }, ] "### @@ -427,6 +437,7 @@ mod tests { ⋮ insert: "the_field", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "### diff --git a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs index 09f743c66..a082a3c7c 100644 --- a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs @@ -45,6 +45,7 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", + deprecated: false, }, ]"## ); @@ -86,6 +87,7 @@ mod tests { documentation: Documentation( "Creates a [`Vec`] containing the arguments.\n\n- Create a [`Vec`] containing a given list of elements:\n\n```\nlet v = vec![1, 2, 3];\nassert_eq!(v[0], 1);\nassert_eq!(v[1], 2);\nassert_eq!(v[2], 3);\n```", ), + deprecated: false, }, ]"## ); @@ -121,6 +123,7 @@ mod tests { documentation: Documentation( "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`", ), + deprecated: false, }, CompletionItem { label: "main()", @@ -130,6 +133,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, ] "### diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 9ac9768af..2c9c8645b 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -308,6 +308,7 @@ mod tests { documentation: Documentation( "Bar Variant with i32", ), + deprecated: false, }, CompletionItem { label: "Foo", @@ -319,6 +320,7 @@ mod tests { documentation: Documentation( "Foo Variant", ), + deprecated: false, }, ]"### ); @@ -354,6 +356,7 @@ mod tests { documentation: Documentation( "Bar Variant with i32 and u32", ), + deprecated: false, }, CompletionItem { label: "Foo", @@ -365,6 +368,7 @@ mod tests { documentation: Documentation( "Foo Variant (empty)", ), + deprecated: false, }, CompletionItem { label: "S", @@ -376,6 +380,7 @@ mod tests { documentation: Documentation( "", ), + deprecated: false, }, ]"### ); @@ -411,6 +416,7 @@ mod tests { documentation: Documentation( "An associated method", ), + deprecated: false, }, ] "### @@ -445,6 +451,7 @@ mod tests { documentation: Documentation( "An associated const", ), + deprecated: false, }, ]"### ); @@ -478,6 +485,7 @@ mod tests { documentation: Documentation( "An associated type", ), + deprecated: false, }, ]"### ); @@ -513,6 +521,7 @@ mod tests { documentation: Documentation( "An associated method", ), + deprecated: false, }, ] "### @@ -549,6 +558,7 @@ mod tests { documentation: Documentation( "An associated method", ), + deprecated: false, }, ] "### @@ -608,6 +618,7 @@ mod tests { documentation: Documentation( "A trait method", ), + deprecated: false, }, ] "### @@ -644,6 +655,7 @@ mod tests { documentation: Documentation( "A trait method", ), + deprecated: false, }, ] "### @@ -680,6 +692,7 @@ mod tests { documentation: Documentation( "A trait method", ), + deprecated: false, }, ] "### @@ -711,6 +724,7 @@ mod tests { kind: Function, lookup: "bar", detail: "fn bar()", + deprecated: false, }, CompletionItem { label: "foo()", @@ -720,6 +734,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", + deprecated: false, }, ] "### @@ -750,6 +765,7 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! foo", + deprecated: false, }, CompletionItem { label: "main()", @@ -759,6 +775,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, ] "### diff --git a/crates/ra_ide_api/src/completion/complete_record_literal.rs b/crates/ra_ide_api/src/completion/complete_record_literal.rs index 4406695d5..33bea411f 100644 --- a/crates/ra_ide_api/src/completion/complete_record_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_record_literal.rs @@ -31,6 +31,34 @@ mod tests { do_completion(code, CompletionKind::Reference) } + #[test] + fn test_record_literal_deprecated_field() { + let completions = complete( + r" + struct A { + #[deprecated] + the_field: u32, + } + fn foo() { + A { the<|> } + } + ", + ); + assert_debug_snapshot!(completions, @r###" + ⋮[ + ⋮ CompletionItem { + ⋮ label: "the_field", + ⋮ source_range: [142; 145), + ⋮ delete: [142; 145), + ⋮ insert: "the_field", + ⋮ kind: Field, + ⋮ detail: "u32", + ⋮ deprecated: true, + ⋮ }, + ⋮] + "###); + } + #[test] fn test_record_literal_field() { let completions = complete( @@ -50,6 +78,7 @@ mod tests { ⋮ insert: "the_field", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -76,6 +105,7 @@ mod tests { ⋮ insert: "a", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -102,6 +132,7 @@ mod tests { ⋮ insert: "b", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -127,6 +158,7 @@ mod tests { ⋮ insert: "a", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "###); diff --git a/crates/ra_ide_api/src/completion/complete_record_pattern.rs b/crates/ra_ide_api/src/completion/complete_record_pattern.rs index d20fa796c..93c26f229 100644 --- a/crates/ra_ide_api/src/completion/complete_record_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_record_pattern.rs @@ -52,6 +52,7 @@ mod tests { ⋮ insert: "foo", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -81,6 +82,7 @@ mod tests { ⋮ insert: "bar", ⋮ kind: Field, ⋮ detail: "()", + ⋮ deprecated: false, ⋮ }, ⋮ CompletionItem { ⋮ label: "foo", @@ -89,6 +91,7 @@ mod tests { ⋮ insert: "foo", ⋮ kind: Field, ⋮ detail: "u32", + ⋮ deprecated: false, ⋮ }, ⋮] "###); diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 4e56de3f5..9d2deee75 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -155,6 +155,7 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux(x: i32)", + deprecated: false, }, CompletionItem { label: "x", @@ -218,6 +219,7 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", + deprecated: false, }, ] "### @@ -246,6 +248,7 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", + deprecated: false, }, CompletionItem { label: "x", @@ -286,6 +289,7 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", + deprecated: false, }, ] "### @@ -391,6 +395,7 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", + deprecated: false, }, ] "### @@ -450,6 +455,7 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", + deprecated: false, }, ] "### @@ -482,6 +488,7 @@ mod tests { kind: Function, lookup: "x", detail: "fn x()", + deprecated: false, }, ] "### @@ -520,6 +527,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", + deprecated: false, }, ] "### @@ -584,6 +592,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", + deprecated: false, }, CompletionItem { label: "std", @@ -639,6 +648,7 @@ mod tests { insert: "bar!($0)", kind: Macro, detail: "macro_rules! bar", + deprecated: false, }, CompletionItem { label: "baz!", @@ -647,6 +657,7 @@ mod tests { insert: "baz!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! baz", + deprecated: false, }, CompletionItem { label: "foo!", @@ -655,6 +666,7 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", + deprecated: false, }, CompletionItem { label: "m1", @@ -678,6 +690,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, ] "### @@ -708,6 +721,7 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", + deprecated: false, }, CompletionItem { label: "foo()", @@ -717,6 +731,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", + deprecated: false, }, ] "### @@ -747,6 +762,7 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", + deprecated: false, }, CompletionItem { label: "main()", @@ -756,6 +772,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, ] "### @@ -786,6 +803,7 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", + deprecated: false, }, CompletionItem { label: "main()", @@ -795,6 +813,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, ] "### diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 5c9c44704..6753672ca 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -44,6 +44,9 @@ pub struct CompletionItem { /// Additional info to show in the UI pop up. detail: Option, documentation: Option, + + /// Whether this item is marked as deprecated + deprecated: Option, } // We use custom debug for CompletionItem to make `insta`'s diffs more readable. @@ -70,6 +73,9 @@ impl fmt::Debug for CompletionItem { if let Some(documentation) = self.documentation() { s.field("documentation", &documentation); } + if let Some(deprecated) = self.deprecated { + s.field("deprecated", &deprecated); + } s.finish() } } @@ -132,6 +138,7 @@ impl CompletionItem { lookup: None, kind: None, text_edit: None, + deprecated: None, } } /// What user sees in pop-up in the UI. @@ -166,6 +173,10 @@ impl CompletionItem { pub fn kind(&self) -> Option { self.kind } + + pub fn deprecated(&self) -> Option { + self.deprecated + } } /// A helper to make `CompletionItem`s. @@ -181,6 +192,7 @@ pub(crate) struct Builder { lookup: Option, kind: Option, text_edit: Option, + deprecated: Option, } impl Builder { @@ -208,6 +220,7 @@ impl Builder { lookup: self.lookup, kind: self.kind, completion_kind: self.completion_kind, + deprecated: self.deprecated, } } pub(crate) fn lookup_by(mut self, lookup: impl Into) -> Builder { @@ -254,6 +267,10 @@ impl Builder { self.documentation = docs.map(Into::into); self } + pub(crate) fn set_deprecated(mut self, deprecated: bool) -> Builder { + self.deprecated = Some(deprecated); + self + } } impl<'a> Into for Builder { diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 65bb639ed..d98201887 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -2,7 +2,7 @@ use hir::{db::HirDatabase, Docs, HasSource, HirDisplay, ScopeDef, Ty, TypeWalk}; use join_to_string::join; -use ra_syntax::ast::NameOwner; +use ra_syntax::ast::{AttrsOwner, NameOwner}; use test_utils::tested_by; use crate::completion::{ @@ -18,6 +18,11 @@ impl Completions { field: hir::StructField, substs: &hir::Substs, ) { + let ast_node = field.source(ctx.db).ast; + let is_deprecated = match ast_node { + hir::FieldSource::Named(m) => is_deprecated(m), + hir::FieldSource::Pos(m) => is_deprecated(m), + }; CompletionItem::new( CompletionKind::Reference, ctx.source_range(), @@ -26,6 +31,7 @@ impl Completions { .kind(CompletionItemKind::Field) .detail(field.ty(ctx.db).subst(substs).display(ctx.db).to_string()) .set_documentation(field.docs(ctx.db)) + .set_deprecated(is_deprecated) .add_to(self); } @@ -179,6 +185,7 @@ impl Completions { CompletionItem::new(CompletionKind::Reference, ctx.source_range(), ¯o_declaration) .kind(CompletionItemKind::Macro) .set_documentation(docs.clone()) + .set_deprecated(is_deprecated(ast_node)) .detail(detail); builder = if ctx.use_item_syntax.is_some() { @@ -211,6 +218,7 @@ impl Completions { CompletionItemKind::Function }) .set_documentation(func.docs(ctx.db)) + .set_deprecated(is_deprecated(ast_node)) .detail(detail); // Add `<>` for generic types @@ -242,6 +250,7 @@ impl Completions { CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) .kind(CompletionItemKind::Const) .set_documentation(constant.docs(ctx.db)) + .set_deprecated(is_deprecated(ast_node)) .detail(detail) .add_to(self); } @@ -257,11 +266,13 @@ impl Completions { CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) .kind(CompletionItemKind::TypeAlias) .set_documentation(type_alias.docs(ctx.db)) + .set_deprecated(is_deprecated(type_def)) .detail(detail) .add_to(self); } pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { + let is_deprecated = is_deprecated(variant.source(ctx.db).ast); let name = match variant.name(ctx.db) { Some(it) => it, None => return, @@ -274,11 +285,16 @@ impl Completions { CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) .kind(CompletionItemKind::EnumVariant) .set_documentation(variant.docs(ctx.db)) + .set_deprecated(is_deprecated) .detail(detail) .add_to(self); } } +fn is_deprecated(node: impl AttrsOwner) -> bool { + node.attrs().filter_map(|x| x.simple_name()).any(|x| x == "deprecated") +} + fn has_non_default_type_params(def: hir::GenericDef, db: &db::RootDatabase) -> bool { let subst = db.generic_defaults(def); subst.iter().any(|ty| ty == &Ty::Unknown) @@ -295,6 +311,57 @@ mod tests { do_completion(code, CompletionKind::Reference) } + #[test] + fn sets_deprecated_flag_in_completion_items() { + assert_debug_snapshot!( + do_reference_completion( + r#" + #[deprecated] + fn something_deprecated() {} + + #[deprecated(since = "1.0.0")] + fn something_else_deprecated() {} + + fn main() { som<|> } + "#, + ), + @r###" + [ + CompletionItem { + label: "main()", + source_range: [203; 206), + delete: [203; 206), + insert: "main()$0", + kind: Function, + lookup: "main", + detail: "fn main()", + deprecated: false, + }, + CompletionItem { + label: "something_deprecated()", + source_range: [203; 206), + delete: [203; 206), + insert: "something_deprecated()$0", + kind: Function, + lookup: "something_deprecated", + detail: "fn something_deprecated()", + deprecated: true, + }, + CompletionItem { + label: "something_else_deprecated()", + source_range: [203; 206), + delete: [203; 206), + insert: "something_else_deprecated()$0", + kind: Function, + lookup: "something_else_deprecated", + detail: "fn something_else_deprecated()", + deprecated: true, + }, + ] + "### + ); + } + #[test] fn inserts_parens_for_function_calls() { covers!(inserts_parens_for_function_calls); @@ -315,6 +382,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, CompletionItem { label: "no_args()", @@ -324,6 +392,7 @@ mod tests { kind: Function, lookup: "no_args", detail: "fn no_args()", + deprecated: false, }, ] "### @@ -345,6 +414,7 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", + deprecated: false, }, CompletionItem { label: "with_args(…)", @@ -354,6 +424,7 @@ mod tests { kind: Function, lookup: "with_args", detail: "fn with_args(x: i32, y: String)", + deprecated: false, }, ] "### @@ -380,6 +451,7 @@ mod tests { kind: Method, lookup: "foo", detail: "fn foo(&self)", + deprecated: false, }, ] "### @@ -404,6 +476,7 @@ mod tests { insert: "foo", kind: Function, detail: "pub fn foo()", + deprecated: false, }, ]"# ); @@ -429,6 +502,7 @@ mod tests { insert: "frobnicate", kind: Function, detail: "fn frobnicate()", + deprecated: false, }, CompletionItem { label: "main", @@ -437,6 +511,7 @@ mod tests { insert: "main", kind: Function, detail: "fn main()", + deprecated: false, }, ]"# ); @@ -459,6 +534,7 @@ mod tests { insert: "new", kind: Function, detail: "fn new() -> Foo", + deprecated: false, }, ]"# ); @@ -492,6 +568,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", + deprecated: false, }, ] "### @@ -521,6 +598,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", + deprecated: false, }, ] "### @@ -549,6 +627,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", + deprecated: false, }, ] "### @@ -577,6 +656,7 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", + deprecated: false, }, ] "### @@ -607,6 +687,7 @@ mod tests { insert: "frobnicate", kind: Macro, detail: "#[macro_export]\nmacro_rules! frobnicate", + deprecated: false, }, ] "### -- cgit v1.2.3 From ccf8817d181ab9430a00c38d96b481a07af701bb Mon Sep 17 00:00:00 2001 From: Martin Asquino Date: Sat, 2 Nov 2019 19:33:34 -0300 Subject: Use `bool` instead of `Option` and print it's value only when `true` --- crates/ra_ide_api/src/completion/complete_dot.rs | 11 ----------- .../src/completion/complete_macro_in_item_position.rs | 4 ---- crates/ra_ide_api/src/completion/complete_path.rs | 17 ----------------- .../src/completion/complete_record_literal.rs | 4 ---- .../src/completion/complete_record_pattern.rs | 3 --- crates/ra_ide_api/src/completion/complete_scope.rs | 19 ------------------- crates/ra_ide_api/src/completion/completion_item.rs | 10 +++++----- crates/ra_ide_api/src/completion/presentation.rs | 15 --------------- 8 files changed, 5 insertions(+), 78 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 9c0abd590..b4df6ee2a 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -96,7 +96,6 @@ mod tests { ⋮ insert: "the_field", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "### @@ -129,7 +128,6 @@ mod tests { kind: Method, lookup: "foo", detail: "fn foo(self)", - deprecated: false, }, CompletionItem { label: "the_field", @@ -141,7 +139,6 @@ mod tests { documentation: Documentation( "This is the_field", ), - deprecated: false, }, ] "### @@ -171,7 +168,6 @@ mod tests { kind: Method, lookup: "foo", detail: "fn foo(&self)", - deprecated: false, }, CompletionItem { label: "the_field", @@ -180,7 +176,6 @@ mod tests { insert: "the_field", kind: Field, detail: "(u32, i32)", - deprecated: false, }, ] "### @@ -226,7 +221,6 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", - deprecated: false, }, ] "### @@ -256,7 +250,6 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", - deprecated: false, }, ] "### @@ -286,7 +279,6 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", - deprecated: false, }, ] "### @@ -339,7 +331,6 @@ mod tests { kind: Method, lookup: "the_method", detail: "fn the_method(&self)", - deprecated: false, }, ] "### @@ -410,7 +401,6 @@ mod tests { kind: Method, lookup: "blah", detail: "pub fn blah(&self)", - deprecated: false, }, ] "### @@ -437,7 +427,6 @@ mod tests { ⋮ insert: "the_field", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "### diff --git a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs index a082a3c7c..09f743c66 100644 --- a/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide_api/src/completion/complete_macro_in_item_position.rs @@ -45,7 +45,6 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", - deprecated: false, }, ]"## ); @@ -87,7 +86,6 @@ mod tests { documentation: Documentation( "Creates a [`Vec`] containing the arguments.\n\n- Create a [`Vec`] containing a given list of elements:\n\n```\nlet v = vec![1, 2, 3];\nassert_eq!(v[0], 1);\nassert_eq!(v[1], 2);\nassert_eq!(v[2], 3);\n```", ), - deprecated: false, }, ]"## ); @@ -123,7 +121,6 @@ mod tests { documentation: Documentation( "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`", ), - deprecated: false, }, CompletionItem { label: "main()", @@ -133,7 +130,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, ] "### diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 2c9c8645b..9ac9768af 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -308,7 +308,6 @@ mod tests { documentation: Documentation( "Bar Variant with i32", ), - deprecated: false, }, CompletionItem { label: "Foo", @@ -320,7 +319,6 @@ mod tests { documentation: Documentation( "Foo Variant", ), - deprecated: false, }, ]"### ); @@ -356,7 +354,6 @@ mod tests { documentation: Documentation( "Bar Variant with i32 and u32", ), - deprecated: false, }, CompletionItem { label: "Foo", @@ -368,7 +365,6 @@ mod tests { documentation: Documentation( "Foo Variant (empty)", ), - deprecated: false, }, CompletionItem { label: "S", @@ -380,7 +376,6 @@ mod tests { documentation: Documentation( "", ), - deprecated: false, }, ]"### ); @@ -416,7 +411,6 @@ mod tests { documentation: Documentation( "An associated method", ), - deprecated: false, }, ] "### @@ -451,7 +445,6 @@ mod tests { documentation: Documentation( "An associated const", ), - deprecated: false, }, ]"### ); @@ -485,7 +478,6 @@ mod tests { documentation: Documentation( "An associated type", ), - deprecated: false, }, ]"### ); @@ -521,7 +513,6 @@ mod tests { documentation: Documentation( "An associated method", ), - deprecated: false, }, ] "### @@ -558,7 +549,6 @@ mod tests { documentation: Documentation( "An associated method", ), - deprecated: false, }, ] "### @@ -618,7 +608,6 @@ mod tests { documentation: Documentation( "A trait method", ), - deprecated: false, }, ] "### @@ -655,7 +644,6 @@ mod tests { documentation: Documentation( "A trait method", ), - deprecated: false, }, ] "### @@ -692,7 +680,6 @@ mod tests { documentation: Documentation( "A trait method", ), - deprecated: false, }, ] "### @@ -724,7 +711,6 @@ mod tests { kind: Function, lookup: "bar", detail: "fn bar()", - deprecated: false, }, CompletionItem { label: "foo()", @@ -734,7 +720,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", - deprecated: false, }, ] "### @@ -765,7 +750,6 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! foo", - deprecated: false, }, CompletionItem { label: "main()", @@ -775,7 +759,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, ] "### diff --git a/crates/ra_ide_api/src/completion/complete_record_literal.rs b/crates/ra_ide_api/src/completion/complete_record_literal.rs index 33bea411f..0295b8101 100644 --- a/crates/ra_ide_api/src/completion/complete_record_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_record_literal.rs @@ -78,7 +78,6 @@ mod tests { ⋮ insert: "the_field", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -105,7 +104,6 @@ mod tests { ⋮ insert: "a", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -132,7 +130,6 @@ mod tests { ⋮ insert: "b", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -158,7 +155,6 @@ mod tests { ⋮ insert: "a", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "###); diff --git a/crates/ra_ide_api/src/completion/complete_record_pattern.rs b/crates/ra_ide_api/src/completion/complete_record_pattern.rs index 93c26f229..d20fa796c 100644 --- a/crates/ra_ide_api/src/completion/complete_record_pattern.rs +++ b/crates/ra_ide_api/src/completion/complete_record_pattern.rs @@ -52,7 +52,6 @@ mod tests { ⋮ insert: "foo", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "###); @@ -82,7 +81,6 @@ mod tests { ⋮ insert: "bar", ⋮ kind: Field, ⋮ detail: "()", - ⋮ deprecated: false, ⋮ }, ⋮ CompletionItem { ⋮ label: "foo", @@ -91,7 +89,6 @@ mod tests { ⋮ insert: "foo", ⋮ kind: Field, ⋮ detail: "u32", - ⋮ deprecated: false, ⋮ }, ⋮] "###); diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 9d2deee75..4e56de3f5 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -155,7 +155,6 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux(x: i32)", - deprecated: false, }, CompletionItem { label: "x", @@ -219,7 +218,6 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", - deprecated: false, }, ] "### @@ -248,7 +246,6 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", - deprecated: false, }, CompletionItem { label: "x", @@ -289,7 +286,6 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", - deprecated: false, }, ] "### @@ -395,7 +391,6 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", - deprecated: false, }, ] "### @@ -455,7 +450,6 @@ mod tests { kind: Function, lookup: "quux", detail: "fn quux()", - deprecated: false, }, ] "### @@ -488,7 +482,6 @@ mod tests { kind: Function, lookup: "x", detail: "fn x()", - deprecated: false, }, ] "### @@ -527,7 +520,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", - deprecated: false, }, ] "### @@ -592,7 +584,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", - deprecated: false, }, CompletionItem { label: "std", @@ -648,7 +639,6 @@ mod tests { insert: "bar!($0)", kind: Macro, detail: "macro_rules! bar", - deprecated: false, }, CompletionItem { label: "baz!", @@ -657,7 +647,6 @@ mod tests { insert: "baz!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! baz", - deprecated: false, }, CompletionItem { label: "foo!", @@ -666,7 +655,6 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", - deprecated: false, }, CompletionItem { label: "m1", @@ -690,7 +678,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, ] "### @@ -721,7 +708,6 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", - deprecated: false, }, CompletionItem { label: "foo()", @@ -731,7 +717,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo()", - deprecated: false, }, ] "### @@ -762,7 +747,6 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", - deprecated: false, }, CompletionItem { label: "main()", @@ -772,7 +756,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, ] "### @@ -803,7 +786,6 @@ mod tests { insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", - deprecated: false, }, CompletionItem { label: "main()", @@ -813,7 +795,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, ] "### diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs index 6753672ca..93f336370 100644 --- a/crates/ra_ide_api/src/completion/completion_item.rs +++ b/crates/ra_ide_api/src/completion/completion_item.rs @@ -46,7 +46,7 @@ pub struct CompletionItem { documentation: Option, /// Whether this item is marked as deprecated - deprecated: Option, + deprecated: bool, } // We use custom debug for CompletionItem to make `insta`'s diffs more readable. @@ -73,8 +73,8 @@ impl fmt::Debug for CompletionItem { if let Some(documentation) = self.documentation() { s.field("documentation", &documentation); } - if let Some(deprecated) = self.deprecated { - s.field("deprecated", &deprecated); + if self.deprecated { + s.field("deprecated", &true); } s.finish() } @@ -174,7 +174,7 @@ impl CompletionItem { self.kind } - pub fn deprecated(&self) -> Option { + pub fn deprecated(&self) -> bool { self.deprecated } } @@ -220,7 +220,7 @@ impl Builder { lookup: self.lookup, kind: self.kind, completion_kind: self.completion_kind, - deprecated: self.deprecated, + deprecated: self.deprecated.unwrap_or(false), } } pub(crate) fn lookup_by(mut self, lookup: impl Into) -> Builder { diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index d98201887..cb55d1875 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs @@ -335,7 +335,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, CompletionItem { label: "something_deprecated()", @@ -382,7 +381,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, CompletionItem { label: "no_args()", @@ -392,7 +390,6 @@ mod tests { kind: Function, lookup: "no_args", detail: "fn no_args()", - deprecated: false, }, ] "### @@ -414,7 +411,6 @@ mod tests { kind: Function, lookup: "main", detail: "fn main()", - deprecated: false, }, CompletionItem { label: "with_args(…)", @@ -424,7 +420,6 @@ mod tests { kind: Function, lookup: "with_args", detail: "fn with_args(x: i32, y: String)", - deprecated: false, }, ] "### @@ -451,7 +446,6 @@ mod tests { kind: Method, lookup: "foo", detail: "fn foo(&self)", - deprecated: false, }, ] "### @@ -476,7 +470,6 @@ mod tests { insert: "foo", kind: Function, detail: "pub fn foo()", - deprecated: false, }, ]"# ); @@ -502,7 +495,6 @@ mod tests { insert: "frobnicate", kind: Function, detail: "fn frobnicate()", - deprecated: false, }, CompletionItem { label: "main", @@ -511,7 +503,6 @@ mod tests { insert: "main", kind: Function, detail: "fn main()", - deprecated: false, }, ]"# ); @@ -534,7 +525,6 @@ mod tests { insert: "new", kind: Function, detail: "fn new() -> Foo", - deprecated: false, }, ]"# ); @@ -568,7 +558,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", - deprecated: false, }, ] "### @@ -598,7 +587,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", - deprecated: false, }, ] "### @@ -627,7 +615,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", - deprecated: false, }, ] "### @@ -656,7 +643,6 @@ mod tests { kind: Function, lookup: "foo", detail: "fn foo(xs: Ve)", - deprecated: false, }, ] "### @@ -687,7 +673,6 @@ mod tests { insert: "frobnicate", kind: Macro, detail: "#[macro_export]\nmacro_rules! frobnicate", - deprecated: false, }, ] "### -- cgit v1.2.3 From ba2efca2bbe5f4434f9a2522b2b94df873f3563b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 31 Oct 2019 18:45:10 +0300 Subject: Move CrateDefMap to hir_def --- crates/ra_ide_api/src/completion/complete_path.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 9ac9768af..09ca40179 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -18,15 +18,15 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { match def { hir::ModuleDef::Module(module) => { let module_scope = module.scope(ctx.db); - for (name, res) in module_scope.entries() { - if let Some(hir::ModuleDef::BuiltinType(..)) = res.def.take_types() { + for (name, def, import) in module_scope { + if let hir::ScopeDef::ModuleDef(hir::ModuleDef::BuiltinType(..)) = def { if ctx.use_item_syntax.is_some() { tested_by!(dont_complete_primitive_in_use); continue; } } if Some(module) == ctx.module { - if let Some(import) = res.import { + if let Some(import) = import { if let Either::A(use_tree) = module.import_source(ctx.db, import) { if use_tree.syntax().text_range().contains_inclusive(ctx.offset) { // for `use self::foo<|>`, don't suggest `foo` as a completion @@ -36,7 +36,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { } } } - acc.add_resolution(ctx, name.to_string(), &res.def.into()); + acc.add_resolution(ctx, name.to_string(), &def); } } hir::ModuleDef::Adt(_) | hir::ModuleDef::TypeAlias(_) => { -- cgit v1.2.3 From 3603d0213480c7b3423345d21243397eb904a073 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 4 Nov 2019 01:14:17 +0300 Subject: Reexport relative_path from ra_db --- crates/ra_ide_api/Cargo.toml | 1 - crates/ra_ide_api/src/change.rs | 4 ++-- crates/ra_ide_api/src/db.rs | 5 ++--- crates/ra_ide_api/src/diagnostics.rs | 3 +-- crates/ra_ide_api/src/mock_analysis.rs | 2 +- crates/ra_ide_api/src/references/rename.rs | 3 +-- crates/ra_ide_api/src/source_change.rs | 2 +- 7 files changed, 8 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide_api') diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml index bf6ef12f3..fa353b5dd 100644 --- a/crates/ra_ide_api/Cargo.toml +++ b/crates/ra_ide_api/Cargo.toml @@ -12,7 +12,6 @@ format-buf = "1.0.0" itertools = "0.8.0" join_to_string = "0.1.3" log = "0.4.5" -relative-path = "1.0.0" rayon = "1.0.2" fst = { version = "0.3.1", default-features = false } rustc-hash = "1.0" diff --git a/crates/ra_ide_api/src/change.rs b/crates/ra_ide_api/src/change.rs index 39c5946c7..4416421ae 100644 --- a/crates/ra_ide_api/src/change.rs +++ b/crates/ra_ide_api/src/change.rs @@ -4,13 +4,13 @@ use std::{fmt, sync::Arc, time}; use ra_db::{ salsa::{Database, Durability, SweepStrategy}, - CrateGraph, CrateId, FileId, SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId, + CrateGraph, CrateId, FileId, RelativePathBuf, SourceDatabase, SourceDatabaseExt, SourceRoot, + SourceRootId, }; use ra_prof::{memory_usage, profile, Bytes}; use ra_syntax::SourceFile; #[cfg(not(feature = "wasm"))] use rayon::prelude::*; -use relative_path::RelativePathBuf; use rustc_hash::FxHashMap; use crate::{ diff --git a/crates/ra_ide_api/src/db.rs b/crates/ra_ide_api/src/db.rs index 785e71808..c96465b6a 100644 --- a/crates/ra_ide_api/src/db.rs +++ b/crates/ra_ide_api/src/db.rs @@ -4,10 +4,9 @@ use std::sync::Arc; use ra_db::{ salsa::{self, Database, Durability}, - Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, - SourceDatabaseExt, SourceRootId, + Canceled, CheckCanceled, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, + SourceDatabase, SourceDatabaseExt, SourceRootId, }; -use relative_path::RelativePath; use rustc_hash::FxHashMap; use crate::{ diff --git a/crates/ra_ide_api/src/diagnostics.rs b/crates/ra_ide_api/src/diagnostics.rs index 1f1f5cd74..2890a3d2b 100644 --- a/crates/ra_ide_api/src/diagnostics.rs +++ b/crates/ra_ide_api/src/diagnostics.rs @@ -4,7 +4,7 @@ use std::cell::RefCell; use hir::diagnostics::{AstDiagnostic, Diagnostic as _, DiagnosticSink}; use itertools::Itertools; -use ra_db::{SourceDatabase, SourceDatabaseExt}; +use ra_db::{RelativePath, SourceDatabase, SourceDatabaseExt}; use ra_prof::profile; use ra_syntax::{ algo, @@ -12,7 +12,6 @@ use ra_syntax::{ Location, SyntaxNode, TextRange, T, }; use ra_text_edit::{TextEdit, TextEditBuilder}; -use relative_path::RelativePath; use crate::{db::RootDatabase, Diagnostic, FileId, FileSystemEdit, SourceChange, SourceFileEdit}; diff --git a/crates/ra_ide_api/src/mock_analysis.rs b/crates/ra_ide_api/src/mock_analysis.rs index 80b71894c..2b1c96dbf 100644 --- a/crates/ra_ide_api/src/mock_analysis.rs +++ b/crates/ra_ide_api/src/mock_analysis.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; -use relative_path::RelativePathBuf; +use ra_db::RelativePathBuf; use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER}; use crate::{ diff --git a/crates/ra_ide_api/src/references/rename.rs b/crates/ra_ide_api/src/references/rename.rs index a8783d7a0..11f81cbb3 100644 --- a/crates/ra_ide_api/src/references/rename.rs +++ b/crates/ra_ide_api/src/references/rename.rs @@ -1,10 +1,9 @@ //! FIXME: write short doc here use hir::ModuleSource; -use ra_db::{SourceDatabase, SourceDatabaseExt}; +use ra_db::{RelativePath, RelativePathBuf, SourceDatabase, SourceDatabaseExt}; use ra_syntax::{algo::find_node_at_offset, ast, AstNode, SyntaxNode}; use ra_text_edit::TextEdit; -use relative_path::{RelativePath, RelativePathBuf}; use crate::{ db::RootDatabase, FileId, FilePosition, FileSystemEdit, RangeInfo, SourceChange, diff --git a/crates/ra_ide_api/src/source_change.rs b/crates/ra_ide_api/src/source_change.rs index 4e63bbf6f..f5f7f8807 100644 --- a/crates/ra_ide_api/src/source_change.rs +++ b/crates/ra_ide_api/src/source_change.rs @@ -3,8 +3,8 @@ //! //! It can be viewed as a dual for `AnalysisChange`. +use ra_db::RelativePathBuf; use ra_text_edit::TextEdit; -use relative_path::RelativePathBuf; use crate::{FileId, FilePosition, SourceRootId, TextUnit}; -- cgit v1.2.3