Skip to content

Commit 7ce2df4

Browse files
bors[bot]Jonas Schievink
and
Jonas Schievink
authored
Merge #11969
11969: fix: Add trailing `;` when completing assoc const/type in trait impl r=jonas-schievink a=jonas-schievink Final item of #11860, thus closes #11860 🎉 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents a64a70e + a182156 commit 7ce2df4

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

crates/ide_completion/src/completions/trait_impl.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,17 @@ fn add_type_alias_impl(
228228
let alias_name = type_alias.name(ctx.db).to_smol_str();
229229

230230
let label = format!("type {} =", alias_name);
231-
let snippet = format!("type {} = ", alias_name);
231+
let replacement = format!("type {} = ", alias_name);
232232

233233
let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
234-
item.text_edit(TextEdit::replace(replacement_range, snippet))
235-
.lookup_by(format!("type {}", alias_name))
234+
item.lookup_by(format!("type {}", alias_name))
236235
.set_documentation(type_alias.docs(ctx.db))
237236
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
237+
match ctx.config.snippet_cap {
238+
Some(cap) => item
239+
.snippet_edit(cap, TextEdit::replace(replacement_range, format!("{}$0;", replacement))),
240+
None => item.text_edit(TextEdit::replace(replacement_range, replacement)),
241+
};
238242
item.add_to(acc);
239243
}
240244

@@ -257,16 +261,22 @@ fn add_const_impl(
257261
};
258262

259263
let label = make_const_compl_syntax(&transformed_const);
260-
let snippet = format!("{} ", label);
264+
let replacement = format!("{} ", label);
261265

262266
let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
263-
item.text_edit(TextEdit::replace(replacement_range, snippet))
264-
.lookup_by(format!("const {}", const_name))
267+
item.lookup_by(format!("const {}", const_name))
265268
.set_documentation(const_.docs(ctx.db))
266269
.set_relevance(CompletionRelevance {
267270
is_item_from_trait: true,
268271
..Default::default()
269272
});
273+
match ctx.config.snippet_cap {
274+
Some(cap) => item.snippet_edit(
275+
cap,
276+
TextEdit::replace(replacement_range, format!("{}$0;", replacement)),
277+
),
278+
None => item.text_edit(TextEdit::replace(replacement_range, replacement)),
279+
};
270280
item.add_to(acc);
271281
}
272282
}
@@ -678,7 +688,7 @@ trait Test {
678688
}
679689
680690
impl Test for () {
681-
type SomeType = \n\
691+
type SomeType = $0;\n\
682692
}
683693
",
684694
);
@@ -703,7 +713,7 @@ trait Test {
703713
}
704714
705715
impl Test for () {
706-
const SOME_CONST: u16 = \n\
716+
const SOME_CONST: u16 = $0;\n\
707717
}
708718
",
709719
);
@@ -725,7 +735,7 @@ trait Test {
725735
}
726736
727737
impl Test for () {
728-
const SOME_CONST: u16 = \n\
738+
const SOME_CONST: u16 = $0;\n\
729739
}
730740
",
731741
);
@@ -784,8 +794,8 @@ impl Test for T {{
784794
"default const OTHER_CONST: i32 = 0;",
785795
] {
786796
test("fn bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
787-
test("type Foo", "type $0", "type Foo = ", next_sibling);
788-
test("const CONST", "const $0", "const CONST: u16 = ", next_sibling);
797+
test("type Foo", "type $0", "type Foo = $0;", next_sibling);
798+
test("const CONST", "const $0", "const CONST: u16 = $0;", next_sibling);
789799
}
790800
}
791801

@@ -831,8 +841,8 @@ impl Foo for T {{
831841
)
832842
};
833843
test("fn function", "fn f$0", "fn function() {\n $0\n}");
834-
test("type Type", "type T$0", "type Type = ");
835-
test("const CONST", "const C$0", "const CONST: i32 = ");
844+
test("type Type", "type T$0", "type Type = $0;");
845+
test("const CONST", "const C$0", "const CONST: i32 = $0;");
836846
}
837847

838848
#[test]
@@ -962,7 +972,7 @@ trait Foo<T> {
962972
struct Bar;
963973
964974
impl Foo<u32> for Bar {
965-
const B$0;
975+
const B$0
966976
}
967977
"#,
968978
r#"
@@ -972,7 +982,7 @@ trait Foo<T> {
972982
struct Bar;
973983
974984
impl Foo<u32> for Bar {
975-
const BAR: u32 = ;
985+
const BAR: u32 = $0;
976986
}
977987
"#,
978988
)

0 commit comments

Comments
 (0)