mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 11:20:54 +00:00
Merge pull request #19179 from alibektas/19090_new
Ignore assists with many results if grouping not supported
This commit is contained in:
commit
3028f844c5
@ -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 {
|
||||
|
@ -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();
|
||||
@ -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,
|
||||
}"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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>() {
|
||||
@ -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<D, T: C<A>> C<D> for B<T> {
|
||||
"#,
|
||||
)
|
||||
}
|
||||
|
||||
#[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,
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user