mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Generate implementation with items even if snippet text edit is disabled
This commit is contained in:
parent
b707b5a117
commit
fc2b70132f
@ -139,7 +139,7 @@ fn add_assist(
|
|||||||
let trait_path = make::ty_path(replace_trait_path.clone());
|
let trait_path = make::ty_path(replace_trait_path.clone());
|
||||||
|
|
||||||
match (ctx.config.snippet_cap, impl_def_with_items) {
|
match (ctx.config.snippet_cap, impl_def_with_items) {
|
||||||
(None, _) => {
|
(None, None) => {
|
||||||
let impl_def = generate_trait_impl(adt, trait_path);
|
let impl_def = generate_trait_impl(adt, trait_path);
|
||||||
|
|
||||||
ted::insert_all(
|
ted::insert_all(
|
||||||
@ -147,6 +147,12 @@ fn add_assist(
|
|||||||
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
|
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
(None, Some((impl_def, _))) => {
|
||||||
|
ted::insert_all(
|
||||||
|
insert_after,
|
||||||
|
vec![make::tokens::blank_line().into(), impl_def.syntax().clone().into()],
|
||||||
|
);
|
||||||
|
}
|
||||||
(Some(cap), None) => {
|
(Some(cap), None) => {
|
||||||
let impl_def = generate_trait_impl(adt, trait_path);
|
let impl_def = generate_trait_impl(adt, trait_path);
|
||||||
|
|
||||||
@ -272,7 +278,7 @@ fn update_attribute(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::tests::{check_assist, check_assist_not_applicable};
|
use crate::tests::{check_assist, check_assist_no_snippet_cap, check_assist_not_applicable};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
@ -297,6 +303,30 @@ impl core::fmt::Debug for Foo {
|
|||||||
f.debug_struct("Foo").field("bar", &self.bar).finish()
|
f.debug_struct("Foo").field("bar", &self.bar).finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn add_custom_impl_without_snippet() {
|
||||||
|
check_assist_no_snippet_cap(
|
||||||
|
replace_derive_with_manual_impl,
|
||||||
|
r#"
|
||||||
|
//- minicore: fmt, derive
|
||||||
|
#[derive(Debu$0g)]
|
||||||
|
struct Foo {
|
||||||
|
bar: String,
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
struct Foo {
|
||||||
|
bar: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl core::fmt::Debug for Foo {
|
||||||
|
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||||
|
f.debug_struct("Foo").field("bar", &self.bar).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user