mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
fix: add semicolon after type ascription
This commit is contained in:
parent
610eba3320
commit
233820d780
@ -56,13 +56,20 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<(
|
|||||||
if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
|
if let Some(let_stmt) = ctx.find_node_at_offset::<ast::LetStmt>() {
|
||||||
if let_stmt.colon_token().is_none() {
|
if let_stmt.colon_token().is_none() {
|
||||||
let type_pos = let_stmt.pat()?.syntax().last_token()?.text_range().end();
|
let type_pos = let_stmt.pat()?.syntax().last_token()?.text_range().end();
|
||||||
|
let semi_pos = let_stmt.syntax().last_token()?.text_range().end();
|
||||||
|
|
||||||
acc.add(
|
acc.add(
|
||||||
AssistId("add_type_ascription", AssistKind::RefactorRewrite),
|
AssistId("add_type_ascription", AssistKind::RefactorRewrite),
|
||||||
"Add `: _` before assignment operator",
|
"Add `: _` before assignment operator",
|
||||||
ident.text_range(),
|
ident.text_range(),
|
||||||
|builder| match ctx.config.snippet_cap {
|
|builder| {
|
||||||
Some(cap) => builder.insert_snippet(cap, type_pos, ": ${0:_}"),
|
if let_stmt.semicolon_token().is_none() {
|
||||||
None => builder.insert(type_pos, ": _"),
|
builder.insert(semi_pos, ";");
|
||||||
|
}
|
||||||
|
match ctx.config.snippet_cap {
|
||||||
|
Some(cap) => builder.insert_snippet(cap, type_pos, ": ${0:_}"),
|
||||||
|
None => builder.insert(type_pos, ": _"),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
@ -265,4 +272,24 @@ fn main() {
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_type_ascription_append_semicolon() {
|
||||||
|
check_assist_by_label(
|
||||||
|
add_turbo_fish,
|
||||||
|
r#"
|
||||||
|
fn make<T>() -> T {}
|
||||||
|
fn main() {
|
||||||
|
let x = make$0()
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn make<T>() -> T {}
|
||||||
|
fn main() {
|
||||||
|
let x: ${0:_} = make();
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
"Add `: _` before assignment operator",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user