Skip to content

Commit 1ed0471

Browse files
Merge pull request #19179 from alibektas/19090_new
Ignore assists with many results if grouping not supported
2 parents e6c1e6c + 6100c2c commit 1ed0471

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/assist_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct AssistConfig {
2020
pub assist_emit_must_use: bool,
2121
pub term_search_fuel: u64,
2222
pub term_search_borrowck: bool,
23+
pub code_action_grouping: bool,
2324
}
2425

2526
impl AssistConfig {

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_methods.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ use crate::{
4848
// }
4949
// ```
5050
pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
51+
if !ctx.config.code_action_grouping {
52+
return None;
53+
}
54+
5155
let strukt = ctx.find_node_at_offset::<ast::Struct>()?;
5256
let strukt_name = strukt.name()?;
5357
let current_module = ctx.sema.scope(strukt.syntax())?.module();
@@ -213,7 +217,9 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
213217

214218
#[cfg(test)]
215219
mod tests {
216-
use crate::tests::{check_assist, check_assist_not_applicable};
220+
use crate::tests::{
221+
check_assist, check_assist_not_applicable, check_assist_not_applicable_no_grouping,
222+
};
217223

218224
use super::*;
219225

@@ -717,4 +723,21 @@ impl Person {
717723
"#,
718724
);
719725
}
726+
727+
#[test]
728+
fn delegate_method_skipped_when_no_grouping() {
729+
check_assist_not_applicable_no_grouping(
730+
generate_delegate_methods,
731+
r#"
732+
struct Age(u8);
733+
impl Age {
734+
fn age(&self) -> u8 {
735+
self.0
736+
}
737+
}
738+
struct Person {
739+
ag$0e: Age,
740+
}"#,
741+
);
742+
}
720743
}

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ use syntax::{
8888
// }
8989
// ```
9090
pub(crate) fn generate_delegate_trait(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
91+
if !ctx.config.code_action_grouping {
92+
return None;
93+
}
94+
9195
let strukt = Struct::new(ctx.find_node_at_offset::<ast::Struct>()?)?;
9296

9397
let field: Field = match ctx.find_node_at_offset::<ast::RecordField>() {
@@ -788,7 +792,9 @@ fn qualified_path(qual_path_ty: ast::Path, path_expr_seg: ast::Path) -> ast::Pat
788792
mod test {
789793

790794
use super::*;
791-
use crate::tests::{check_assist, check_assist_not_applicable};
795+
use crate::tests::{
796+
check_assist, check_assist_not_applicable, check_assist_not_applicable_no_grouping,
797+
};
792798

793799
#[test]
794800
fn test_tuple_struct_basic() {
@@ -1836,4 +1842,33 @@ impl<D, T: C<A>> C<D> for B<T> {
18361842
"#,
18371843
)
18381844
}
1845+
1846+
#[test]
1847+
fn delegate_trait_skipped_when_no_grouping() {
1848+
check_assist_not_applicable_no_grouping(
1849+
generate_delegate_trait,
1850+
r#"
1851+
trait SomeTrait {
1852+
type T;
1853+
fn fn_(arg: u32) -> u32;
1854+
fn method_(&mut self) -> bool;
1855+
}
1856+
struct A;
1857+
impl SomeTrait for A {
1858+
type T = u32;
1859+
1860+
fn fn_(arg: u32) -> u32 {
1861+
42
1862+
}
1863+
1864+
fn method_(&mut self) -> bool {
1865+
false
1866+
}
1867+
}
1868+
struct B {
1869+
a$0 : A,
1870+
}
1871+
"#,
1872+
);
1873+
}
18391874
}

src/tools/rust-analyzer/crates/ide-assists/src/tests.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig {
3434
assist_emit_must_use: false,
3535
term_search_fuel: 400,
3636
term_search_borrowck: true,
37+
code_action_grouping: true,
38+
};
39+
40+
pub(crate) const TEST_CONFIG_NO_GROUPING: AssistConfig = AssistConfig {
41+
snippet_cap: SnippetCap::new(true),
42+
allowed: None,
43+
insert_use: InsertUseConfig {
44+
granularity: ImportGranularity::Crate,
45+
prefix_kind: hir::PrefixKind::Plain,
46+
enforce_granularity: true,
47+
group: true,
48+
skip_glob_imports: true,
49+
},
50+
prefer_no_std: false,
51+
prefer_prelude: true,
52+
prefer_absolute: false,
53+
assist_emit_must_use: false,
54+
term_search_fuel: 400,
55+
term_search_borrowck: true,
56+
code_action_grouping: false,
3757
};
3858

3959
pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
@@ -52,6 +72,7 @@ pub(crate) const TEST_CONFIG_NO_SNIPPET_CAP: AssistConfig = AssistConfig {
5272
assist_emit_must_use: false,
5373
term_search_fuel: 400,
5474
term_search_borrowck: true,
75+
code_action_grouping: true,
5576
};
5677

5778
pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
@@ -70,6 +91,7 @@ pub(crate) const TEST_CONFIG_IMPORT_ONE: AssistConfig = AssistConfig {
7091
assist_emit_must_use: false,
7192
term_search_fuel: 400,
7293
term_search_borrowck: true,
94+
code_action_grouping: true,
7395
};
7496

7597
pub(crate) fn with_single_file(text: &str) -> (RootDatabase, EditionedFileId) {
@@ -173,6 +195,20 @@ pub(crate) fn check_assist_not_applicable_for_import_one(
173195
);
174196
}
175197

198+
#[track_caller]
199+
pub(crate) fn check_assist_not_applicable_no_grouping(
200+
assist: Handler,
201+
#[rust_analyzer::rust_fixture] ra_fixture: &str,
202+
) {
203+
check_with_config(
204+
TEST_CONFIG_NO_GROUPING,
205+
assist,
206+
ra_fixture,
207+
ExpectedResult::NotApplicable,
208+
None,
209+
);
210+
}
211+
176212
/// Check assist in unresolved state. Useful to check assists for lazy computation.
177213
#[track_caller]
178214
pub(crate) fn check_assist_unresolved(

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ impl Config {
14761476
prefer_absolute: self.imports_prefixExternPrelude(source_root).to_owned(),
14771477
term_search_fuel: self.assist_termSearch_fuel(source_root).to_owned() as u64,
14781478
term_search_borrowck: self.assist_termSearch_borrowcheck(source_root).to_owned(),
1479+
code_action_grouping: self.code_action_group(),
14791480
}
14801481
}
14811482

0 commit comments

Comments
 (0)