From 6bca91af532d79abbced5b151cb4188ff8625c04 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 8 Jan 2019 22:30:56 +0300 Subject: rename ra_analysis -> ra_ide_api --- crates/ra_analysis/src/completion/complete_dot.rs | 121 ---------------------- 1 file changed, 121 deletions(-) delete mode 100644 crates/ra_analysis/src/completion/complete_dot.rs (limited to 'crates/ra_analysis/src/completion/complete_dot.rs') diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs deleted file mode 100644 index 5d4e60dc5..000000000 --- a/crates/ra_analysis/src/completion/complete_dot.rs +++ /dev/null @@ -1,121 +0,0 @@ -use hir::{Ty, Def}; - -use crate::Cancelable; -use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; - -/// Complete dot accesses, i.e. fields or methods (currently only fields). -pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { - let (function, receiver) = match (&ctx.function, ctx.dot_receiver) { - (Some(function), Some(receiver)) => (function, receiver), - _ => return Ok(()), - }; - let infer_result = function.infer(ctx.db)?; - let syntax_mapping = function.body_syntax_mapping(ctx.db)?; - let expr = match syntax_mapping.node_expr(receiver) { - Some(expr) => expr, - None => return Ok(()), - }; - let receiver_ty = infer_result[expr].clone(); - if !ctx.is_method_call { - complete_fields(acc, ctx, receiver_ty)?; - } - Ok(()) -} - -fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) -> Cancelable<()> { - for receiver in receiver.autoderef(ctx.db) { - match receiver { - Ty::Adt { def_id, .. } => { - match def_id.resolve(ctx.db)? { - Def::Struct(s) => { - let variant_data = s.variant_data(ctx.db)?; - for field in variant_data.fields() { - CompletionItem::new( - CompletionKind::Reference, - field.name().to_string(), - ) - .kind(CompletionItemKind::Field) - .add_to(acc); - } - } - // TODO unions - _ => {} - } - } - Ty::Tuple(fields) => { - for (i, _ty) in fields.iter().enumerate() { - CompletionItem::new(CompletionKind::Reference, i.to_string()) - .kind(CompletionItemKind::Field) - .add_to(acc); - } - } - _ => {} - }; - } - Ok(()) -} - -#[cfg(test)] -mod tests { - use crate::completion::*; - - fn check_ref_completion(code: &str, expected_completions: &str) { - check_completion(code, expected_completions, CompletionKind::Reference); - } - - #[test] - fn test_struct_field_completion() { - check_ref_completion( - r" - struct A { the_field: u32 } - fn foo(a: A) { - a.<|> - } - ", - r#"the_field"#, - ); - } - - #[test] - fn test_struct_field_completion_self() { - check_ref_completion( - r" - struct A { the_field: u32 } - impl A { - fn foo(self) { - self.<|> - } - } - ", - r#"the_field"#, - ); - } - - #[test] - fn test_struct_field_completion_autoderef() { - check_ref_completion( - r" - struct A { the_field: u32 } - impl A { - fn foo(&self) { - self.<|> - } - } - ", - r#"the_field"#, - ); - } - - #[test] - fn test_no_struct_field_completion_for_method_call() { - check_ref_completion( - r" - struct A { the_field: u32 } - fn foo(a: A) { - a.<|>() - } - ", - r#""#, - ); - } -} -- cgit v1.2.3