Fix 19090

This commit is contained in:
Ali Bektas 2025-02-18 20:49:43 +01:00
parent 957d3450da
commit fc10fe44de
5 changed files with 67 additions and 0 deletions

View file

@ -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 {

View file

@ -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::<ast::Struct>()?;
let strukt_name = strukt.name()?;
let current_module = ctx.sema.scope(strukt.syntax())?.module();

View file

@ -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::<ast::Struct>()?)?;
let field: Field = match ctx.find_node_at_offset::<ast::RecordField>() {

View file

@ -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::<String>()
}
#[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 }";

View file

@ -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(),
}
}