diff options
author | Aleksey Kladov <[email protected]> | 2019-11-26 11:02:57 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-11-26 11:02:57 +0000 |
commit | e5eadb339039e21718d382c0b3d02a4bf053b3f4 (patch) | |
tree | 2f7839288ce5676a89c6d6062cbaf70544e0beed /crates/ra_ide_api/src/completion/complete_postfix.rs | |
parent | 5901cc736074bbc4d780a8e45079d405ab2cec4b (diff) |
Introduce hir::Type
It should provide a convenient API over more low-level Ty
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_postfix.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_postfix.rs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_postfix.rs b/crates/ra_ide_api/src/completion/complete_postfix.rs index 17b75cf7e..646a30c76 100644 --- a/crates/ra_ide_api/src/completion/complete_postfix.rs +++ b/crates/ra_ide_api/src/completion/complete_postfix.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{Ty, TypeCtor}; | ||
4 | use ra_syntax::{ast::AstNode, TextRange, TextUnit}; | 3 | use ra_syntax::{ast::AstNode, TextRange, TextUnit}; |
5 | use ra_text_edit::TextEdit; | 4 | use ra_text_edit::TextEdit; |
6 | 5 | ||
@@ -30,9 +29,12 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
30 | dot_receiver.syntax().text().to_string() | 29 | dot_receiver.syntax().text().to_string() |
31 | }; | 30 | }; |
32 | 31 | ||
33 | let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver); | 32 | let receiver_ty = match ctx.analyzer.type_of(ctx.db, &dot_receiver) { |
33 | Some(it) => it, | ||
34 | None => return, | ||
35 | }; | ||
34 | 36 | ||
35 | if is_bool_or_unknown(receiver_ty) { | 37 | if receiver_ty.is_bool() || receiver_ty.is_unknown() { |
36 | postfix_snippet(ctx, "if", "if expr {}", &format!("if {} {{$0}}", receiver_text)) | 38 | postfix_snippet(ctx, "if", "if expr {}", &format!("if {} {{$0}}", receiver_text)) |
37 | .add_to(acc); | 39 | .add_to(acc); |
38 | postfix_snippet( | 40 | postfix_snippet( |
@@ -75,14 +77,6 @@ fn postfix_snippet(ctx: &CompletionContext, label: &str, detail: &str, snippet: | |||
75 | .snippet_edit(edit) | 77 | .snippet_edit(edit) |
76 | } | 78 | } |
77 | 79 | ||
78 | fn is_bool_or_unknown(ty: Option<Ty>) -> bool { | ||
79 | match &ty { | ||
80 | Some(Ty::Apply(app)) if app.ctor == TypeCtor::Bool => true, | ||
81 | Some(Ty::Unknown) | None => true, | ||
82 | Some(_) => false, | ||
83 | } | ||
84 | } | ||
85 | |||
86 | #[cfg(test)] | 80 | #[cfg(test)] |
87 | mod tests { | 81 | mod tests { |
88 | use insta::assert_debug_snapshot; | 82 | use insta::assert_debug_snapshot; |