diff options
Diffstat (limited to 'crates/ra_ide/src/completion/complete_record.rs')
-rw-r--r-- | crates/ra_ide/src/completion/complete_record.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/crates/ra_ide/src/completion/complete_record.rs b/crates/ra_ide/src/completion/complete_record.rs index 01dd8c6db..79f5c8c8f 100644 --- a/crates/ra_ide/src/completion/complete_record.rs +++ b/crates/ra_ide/src/completion/complete_record.rs | |||
@@ -1,12 +1,13 @@ | |||
1 | //! Complete fields in record literals and patterns. | 1 | //! Complete fields in record literals and patterns. |
2 | use crate::completion::{CompletionContext, Completions}; | ||
3 | use ra_syntax::{ast, ast::NameOwner, SmolStr}; | 2 | use ra_syntax::{ast, ast::NameOwner, SmolStr}; |
4 | 3 | ||
4 | use crate::completion::{CompletionContext, Completions}; | ||
5 | |||
5 | pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { | 6 | pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { |
6 | let (ty, variant, already_present_fields) = | 7 | let (ty, variant, already_present_fields) = |
7 | match (ctx.record_lit_pat.as_ref(), ctx.record_lit_syntax.as_ref()) { | 8 | match (ctx.record_lit_pat.as_ref(), ctx.record_lit_syntax.as_ref()) { |
8 | (None, None) => return None, | 9 | (None, None) => return None, |
9 | (Some(_), Some(_)) => panic!("A record cannot be both a literal and a pattern"), | 10 | (Some(_), Some(_)) => unreachable!("A record cannot be both a literal and a pattern"), |
10 | (Some(record_pat), _) => ( | 11 | (Some(record_pat), _) => ( |
11 | ctx.sema.type_of_pat(&record_pat.clone().into())?, | 12 | ctx.sema.type_of_pat(&record_pat.clone().into())?, |
12 | ctx.sema.resolve_record_pattern(record_pat)?, | 13 | ctx.sema.resolve_record_pattern(record_pat)?, |
@@ -59,9 +60,10 @@ fn pattern_ascribed_fields(record_pat: &ast::RecordPat) -> Vec<SmolStr> { | |||
59 | #[cfg(test)] | 60 | #[cfg(test)] |
60 | mod tests { | 61 | mod tests { |
61 | mod record_lit_tests { | 62 | mod record_lit_tests { |
62 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
63 | use insta::assert_debug_snapshot; | 63 | use insta::assert_debug_snapshot; |
64 | 64 | ||
65 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
66 | |||
65 | fn complete(code: &str) -> Vec<CompletionItem> { | 67 | fn complete(code: &str) -> Vec<CompletionItem> { |
66 | do_completion(code, CompletionKind::Reference) | 68 | do_completion(code, CompletionKind::Reference) |
67 | } | 69 | } |
@@ -204,9 +206,10 @@ mod tests { | |||
204 | } | 206 | } |
205 | 207 | ||
206 | mod record_pat_tests { | 208 | mod record_pat_tests { |
207 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
208 | use insta::assert_debug_snapshot; | 209 | use insta::assert_debug_snapshot; |
209 | 210 | ||
211 | use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; | ||
212 | |||
210 | fn complete(code: &str) -> Vec<CompletionItem> { | 213 | fn complete(code: &str) -> Vec<CompletionItem> { |
211 | do_completion(code, CompletionKind::Reference) | 214 | do_completion(code, CompletionKind::Reference) |
212 | } | 215 | } |