Add const parameter keyword completion

Example
---
```rust
fn foo<c$0>() {}
```
->
```rust
fn foo<const $1: $0>() {}
```
This commit is contained in:
A4-Tacks 2025-09-23 11:26:52 +08:00
parent 06ee0ef31f
commit c241ff4089
No known key found for this signature in database
GPG key ID: DBD861323040663B
2 changed files with 28 additions and 1 deletions

View file

@ -691,6 +691,9 @@ pub(super) fn complete_name(
NameKind::RecordField => {
field::complete_field_list_record_variant(acc, ctx);
}
NameKind::TypeParam => {
acc.add_keyword_snippet(ctx, "const", "const $1: $0");
}
NameKind::ConstParam
| NameKind::Enum
| NameKind::MacroDef
@ -700,7 +703,6 @@ pub(super) fn complete_name(
| NameKind::Static
| NameKind::Struct
| NameKind::Trait
| NameKind::TypeParam
| NameKind::Union
| NameKind::Variant => (),
}

View file

@ -1510,3 +1510,28 @@ fn foo<T>() {
"#]],
);
}
#[test]
fn fn_generic_params_const_param_snippet() {
check_edit("const", "fn foo<c$0>() {}", "fn foo<const $1: $0>() {}");
check_edit("const", "fn foo<T, c$0>() {}", "fn foo<T, const $1: $0>() {}");
check(
r#"
fn foo<T: $0>() {}
"#,
expect![[r#"
kw crate::
kw self::
"#]],
);
check(
r#"
fn foo<const N: $0>() {}
"#,
expect![[r#"
bt u32 u32
kw crate::
kw self::
"#]],
);
}