Skip to content

Commit ebe8c48

Browse files
committed
Fix 19090
1 parent 78b7390 commit ebe8c48

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
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: 4 additions & 0 deletions
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();

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

Lines changed: 4 additions & 0 deletions
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>() {

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

Lines changed: 57 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) {
@@ -346,6 +368,41 @@ fn labels(assists: &[Assist]) -> String {
346368
labels.into_iter().collect::<String>()
347369
}
348370

371+
#[test]
372+
fn long_groups_are_skipped_under_skip_resolve_strategy() {
373+
let before = r#"
374+
trait SomeTrait {
375+
type T;
376+
fn fn_(arg: u32) -> u32;
377+
fn method_(&mut self) -> bool;
378+
}
379+
struct A;
380+
impl SomeTrait for A {
381+
type T = u32;
382+
383+
fn fn_(arg: u32) -> u32 {
384+
42
385+
}
386+
387+
fn method_(&mut self) -> bool {
388+
false
389+
}
390+
}
391+
struct B {
392+
a$0 : A,
393+
}
394+
"#;
395+
let (before_cursor_pos, before) = extract_offset(before);
396+
let (db, file_id) = with_single_file(&before);
397+
let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
398+
let res = assists(&db, &TEST_CONFIG, AssistResolveStrategy::None, frange.into());
399+
assert!(res.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" }));
400+
401+
let limited =
402+
assists(&db, &TEST_CONFIG_NO_GROUPING, AssistResolveStrategy::None, frange.into());
403+
assert!(!limited.iter().map(|a| &a.id).any(|a| { a.0 == "generate_delegate_trait" }));
404+
}
405+
349406
#[test]
350407
fn assist_order_field_struct() {
351408
let before = "struct Foo { $0bar: u32 }";

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)