From a1c187eef3ba08076aedb5154929f7eda8d1b424 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Aug 2020 18:26:51 +0200 Subject: Rename ra_syntax -> syntax --- crates/ra_ide/src/completion/complete_fn_param.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/completion/complete_fn_param.rs') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs index 406334257..7c63ce58f 100644 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ b/crates/ra_ide/src/completion/complete_fn_param.rs @@ -1,10 +1,10 @@ //! See `complete_fn_param`. -use ra_syntax::{ +use rustc_hash::FxHashMap; +use syntax::{ ast::{self, ModuleItemOwner}, match_ast, AstNode, }; -use rustc_hash::FxHashMap; use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; -- cgit v1.2.3 From 1b0c7701cc97cd7bef8bb9729011d4cf291a60c5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Aug 2020 17:42:52 +0200 Subject: Rename ra_ide -> ide --- crates/ra_ide/src/completion/complete_fn_param.rs | 135 ---------------------- 1 file changed, 135 deletions(-) delete mode 100644 crates/ra_ide/src/completion/complete_fn_param.rs (limited to 'crates/ra_ide/src/completion/complete_fn_param.rs') diff --git a/crates/ra_ide/src/completion/complete_fn_param.rs b/crates/ra_ide/src/completion/complete_fn_param.rs deleted file mode 100644 index 7c63ce58f..000000000 --- a/crates/ra_ide/src/completion/complete_fn_param.rs +++ /dev/null @@ -1,135 +0,0 @@ -//! See `complete_fn_param`. - -use rustc_hash::FxHashMap; -use syntax::{ - ast::{self, ModuleItemOwner}, - match_ast, AstNode, -}; - -use crate::completion::{CompletionContext, CompletionItem, CompletionKind, Completions}; - -/// Complete repeated parameters, both name and type. For example, if all -/// functions in a file have a `spam: &mut Spam` parameter, a completion with -/// `spam: &mut Spam` insert text/label and `spam` lookup string will be -/// suggested. -pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.is_param { - return; - } - - let mut params = FxHashMap::default(); - - let me = ctx.token.ancestors().find_map(ast::Fn::cast); - let mut process_fn = |func: ast::Fn| { - if Some(&func) == me.as_ref() { - return; - } - func.param_list().into_iter().flat_map(|it| it.params()).for_each(|param| { - let text = param.syntax().text().to_string(); - params.entry(text).or_insert(param); - }) - }; - - for node in ctx.token.parent().ancestors() { - match_ast! { - match node { - ast::SourceFile(it) => it.items().filter_map(|item| match item { - ast::Item::Fn(it) => Some(it), - _ => None, - }).for_each(&mut process_fn), - ast::ItemList(it) => it.items().filter_map(|item| match item { - ast::Item::Fn(it) => Some(it), - _ => None, - }).for_each(&mut process_fn), - ast::AssocItemList(it) => it.assoc_items().filter_map(|item| match item { - ast::AssocItem::Fn(it) => Some(it), - _ => None, - }).for_each(&mut process_fn), - _ => continue, - } - }; - } - - params - .into_iter() - .filter_map(|(label, param)| { - let lookup = param.pat()?.syntax().text().to_string(); - Some((label, lookup)) - }) - .for_each(|(label, lookup)| { - CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label) - .kind(crate::CompletionItemKind::Binding) - .lookup_by(lookup) - .add_to(acc) - }); -} - -#[cfg(test)] -mod tests { - use expect::{expect, Expect}; - - use crate::completion::{test_utils::completion_list, CompletionKind}; - - fn check(ra_fixture: &str, expect: Expect) { - let actual = completion_list(ra_fixture, CompletionKind::Magic); - expect.assert_eq(&actual); - } - - #[test] - fn test_param_completion_last_param() { - check( - r#" -fn foo(file_id: FileId) {} -fn bar(file_id: FileId) {} -fn baz(file<|>) {} -"#, - expect![[r#" - bn file_id: FileId - "#]], - ); - } - - #[test] - fn test_param_completion_nth_param() { - check( - r#" -fn foo(file_id: FileId) {} -fn baz(file<|>, x: i32) {} -"#, - expect![[r#" - bn file_id: FileId - "#]], - ); - } - - #[test] - fn test_param_completion_trait_param() { - check( - r#" -pub(crate) trait SourceRoot { - pub fn contains(&self, file_id: FileId) -> bool; - pub fn module_map(&self) -> &ModuleMap; - pub fn lines(&self, file_id: FileId) -> &LineIndex; - pub fn syntax(&self, file<|>) -} -"#, - expect![[r#" - bn file_id: FileId - "#]], - ); - } - - #[test] - fn completes_param_in_inner_function() { - check( - r#" -fn outer(text: String) { - fn inner(<|>) -} -"#, - expect![[r#" - bn text: String - "#]], - ) - } -} -- cgit v1.2.3