From 9b0b59c5d2eb1eee8ef16118ddd20ad1302f2c62 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 11 Mar 2020 10:39:39 +0100 Subject: Add a test for disabled argument snippets --- crates/ra_ide/src/completion.rs | 2 +- crates/ra_ide/src/completion/completion_item.rs | 12 +++++-- crates/ra_ide/src/completion/presentation.rs | 48 +++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 5 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion.rs b/crates/ra_ide/src/completion.rs index a27e0fc15..ed1ab65af 100644 --- a/crates/ra_ide/src/completion.rs +++ b/crates/ra_ide/src/completion.rs @@ -20,7 +20,7 @@ mod complete_trait_impl; use ra_ide_db::RootDatabase; #[cfg(test)] -use crate::completion::completion_item::do_completion; +use crate::completion::completion_item::{do_completion, do_completion_with_options}; use crate::{ completion::{ completion_context::CompletionContext, diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs index 1d14e9636..ef6848607 100644 --- a/crates/ra_ide/src/completion/completion_item.rs +++ b/crates/ra_ide/src/completion/completion_item.rs @@ -321,8 +321,17 @@ impl Into> for Completions { #[cfg(test)] pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { + do_completion_with_options(code, kind, &crate::completion::CompletionOptions::default()) +} + +#[cfg(test)] +pub(crate) fn do_completion_with_options( + code: &str, + kind: CompletionKind, + options: &crate::completion::CompletionOptions, +) -> Vec { use crate::{ - completion::{completions, CompletionOptions}, + completion::completions, mock_analysis::{analysis_and_position, single_file_with_position}, }; @@ -331,7 +340,6 @@ pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec = completions.into(); let mut kind_completions: Vec = diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 3dc56e4a3..5fc8b483c 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -307,12 +307,22 @@ mod tests { use insta::assert_debug_snapshot; use test_utils::covers; - use crate::completion::{do_completion, CompletionItem, CompletionKind}; + use crate::completion::{ + do_completion, do_completion_with_options, CompletionItem, CompletionKind, + CompletionOptions, + }; fn do_reference_completion(ra_fixture: &str) -> Vec { do_completion(ra_fixture, CompletionKind::Reference) } + fn do_reference_completion_with_options( + ra_fixture: &str, + options: CompletionOptions, + ) -> Vec { + do_completion_with_options(ra_fixture, CompletionKind::Reference, &options) + } + #[test] fn enum_detail_includes_names_for_record() { assert_debug_snapshot!( @@ -533,7 +543,7 @@ mod tests { } #[test] - fn parens_for_method_call() { + fn arg_snippets_for_method_call() { assert_debug_snapshot!( do_reference_completion( r" @@ -562,6 +572,40 @@ mod tests { ) } + #[test] + fn no_arg_snippets_for_method_call() { + assert_debug_snapshot!( + do_reference_completion_with_options( + r" + struct S {} + impl S { + fn foo(&self, x: i32) {} + } + fn bar(s: &S) { + s.f<|> + } + ", + CompletionOptions { + add_call_argument_snippets: false, + .. Default::default() + } + ), + @r###" + [ + CompletionItem { + label: "foo(…)", + source_range: [171; 172), + delete: [171; 172), + insert: "foo($0)", + kind: Method, + lookup: "foo", + detail: "fn foo(&self, x: i32)", + }, + ] + "### + ) + } + #[test] fn dont_render_function_parens_in_use_item() { assert_debug_snapshot!( -- cgit v1.2.3