diff --git a/crates/ide-assists/src/assist_config.rs b/crates/ide-assists/src/assist_config.rs index fb533077d9..05105c8c92 100644 --- a/crates/ide-assists/src/assist_config.rs +++ b/crates/ide-assists/src/assist_config.rs @@ -20,6 +20,7 @@ pub struct AssistConfig { pub assist_emit_must_use: bool, pub term_search_fuel: u64, pub term_search_borrowck: bool, + pub code_action_grouping: bool, } impl AssistConfig { diff --git a/crates/ide-assists/src/handlers/generate_delegate_methods.rs b/crates/ide-assists/src/handlers/generate_delegate_methods.rs index 081e36b4ff..220259451e 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_methods.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_methods.rs @@ -48,6 +48,10 @@ use crate::{ // } // ``` pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { + if !ctx.config.code_action_grouping { + return None; + } + let strukt = ctx.find_node_at_offset::()?; let strukt_name = strukt.name()?; let current_module = ctx.sema.scope(strukt.syntax())?.module(); @@ -213,7 +217,9 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<' #[cfg(test)] mod tests { - use crate::tests::{check_assist, check_assist_not_applicable}; + use crate::tests::{ + check_assist, check_assist_not_applicable, check_assist_not_applicable_no_grouping, + }; use super::*; @@ -717,4 +723,21 @@ impl Person { "#, ); } + + #[test] + fn delegate_method_skipped_when_no_grouping() { + check_assist_not_applicable_no_grouping( + generate_delegate_methods, + r#" +struct Age(u8); +impl Age { + fn age(&self) -> u8 { + self.0 + } +} +struct Person { + ag$0e: Age, +}"#, + ); + } } diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 66bf9b0186..55b860d0ff 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -88,6 +88,10 @@ use syntax::{ // } // ``` pub(crate) fn generate_delegate_trait(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> { + if !ctx.config.code_action_grouping { + return None; + } + let strukt = Struct::new(ctx.find_node_at_offset::()?)?; let field: Field = match ctx.find_node_at_offset::() { @@ -788,7 +792,9 @@ fn qualified_path(qual_path_ty: ast::Path, path_expr_seg: ast::Path) -> ast::Pat mod test { use super::*; - use crate::tests::{check_assist, check_assist_not_applicable}; + use crate::tests::{ + check_assist, check_assist_not_applicable, check_assist_not_applicable_no_grouping, + }; #[test] fn test_tuple_struct_basic() { @@ -1836,4 +1842,33 @@ impl> C for B { "#, ) } + + #[test] + fn delegate_trait_skipped_when_no_grouping() { + check_assist_not_applicable_no_grouping( + generate_delegate_trait, + r#" +trait SomeTrait { + type T; + fn fn_(arg: u32) -> u32; + fn method_(&mut self) -> bool; +} +struct A; +impl SomeTrait for A { + type T = u32; + + fn fn_(arg: u32) -> u32 { + 42 + } + + fn method_(&mut self) -> bool { + false + } +} +struct B { + a$0 : A, +} +"#, + ); + } } diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 48d2af6d3f..11aeb21c77 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -34,6 +34,26 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { assist_emit_must_use: false, term_search_fuel: 400, term_search_borrowck: true, + code_action_grouping: true, +}; + +pub(crate) const TEST_CONFIG_NO_GROUPING: AssistConfig = AssistConfig { + snippet_cap: SnippetCap::new(true), + allowed: None, + insert_use: InsertUseConfig { + granularity: ImportGranularity::Crate, + prefix_kind: hir::PrefixKind::Plain, + enforce_granularity: true, + group: true, + skip_glob_imports: true, + }, + prefer_no_std: false, + prefer_prelude: true, + prefer_absolute: false, + assist_emit_must_use: false, + term_search_fuel: 400, + term_search_borrowck: true, + code_action_grouping: false, }; pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig { @@ -52,6 +72,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig { assist_emit_must_use: false, term_search_fuel: 400, term_search_borrowck: true, + code_action_grouping: true, }; pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig { @@ -70,6 +91,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig { assist_emit_must_use: false, term_search_fuel: 400, term_search_borrowck: true, + code_action_grouping: true, }; pub(crate) fn with_single_file(text: &str) -> (RootDatabase, EditionedFileId) { @@ -173,6 +195,20 @@ pub(crate) fn check_assist_not_applicable_for_import_one( ); } +#[track_caller] +pub(crate) fn check_assist_not_applicable_no_grouping( + assist: Handler, + #[rust_analyzer::rust_fixture] ra_fixture: &str, +) { + check_with_config( + TEST_CONFIG_NO_GROUPING, + assist, + ra_fixture, + ExpectedResult::NotApplicable, + None, + ); +} + /// Check assist in unresolved state. Useful to check assists for lazy computation. #[track_caller] pub(crate) fn check_assist_unresolved( diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index d7e9a5c586..1dce0bea1a 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs @@ -1476,6 +1476,7 @@ impl Config { prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(), term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64, term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(), + code_action_grouping: self.code_action_group(), } }