Use bool instead of Option<bool> and print it's value only when true

This commit is contained in:
Martin Asquino 2019-11-02 19:33:34 -03:00
parent dc3848a6a3
commit ccf8817d18
9 changed files with 6 additions and 79 deletions

View file

@ -96,7 +96,6 @@ mod tests {
insert: "the_field", insert: "the_field",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"### "###
@ -129,7 +128,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "foo", lookup: "foo",
detail: "fn foo(self)", detail: "fn foo(self)",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "the_field", label: "the_field",
@ -141,7 +139,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"This is the_field", "This is the_field",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -171,7 +168,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "foo", lookup: "foo",
detail: "fn foo(&self)", detail: "fn foo(&self)",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "the_field", label: "the_field",
@ -180,7 +176,6 @@ mod tests {
insert: "the_field", insert: "the_field",
kind: Field, kind: Field,
detail: "(u32, i32)", detail: "(u32, i32)",
deprecated: false,
}, },
] ]
"### "###
@ -226,7 +221,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "the_method", lookup: "the_method",
detail: "fn the_method(&self)", detail: "fn the_method(&self)",
deprecated: false,
}, },
] ]
"### "###
@ -256,7 +250,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "the_method", lookup: "the_method",
detail: "fn the_method(&self)", detail: "fn the_method(&self)",
deprecated: false,
}, },
] ]
"### "###
@ -286,7 +279,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "the_method", lookup: "the_method",
detail: "fn the_method(&self)", detail: "fn the_method(&self)",
deprecated: false,
}, },
] ]
"### "###
@ -339,7 +331,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "the_method", lookup: "the_method",
detail: "fn the_method(&self)", detail: "fn the_method(&self)",
deprecated: false,
}, },
] ]
"### "###
@ -410,7 +401,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "blah", lookup: "blah",
detail: "pub fn blah(&self)", detail: "pub fn blah(&self)",
deprecated: false,
}, },
] ]
"### "###
@ -437,7 +427,6 @@ mod tests {
insert: "the_field", insert: "the_field",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"### "###

View file

@ -45,7 +45,6 @@ mod tests {
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
detail: "macro_rules! foo", detail: "macro_rules! foo",
deprecated: false,
}, },
]"## ]"##
); );
@ -87,7 +86,6 @@ mod tests {
documentation: Documentation( 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```", "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( documentation: Documentation(
"Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`", "Foo\n\nNot call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`.\nCall as `let _=foo! { hello world };`",
), ),
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "main()", label: "main()",
@ -133,7 +130,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
] ]
"### "###

View file

@ -308,7 +308,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"Bar Variant with i32", "Bar Variant with i32",
), ),
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "Foo", label: "Foo",
@ -320,7 +319,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"Foo Variant", "Foo Variant",
), ),
deprecated: false,
}, },
]"### ]"###
); );
@ -356,7 +354,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"Bar Variant with i32 and u32", "Bar Variant with i32 and u32",
), ),
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "Foo", label: "Foo",
@ -368,7 +365,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"Foo Variant (empty)", "Foo Variant (empty)",
), ),
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "S", label: "S",
@ -380,7 +376,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"", "",
), ),
deprecated: false,
}, },
]"### ]"###
); );
@ -416,7 +411,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"An associated method", "An associated method",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -451,7 +445,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"An associated const", "An associated const",
), ),
deprecated: false,
}, },
]"### ]"###
); );
@ -485,7 +478,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"An associated type", "An associated type",
), ),
deprecated: false,
}, },
]"### ]"###
); );
@ -521,7 +513,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"An associated method", "An associated method",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -558,7 +549,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"An associated method", "An associated method",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -618,7 +608,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"A trait method", "A trait method",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -655,7 +644,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"A trait method", "A trait method",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -692,7 +680,6 @@ mod tests {
documentation: Documentation( documentation: Documentation(
"A trait method", "A trait method",
), ),
deprecated: false,
}, },
] ]
"### "###
@ -724,7 +711,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "bar", lookup: "bar",
detail: "fn bar()", detail: "fn bar()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "foo()", label: "foo()",
@ -734,7 +720,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo()", detail: "fn foo()",
deprecated: false,
}, },
] ]
"### "###
@ -765,7 +750,6 @@ mod tests {
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
detail: "#[macro_export]\nmacro_rules! foo", detail: "#[macro_export]\nmacro_rules! foo",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "main()", label: "main()",
@ -775,7 +759,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
] ]
"### "###

View file

@ -78,7 +78,6 @@ mod tests {
insert: "the_field", insert: "the_field",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"###); "###);
@ -105,7 +104,6 @@ mod tests {
insert: "a", insert: "a",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"###); "###);
@ -132,7 +130,6 @@ mod tests {
insert: "b", insert: "b",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"###); "###);
@ -158,7 +155,6 @@ mod tests {
insert: "a", insert: "a",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"###); "###);

View file

@ -52,7 +52,6 @@ mod tests {
insert: "foo", insert: "foo",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"###); "###);
@ -82,7 +81,6 @@ mod tests {
insert: "bar", insert: "bar",
kind: Field, kind: Field,
detail: "()", detail: "()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "foo", label: "foo",
@ -91,7 +89,6 @@ mod tests {
insert: "foo", insert: "foo",
kind: Field, kind: Field,
detail: "u32", detail: "u32",
deprecated: false,
}, },
] ]
"###); "###);

View file

@ -155,7 +155,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "quux", lookup: "quux",
detail: "fn quux(x: i32)", detail: "fn quux(x: i32)",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "x", label: "x",
@ -219,7 +218,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "quux", lookup: "quux",
detail: "fn quux()", detail: "fn quux()",
deprecated: false,
}, },
] ]
"### "###
@ -248,7 +246,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "quux", lookup: "quux",
detail: "fn quux()", detail: "fn quux()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "x", label: "x",
@ -289,7 +286,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "quux", lookup: "quux",
detail: "fn quux<T>()", detail: "fn quux<T>()",
deprecated: false,
}, },
] ]
"### "###
@ -395,7 +391,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "quux", lookup: "quux",
detail: "fn quux()", detail: "fn quux()",
deprecated: false,
}, },
] ]
"### "###
@ -455,7 +450,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "quux", lookup: "quux",
detail: "fn quux()", detail: "fn quux()",
deprecated: false,
}, },
] ]
"### "###
@ -488,7 +482,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "x", lookup: "x",
detail: "fn x()", detail: "fn x()",
deprecated: false,
}, },
] ]
"### "###
@ -527,7 +520,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo()", detail: "fn foo()",
deprecated: false,
}, },
] ]
"### "###
@ -592,7 +584,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo()", detail: "fn foo()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "std", label: "std",
@ -648,7 +639,6 @@ mod tests {
insert: "bar!($0)", insert: "bar!($0)",
kind: Macro, kind: Macro,
detail: "macro_rules! bar", detail: "macro_rules! bar",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "baz!", label: "baz!",
@ -657,7 +647,6 @@ mod tests {
insert: "baz!($0)", insert: "baz!($0)",
kind: Macro, kind: Macro,
detail: "#[macro_export]\nmacro_rules! baz", detail: "#[macro_export]\nmacro_rules! baz",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "foo!", label: "foo!",
@ -666,7 +655,6 @@ mod tests {
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
detail: "macro_rules! foo", detail: "macro_rules! foo",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "m1", label: "m1",
@ -690,7 +678,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
] ]
"### "###
@ -721,7 +708,6 @@ mod tests {
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
detail: "macro_rules! foo", detail: "macro_rules! foo",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "foo()", label: "foo()",
@ -731,7 +717,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo()", detail: "fn foo()",
deprecated: false,
}, },
] ]
"### "###
@ -762,7 +747,6 @@ mod tests {
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
detail: "macro_rules! foo", detail: "macro_rules! foo",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "main()", label: "main()",
@ -772,7 +756,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
] ]
"### "###
@ -803,7 +786,6 @@ mod tests {
insert: "foo!($0)", insert: "foo!($0)",
kind: Macro, kind: Macro,
detail: "macro_rules! foo", detail: "macro_rules! foo",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "main()", label: "main()",
@ -813,7 +795,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
] ]
"### "###

View file

@ -46,7 +46,7 @@ pub struct CompletionItem {
documentation: Option<Documentation>, documentation: Option<Documentation>,
/// Whether this item is marked as deprecated /// Whether this item is marked as deprecated
deprecated: Option<bool>, deprecated: bool,
} }
// We use custom debug for CompletionItem to make `insta`'s diffs more readable. // 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() { if let Some(documentation) = self.documentation() {
s.field("documentation", &documentation); s.field("documentation", &documentation);
} }
if let Some(deprecated) = self.deprecated { if self.deprecated {
s.field("deprecated", &deprecated); s.field("deprecated", &true);
} }
s.finish() s.finish()
} }
@ -174,7 +174,7 @@ impl CompletionItem {
self.kind self.kind
} }
pub fn deprecated(&self) -> Option<bool> { pub fn deprecated(&self) -> bool {
self.deprecated self.deprecated
} }
} }
@ -220,7 +220,7 @@ impl Builder {
lookup: self.lookup, lookup: self.lookup,
kind: self.kind, kind: self.kind,
completion_kind: self.completion_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<String>) -> Builder { pub(crate) fn lookup_by(mut self, lookup: impl Into<String>) -> Builder {

View file

@ -335,7 +335,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "something_deprecated()", label: "something_deprecated()",
@ -382,7 +381,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "no_args()", label: "no_args()",
@ -392,7 +390,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "no_args", lookup: "no_args",
detail: "fn no_args()", detail: "fn no_args()",
deprecated: false,
}, },
] ]
"### "###
@ -414,7 +411,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "main", lookup: "main",
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "with_args(…)", label: "with_args(…)",
@ -424,7 +420,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "with_args", lookup: "with_args",
detail: "fn with_args(x: i32, y: String)", detail: "fn with_args(x: i32, y: String)",
deprecated: false,
}, },
] ]
"### "###
@ -451,7 +446,6 @@ mod tests {
kind: Method, kind: Method,
lookup: "foo", lookup: "foo",
detail: "fn foo(&self)", detail: "fn foo(&self)",
deprecated: false,
}, },
] ]
"### "###
@ -476,7 +470,6 @@ mod tests {
insert: "foo", insert: "foo",
kind: Function, kind: Function,
detail: "pub fn foo()", detail: "pub fn foo()",
deprecated: false,
}, },
]"# ]"#
); );
@ -502,7 +495,6 @@ mod tests {
insert: "frobnicate", insert: "frobnicate",
kind: Function, kind: Function,
detail: "fn frobnicate()", detail: "fn frobnicate()",
deprecated: false,
}, },
CompletionItem { CompletionItem {
label: "main", label: "main",
@ -511,7 +503,6 @@ mod tests {
insert: "main", insert: "main",
kind: Function, kind: Function,
detail: "fn main()", detail: "fn main()",
deprecated: false,
}, },
]"# ]"#
); );
@ -534,7 +525,6 @@ mod tests {
insert: "new", insert: "new",
kind: Function, kind: Function,
detail: "fn new() -> Foo", detail: "fn new() -> Foo",
deprecated: false,
}, },
]"# ]"#
); );
@ -568,7 +558,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo(xs: Ve)", detail: "fn foo(xs: Ve)",
deprecated: false,
}, },
] ]
"### "###
@ -598,7 +587,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo(xs: Ve)", detail: "fn foo(xs: Ve)",
deprecated: false,
}, },
] ]
"### "###
@ -627,7 +615,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo(xs: Ve)", detail: "fn foo(xs: Ve)",
deprecated: false,
}, },
] ]
"### "###
@ -656,7 +643,6 @@ mod tests {
kind: Function, kind: Function,
lookup: "foo", lookup: "foo",
detail: "fn foo(xs: Ve<i128>)", detail: "fn foo(xs: Ve<i128>)",
deprecated: false,
}, },
] ]
"### "###
@ -687,7 +673,6 @@ mod tests {
insert: "frobnicate", insert: "frobnicate",
kind: Macro, kind: Macro,
detail: "#[macro_export]\nmacro_rules! frobnicate", detail: "#[macro_export]\nmacro_rules! frobnicate",
deprecated: false,
}, },
] ]
"### "###

View file

@ -127,7 +127,7 @@ impl ConvWith<(&LineIndex, LineEndings)> for CompletionItem {
text_edit: Some(text_edit), text_edit: Some(text_edit),
additional_text_edits: Some(additional_text_edits), additional_text_edits: Some(additional_text_edits),
documentation: self.documentation().map(|it| it.conv()), documentation: self.documentation().map(|it| it.conv()),
deprecated: self.deprecated(), deprecated: Some(self.deprecated()),
..Default::default() ..Default::default()
}; };
res.insert_text_format = Some(match self.insert_text_format() { res.insert_text_format = Some(match self.insert_text_format() {