mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
generate function assist convert arg names to lower snake case
This commit is contained in:
parent
cd60c4f76c
commit
e29b53f1e6
1 changed files with 52 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
use hir::HirDisplay;
|
use hir::HirDisplay;
|
||||||
use ide_db::{base_db::FileId, helpers::SnippetCap};
|
use ide_db::{base_db::FileId, helpers::SnippetCap};
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
use stdx::to_lower_snake_case;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{
|
ast::{
|
||||||
self,
|
self,
|
||||||
|
@ -257,14 +258,15 @@ fn deduplicate_arg_names(arg_names: &mut Vec<String>) {
|
||||||
fn fn_arg_name(fn_arg: &ast::Expr) -> Option<String> {
|
fn fn_arg_name(fn_arg: &ast::Expr) -> Option<String> {
|
||||||
match fn_arg {
|
match fn_arg {
|
||||||
ast::Expr::CastExpr(cast_expr) => fn_arg_name(&cast_expr.expr()?),
|
ast::Expr::CastExpr(cast_expr) => fn_arg_name(&cast_expr.expr()?),
|
||||||
_ => Some(
|
_ => {
|
||||||
fn_arg
|
let s = fn_arg
|
||||||
.syntax()
|
.syntax()
|
||||||
.descendants()
|
.descendants()
|
||||||
.filter(|d| ast::NameRef::can_cast(d.kind()))
|
.filter(|d| ast::NameRef::can_cast(d.kind()))
|
||||||
.last()?
|
.last()?
|
||||||
.to_string(),
|
.to_string();
|
||||||
),
|
Some(to_lower_snake_case(&s))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,6 +449,52 @@ mod baz {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_function_with_upper_camel_case_arg() {
|
||||||
|
check_assist(
|
||||||
|
generate_function,
|
||||||
|
r"
|
||||||
|
struct BazBaz;
|
||||||
|
fn foo() {
|
||||||
|
bar$0(BazBaz);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
struct BazBaz;
|
||||||
|
fn foo() {
|
||||||
|
bar(BazBaz);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(baz_baz: BazBaz) ${0:-> ()} {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_function_with_upper_camel_case_arg_as_cast() {
|
||||||
|
check_assist(
|
||||||
|
generate_function,
|
||||||
|
r"
|
||||||
|
struct BazBaz;
|
||||||
|
fn foo() {
|
||||||
|
bar$0(&BazBaz as *const BazBaz);
|
||||||
|
}
|
||||||
|
",
|
||||||
|
r"
|
||||||
|
struct BazBaz;
|
||||||
|
fn foo() {
|
||||||
|
bar(&BazBaz as *const BazBaz);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar(baz_baz: *const BazBaz) ${0:-> ()} {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_function_with_function_call_arg() {
|
fn add_function_with_function_call_arg() {
|
||||||
check_assist(
|
check_assist(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue