Skip to content

Commit b207e57

Browse files
committed
refactor: move ide_assist::utils::suggest_name to ide-db
1 parent 779d9ee commit b207e57

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

crates/ide-assists/src/handlers/extract_variable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use hir::TypeInfo;
2+
use ide_db::syntax_helpers::suggest_name;
23
use syntax::{
34
ast::{self, edit::IndentLevel, edit_in_place::Indent, make, AstNode, HasName},
45
ted, NodeOrToken,
56
SyntaxKind::{BLOCK_EXPR, BREAK_EXPR, COMMENT, LOOP_EXPR, MATCH_GUARD, PATH_EXPR, RETURN_EXPR},
67
SyntaxNode, T,
78
};
89

9-
use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
10+
use crate::{AssistContext, AssistId, AssistKind, Assists};
1011

1112
// Assist: extract_variable
1213
//

crates/ide-assists/src/handlers/generate_delegate_trait.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use std::ops::Not;
22

33
use crate::{
44
assist_context::{AssistContext, Assists},
5-
utils::{convert_param_list_to_arg_list, suggest_name},
5+
utils::convert_param_list_to_arg_list,
66
};
77
use either::Either;
88
use hir::{db::HirDatabase, HasVisibility};
99
use ide_db::{
1010
assists::{AssistId, GroupLabel},
1111
path_transform::PathTransform,
12+
syntax_helpers::suggest_name,
1213
FxHashMap, FxHashSet,
1314
};
1415
use itertools::Itertools;

crates/ide-assists/src/handlers/introduce_named_generic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use ide_db::syntax_helpers::suggest_name;
12
use syntax::{
23
ast::{self, edit_in_place::GenericParamsOwnerEdit, make, AstNode, HasGenericParams},
34
ted,
45
};
56

6-
use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
7+
use crate::{AssistContext, AssistId, AssistKind, Assists};
78

89
// Assist: introduce_named_generic
910
//

crates/ide-assists/src/handlers/replace_is_method_with_if_let_method.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use ide_db::syntax_helpers::suggest_name;
12
use syntax::{
23
ast::{self, make, AstNode},
34
ted,
45
};
56

6-
use crate::{utils::suggest_name, AssistContext, AssistId, AssistKind, Assists};
7+
use crate::{AssistContext, AssistId, AssistKind, Assists};
78

89
// Assist: replace_is_some_with_if_let_some
910
//

crates/ide-assists/src/utils.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use crate::assist_context::{AssistContext, SourceChangeBuilder};
2323

2424
mod gen_trait_fn_body;
2525
pub(crate) mod ref_field_expr;
26-
pub(crate) mod suggest_name;
2726

2827
pub(crate) fn unwrap_trivial_block(block_expr: ast::BlockExpr) -> ast::Expr {
2928
extract_trivial_expression(&block_expr)

crates/ide-db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub mod syntax_helpers {
3838
pub mod format_string_exprs;
3939
pub use hir::insert_whitespace_into_node;
4040
pub mod node_ext;
41+
pub mod suggest_name;
4142

4243
pub use parser::LexedStr;
4344
}

crates/ide-assists/src/utils/suggest_name.rs renamed to crates/ide-db/src/syntax_helpers/suggest_name.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//! This module contains functions to suggest names for expressions, functions and other items
22
33
use hir::Semantics;
4-
use ide_db::{FxHashSet, RootDatabase};
54
use itertools::Itertools;
5+
use rustc_hash::FxHashSet;
66
use stdx::to_lower_snake_case;
77
use syntax::{
88
ast::{self, HasName},
99
match_ast, AstNode, Edition, SmolStr,
1010
};
1111

12+
use crate::RootDatabase;
13+
1214
/// Trait names, that will be ignored when in `impl Trait` and `dyn Trait`
1315
const USELESS_TRAITS: &[&str] = &["Send", "Sync", "Copy", "Clone", "Eq", "PartialEq"];
1416

@@ -66,10 +68,7 @@ const USELESS_METHODS: &[&str] = &[
6668
/// The function checks if the name conflicts with existing generic parameters.
6769
/// If so, it will try to resolve the conflict by adding a number suffix, e.g.
6870
/// `T`, `T0`, `T1`, ...
69-
pub(crate) fn for_unique_generic_name(
70-
name: &str,
71-
existing_params: &ast::GenericParamList,
72-
) -> SmolStr {
71+
pub fn for_unique_generic_name(name: &str, existing_params: &ast::GenericParamList) -> SmolStr {
7372
let param_names = existing_params
7473
.generic_params()
7574
.map(|param| match param {
@@ -101,7 +100,7 @@ pub(crate) fn for_unique_generic_name(
101100
///
102101
/// If the name conflicts with existing generic parameters, it will try to
103102
/// resolve the conflict with `for_unique_generic_name`.
104-
pub(crate) fn for_impl_trait_as_generic(
103+
pub fn for_impl_trait_as_generic(
105104
ty: &ast::ImplTraitType,
106105
existing_params: &ast::GenericParamList,
107106
) -> SmolStr {
@@ -132,7 +131,7 @@ pub(crate) fn for_impl_trait_as_generic(
132131
///
133132
/// Currently it sticks to the first name found.
134133
// FIXME: Microoptimize and return a `SmolStr` here.
135-
pub(crate) fn for_variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
134+
pub fn for_variable(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> String {
136135
// `from_param` does not benefit from stripping
137136
// it need the largest context possible
138137
// so we check firstmost
@@ -184,7 +183,7 @@ fn normalize(name: &str) -> Option<String> {
184183

185184
fn is_valid_name(name: &str) -> bool {
186185
matches!(
187-
ide_db::syntax_helpers::LexedStr::single_token(syntax::Edition::CURRENT_FIXME, name),
186+
super::LexedStr::single_token(syntax::Edition::CURRENT_FIXME, name),
188187
Some((syntax::SyntaxKind::IDENT, _error))
189188
)
190189
}

0 commit comments

Comments
 (0)