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 --------------- crates/ra_lsp_server/src/conv.rs | 2 +- 9 files changed, 6 insertions(+), 79 deletions(-) (limited to 'crates') 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, }, ] "### diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index a4667d284..94ed619fa 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -127,7 +127,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem { text_edit: Some(text_edit), additional_text_edits: Some(additional_text_edits), documentation: self.documentation().map(|it| it.conv()), - deprecated: self.deprecated(), + deprecated: Some(self.deprecated()), ..Default::default() }; res.insert_text_format = Some(match self.insert_text_format() { -- cgit v1.2.3