From 0f5d6766fd5b18716ede611060a69cbff9c2a35c Mon Sep 17 00:00:00 2001 From: Jeremy Kolb Date: Sat, 11 Apr 2020 15:47:09 -0400 Subject: Remove #[should_panic] from call_info tests --- crates/ra_ide/src/call_info.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index ca57eceff..f95b6baf3 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs @@ -208,9 +208,20 @@ mod tests { } } - fn call_info(text: &str) -> CallInfo { + fn call_info_helper(text: &str) -> Option { let (analysis, position) = single_file_with_position(text); - analysis.call_info(position).unwrap().unwrap() + analysis.call_info(position).unwrap() + } + + fn call_info(text: &str) -> CallInfo { + let info = call_info_helper(text); + assert!(info.is_some()); + info.unwrap() + } + + fn no_call_info(text: &str) { + let info = call_info_helper(text); + assert!(info.is_none()); } #[test] @@ -558,9 +569,8 @@ fn main() { } #[test] - #[should_panic] fn cant_call_named_structs() { - let _ = call_info( + no_call_info( r#" struct TS { x: u32, y: i32 } fn main() { @@ -594,9 +604,8 @@ fn main() { } #[test] - #[should_panic] fn cant_call_enum_records() { - let _ = call_info( + no_call_info( r#" enum E { /// A Variant -- cgit v1.2.3 From 5e5eb6a108b00c573455d8d088742592012707be Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 11 Apr 2020 23:33:17 +0200 Subject: Align grammar for record patterns and literals The grammar now looks like this [name_ref :] pat --- crates/ra_ide/src/completion/complete_pattern.rs | 4 ++++ crates/ra_ide/src/completion/complete_record.rs | 2 +- crates/ra_ide/src/completion/complete_unqualified_path.rs | 9 ++++++++- crates/ra_ide/src/completion/completion_context.rs | 12 +++++++++--- 4 files changed, 22 insertions(+), 5 deletions(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_pattern.rs b/crates/ra_ide/src/completion/complete_pattern.rs index 1b7d3122f..a8b4ce114 100644 --- a/crates/ra_ide/src/completion/complete_pattern.rs +++ b/crates/ra_ide/src/completion/complete_pattern.rs @@ -7,6 +7,10 @@ pub(super) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_pat_binding_or_const { return; } + if ctx.record_pat_syntax.is_some() { + return; + } + // FIXME: ideally, we should look at the type we are matching against and // suggest variants + auto-imports ctx.scope().process_all_names(&mut |name, res| { diff --git a/crates/ra_ide/src/completion/complete_record.rs b/crates/ra_ide/src/completion/complete_record.rs index f46bcee5c..83a553155 100644 --- a/crates/ra_ide/src/completion/complete_record.rs +++ b/crates/ra_ide/src/completion/complete_record.rs @@ -2,7 +2,7 @@ use crate::completion::{CompletionContext, Completions}; pub(super) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> { - let missing_fields = match (ctx.record_lit_pat.as_ref(), ctx.record_lit_syntax.as_ref()) { + let missing_fields = match (ctx.record_pat_syntax.as_ref(), ctx.record_lit_syntax.as_ref()) { (None, None) => return None, (Some(_), Some(_)) => unreachable!("A record cannot be both a literal and a pattern"), (Some(record_pat), _) => ctx.sema.record_pattern_missing_fields(record_pat), diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index 0b0da6ee4..2d8e0776c 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -3,7 +3,14 @@ use crate::completion::{CompletionContext, Completions}; pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { - if !(ctx.is_trivial_path && !ctx.is_pat_binding_or_const && !ctx.record_lit_syntax.is_some()) { + if !ctx.is_trivial_path { + return; + } + + if ctx.is_pat_binding_or_const + || ctx.record_lit_syntax.is_some() + || ctx.record_pat_syntax.is_some() + { return; } diff --git a/crates/ra_ide/src/completion/completion_context.rs b/crates/ra_ide/src/completion/completion_context.rs index 14a4a14d7..8b3401595 100644 --- a/crates/ra_ide/src/completion/completion_context.rs +++ b/crates/ra_ide/src/completion/completion_context.rs @@ -30,7 +30,7 @@ pub(crate) struct CompletionContext<'a> { pub(super) function_syntax: Option, pub(super) use_item_syntax: Option, pub(super) record_lit_syntax: Option, - pub(super) record_lit_pat: Option, + pub(super) record_pat_syntax: Option, pub(super) impl_def: Option, pub(super) is_param: bool, /// If a name-binding or reference to a const in a pattern. @@ -93,7 +93,7 @@ impl<'a> CompletionContext<'a> { function_syntax: None, use_item_syntax: None, record_lit_syntax: None, - record_lit_pat: None, + record_pat_syntax: None, impl_def: None, is_param: false, is_pat_binding_or_const: false, @@ -182,6 +182,11 @@ impl<'a> CompletionContext<'a> { self.is_param = true; return; } + // FIXME: remove this (V) duplication and make the check more precise + if name_ref.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { + self.record_pat_syntax = + self.sema.find_node_at_offset_with_macros(&original_file, offset); + } self.classify_name_ref(original_file, name_ref, offset); } @@ -211,8 +216,9 @@ impl<'a> CompletionContext<'a> { self.is_param = true; return; } + // FIXME: remove this (^) duplication and make the check more precise if name.syntax().ancestors().find_map(ast::RecordFieldPatList::cast).is_some() { - self.record_lit_pat = + self.record_pat_syntax = self.sema.find_node_at_offset_with_macros(&original_file, offset); } } -- cgit v1.2.3