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..03ec60bede 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(); diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 66bf9b0186..6a4541e4fe 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::() { diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 48d2af6d3f..87851e445d 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) { @@ -346,6 +368,41 @@ fn labels(assists: &[Assist]) -> String { labels.into_iter().collect::() } +#[test] +fn long_groups_are_skipped_under_skip_resolve_strategy() { + let before = 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, +} + "#; + let (before_cursor_pos, before) = extract_offset(before); + let (db, file_id) = with_single_file(&before); + let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) }; + let res = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange.into()); + assert!(res.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" })); + + let limited = + assists(&db, &TEST_CONFIG_NO_GROUPING, AssistResolveStrategy::None, frange.into()); + assert!(!limited.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" })); +} + #[test] fn assist_order_field_struct() { let before = "struct Foo { $0bar: u32 }"; 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(), } }