aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-09 15:59:52 +0100
committerAleksey Kladov <[email protected]>2021-05-09 16:01:54 +0100
commit984d20aad8445ecbdc05d1dc3ea2de104c685af0 (patch)
tree6de21908b9bb59d7d171fe76bb289a42de294257
parentd9c9f6dc2cd3080009c4ce2c3f0f340949f4f53c (diff)
cleanups
-rw-r--r--crates/ide_assists/src/handlers/extract_variable.rs2
-rw-r--r--crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs2
-rw-r--r--crates/ide_assists/src/utils/suggest_name.rs7
3 files changed, 6 insertions, 5 deletions
diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs
index 136b9a55b..ae084c86c 100644
--- a/crates/ide_assists/src/handlers/extract_variable.rs
+++ b/crates/ide_assists/src/handlers/extract_variable.rs
@@ -54,7 +54,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
54 54
55 let var_name = match &field_shorthand { 55 let var_name = match &field_shorthand {
56 Some(it) => it.to_string(), 56 Some(it) => it.to_string(),
57 None => suggest_name::variable(&to_extract, &ctx.sema), 57 None => suggest_name::for_variable(&to_extract, &ctx.sema),
58 }; 58 };
59 let expr_range = match &field_shorthand { 59 let expr_range = match &field_shorthand {
60 Some(it) => it.syntax().text_range().cover(to_extract.syntax().text_range()), 60 Some(it) => it.syntax().text_range().cover(to_extract.syntax().text_range()),
diff --git a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
index 26a0e81f0..899c773df 100644
--- a/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
+++ b/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs
@@ -29,7 +29,7 @@ pub(crate) fn replace_impl_trait_with_generic(
29 "Replace impl trait with generic", 29 "Replace impl trait with generic",
30 target, 30 target,
31 |edit| { 31 |edit| {
32 let type_param_name = suggest_name::generic_parameter(&impl_trait_type); 32 let type_param_name = suggest_name::for_generic_parameter(&impl_trait_type);
33 33
34 let generic_param_list = fn_ 34 let generic_param_list = fn_
35 .generic_param_list() 35 .generic_param_list()
diff --git a/crates/ide_assists/src/utils/suggest_name.rs b/crates/ide_assists/src/utils/suggest_name.rs
index c8487846d..b3aabeab3 100644
--- a/crates/ide_assists/src/utils/suggest_name.rs
+++ b/crates/ide_assists/src/utils/suggest_name.rs
@@ -57,7 +57,7 @@ const USELESS_METHODS: &[&str] = &[
57 "iter_mut", 57 "iter_mut",
58]; 58];
59 59
60pub(crate) fn generic_parameter(ty: &ast::ImplTraitType) -> SmolStr { 60pub(crate) fn for_generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
61 let c = ty 61 let c = ty
62 .type_bound_list() 62 .type_bound_list()
63 .and_then(|bounds| bounds.syntax().text().char_at(0.into())) 63 .and_then(|bounds| bounds.syntax().text().char_at(0.into()))
@@ -83,7 +83,8 @@ pub(crate) fn generic_parameter(ty: &ast::ImplTraitType) -> SmolStr {
83/// It also applies heuristics to filter out less informative names 83/// It also applies heuristics to filter out less informative names
84/// 84///
85/// Currently it sticks to the first name found. 85/// Currently it sticks to the first name found.
86pub(crate) fn variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String { 86// FIXME: Microoptimize and return a `SmolStr` here.
87pub(crate) fn for_variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
87 // `from_param` does not benifit from stripping 88 // `from_param` does not benifit from stripping
88 // it need the largest context possible 89 // it need the largest context possible
89 // so we check firstmost 90 // so we check firstmost
@@ -284,7 +285,7 @@ mod tests {
284 frange.range, 285 frange.range,
285 "selection is not an expression(yet contained in one)" 286 "selection is not an expression(yet contained in one)"
286 ); 287 );
287 let name = variable(&expr, &sema); 288 let name = for_variable(&expr, &sema);
288 assert_eq!(&name, expected); 289 assert_eq!(&name, expected);
289 } 290 }
290 291