Skip to content

Commit 7e77d4e

Browse files
author
Jonas Schievink
committed
Strip comments and attributes off of all trait item completions
1 parent a516b90 commit 7e77d4e

File tree

1 file changed

+76
-6
lines changed

1 file changed

+76
-6
lines changed

crates/ide-completion/src/completions/item_list/trait_impl.rs

Lines changed: 76 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ fn get_transformed_assoc_item(
236236
);
237237

238238
transform.apply(assoc_item.syntax());
239-
if let ast::AssocItem::Fn(func) = &assoc_item {
240-
func.remove_attrs_and_docs();
241-
}
239+
assoc_item.remove_attrs_and_docs();
242240
Some(assoc_item)
243241
}
244242

@@ -335,7 +333,6 @@ fn add_const_impl(
335333
}
336334

337335
fn make_const_compl_syntax(const_: &ast::Const, needs_whitespace: bool) -> String {
338-
const_.remove_attrs_and_docs();
339336
let const_ = if needs_whitespace {
340337
insert_whitespace_into_node::insert_ws_into(const_.syntax().clone())
341338
} else {
@@ -359,8 +356,6 @@ fn make_const_compl_syntax(const_: &ast::Const, needs_whitespace: bool) -> Strin
359356
}
360357

361358
fn function_declaration(node: &ast::Fn, needs_whitespace: bool) -> String {
362-
node.remove_attrs_and_docs();
363-
364359
let node = if needs_whitespace {
365360
insert_whitespace_into_node::insert_ws_into(node.syntax().clone())
366361
} else {
@@ -1209,6 +1204,81 @@ trait Tr<'b> {
12091204
impl<'b> Tr<'b> for () {
12101205
type Ty<'a: 'b, T: Copy, const C: usize> = $0;
12111206
}
1207+
"#,
1208+
);
1209+
}
1210+
1211+
#[test]
1212+
fn strips_comments() {
1213+
check_edit(
1214+
"fn func",
1215+
r#"
1216+
trait Tr {
1217+
/// docs
1218+
#[attr]
1219+
fn func();
1220+
}
1221+
impl Tr for () {
1222+
$0
1223+
}
1224+
"#,
1225+
r#"
1226+
trait Tr {
1227+
/// docs
1228+
#[attr]
1229+
fn func();
1230+
}
1231+
impl Tr for () {
1232+
fn func() {
1233+
$0
1234+
}
1235+
}
1236+
"#,
1237+
);
1238+
check_edit(
1239+
"const C",
1240+
r#"
1241+
trait Tr {
1242+
/// docs
1243+
#[attr]
1244+
const C: usize;
1245+
}
1246+
impl Tr for () {
1247+
$0
1248+
}
1249+
"#,
1250+
r#"
1251+
trait Tr {
1252+
/// docs
1253+
#[attr]
1254+
const C: usize;
1255+
}
1256+
impl Tr for () {
1257+
const C: usize = $0;
1258+
}
1259+
"#,
1260+
);
1261+
check_edit(
1262+
"type Item",
1263+
r#"
1264+
trait Tr {
1265+
/// docs
1266+
#[attr]
1267+
type Item;
1268+
}
1269+
impl Tr for () {
1270+
$0
1271+
}
1272+
"#,
1273+
r#"
1274+
trait Tr {
1275+
/// docs
1276+
#[attr]
1277+
type Item;
1278+
}
1279+
impl Tr for () {
1280+
type Item = $0;
1281+
}
12121282
"#,
12131283
);
12141284
}

0 commit comments

Comments
 (0)