diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-26 11:05:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-26 11:05:05 +0000 |
commit | 500e022f7decbee29a693b0f0dd2f63789a99e5a (patch) | |
tree | 2f7839288ce5676a89c6d6062cbaf70544e0beed /crates/ra_ide_api/src/completion/complete_postfix.rs | |
parent | 5901cc736074bbc4d780a8e45079d405ab2cec4b (diff) | |
parent | e5eadb339039e21718d382c0b3d02a4bf053b3f4 (diff) |
Merge #2398
2398: WIP: introduce hir::Type r=matklad a=matklad
This introduces `hir::Type` wrapper over `hir::Ty`, with two purposes:
* bind `Ty` and it's corresponding environment
* Am I correct that `Ty` without an env doesn't make much sense, because the meaning of type parameters is unclear
* Am I correct that we can safely re-use the same environment for all types derived from the given type?
* hide representation defails of `Ty`. Specifically, I want to change `Ty::Adt` to use `hir_def::AdtId` instead of `hir::Adt`, but IDE doesn't know about underlying IDs. More generally, I feel like IDE shouldn't know that `Ty` is enum.
@flodiebold what do you think about this?
Co-authored-by: Aleksey Kladov <[email protected]>
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; |