Skip to content

Commit f4ae365

Browse files
Extract the import code into the shared module
1 parent 0993f90 commit f4ae365

30 files changed

+298
-254
lines changed

Cargo.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/assists/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ doctest = false
1212
[dependencies]
1313
rustc-hash = "1.1.0"
1414
itertools = "0.9.0"
15-
either = "1.5.3"
15+
either = "1.6.1"
1616

1717
stdx = { path = "../stdx", version = "0.0.0" }
1818
syntax = { path = "../syntax", version = "0.0.0" }
@@ -21,3 +21,4 @@ profile = { path = "../profile", version = "0.0.0" }
2121
ide_db = { path = "../ide_db", version = "0.0.0" }
2222
hir = { path = "../hir", version = "0.0.0" }
2323
test_utils = { path = "../test_utils", version = "0.0.0" }
24+
ide_helpers = { path = "../ide_helpers", version = "0.0.0" }

crates/assists/src/assist_config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
//! assists if we are allowed to.
66
77
use hir::PrefixKind;
8+
use ide_helpers::insert_use::MergeBehaviour;
89

9-
use crate::{utils::MergeBehaviour, AssistKind};
10+
use crate::AssistKind;
1011

1112
#[derive(Clone, Debug, PartialEq, Eq)]
1213
pub struct AssistConfig {

crates/assists/src/ast_transform.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
22
use hir::{HirDisplay, PathResolution, SemanticsScope};
3+
use ide_helpers::mod_path_to_ast;
34
use rustc_hash::FxHashMap;
45
use syntax::{
56
algo::SyntaxRewriter,
67
ast::{self, AstNode},
78
SyntaxNode,
89
};
910

10-
use crate::utils::mod_path_to_ast;
11-
1211
pub fn apply<'a, N: AstNode>(transformer: &dyn AstTransform<'a>, node: N) -> N {
1312
SyntaxRewriter::from_fn(|element| match element {
1413
syntax::SyntaxElement::Node(n) => {

crates/assists/src/handlers/auto_import.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use ide_helpers::{
2+
insert_use::{insert_use, ImportScope},
3+
mod_path_to_ast,
4+
};
15
use syntax::ast;
26

37
use crate::{
48
utils::import_assets::{ImportAssets, ImportCandidate},
5-
utils::{insert_use, mod_path_to_ast, ImportScope},
69
AssistContext, AssistId, AssistKind, Assists, GroupLabel,
710
};
811

crates/assists/src/handlers/extract_struct_from_enum_variant.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ use std::iter;
33
use either::Either;
44
use hir::{AsName, EnumVariant, Module, ModuleDef, Name};
55
use ide_db::{defs::Definition, search::Reference, RootDatabase};
6+
use ide_helpers::{
7+
insert_use::{insert_use, ImportScope},
8+
mod_path_to_ast,
9+
};
610
use rustc_hash::{FxHashMap, FxHashSet};
711
use syntax::{
812
algo::{find_node_at_offset, SyntaxRewriter},
913
ast::{self, edit::IndentLevel, make, AstNode, NameOwner, VisibilityOwner},
1014
SourceFile, SyntaxElement, SyntaxNode, T,
1115
};
1216

13-
use crate::{
14-
utils::{insert_use, mod_path_to_ast, ImportScope},
15-
AssistContext, AssistId, AssistKind, Assists,
16-
};
17+
use crate::{AssistContext, AssistId, AssistKind, Assists};
1718

1819
// Assist: extract_struct_from_enum_variant
1920
//
@@ -236,10 +237,9 @@ fn update_reference(
236237

237238
#[cfg(test)]
238239
mod tests {
239-
use crate::{
240-
tests::{check_assist, check_assist_not_applicable},
241-
utils::FamousDefs,
242-
};
240+
use ide_helpers::FamousDefs;
241+
242+
use crate::tests::{check_assist, check_assist_not_applicable};
243243

244244
use super::*;
245245

crates/assists/src/handlers/fill_match_arms.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ use std::iter;
22

33
use hir::{Adt, HasSource, ModuleDef, Semantics};
44
use ide_db::RootDatabase;
5+
use ide_helpers::{mod_path_to_ast, FamousDefs};
56
use itertools::Itertools;
67
use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
78
use test_utils::mark;
89

910
use crate::{
10-
utils::{mod_path_to_ast, render_snippet, Cursor, FamousDefs},
11+
utils::{render_snippet, Cursor},
1112
AssistContext, AssistId, AssistKind, Assists,
1213
};
1314

@@ -212,12 +213,10 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O
212213

213214
#[cfg(test)]
214215
mod tests {
216+
use ide_helpers::FamousDefs;
215217
use test_utils::mark;
216218

217-
use crate::{
218-
tests::{check_assist, check_assist_not_applicable, check_assist_target},
219-
utils::FamousDefs,
220-
};
219+
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};
221220

222221
use super::fill_match_arms;
223222

crates/assists/src/handlers/generate_from_impl_for_enum.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use ide_db::RootDatabase;
2+
use ide_helpers::FamousDefs;
23
use syntax::ast::{self, AstNode, NameOwner};
34
use test_utils::mark;
45

5-
use crate::{utils::FamousDefs, AssistContext, AssistId, AssistKind, Assists};
6+
use crate::{AssistContext, AssistId, AssistKind, Assists};
67

78
// Assist: generate_from_impl_for_enum
89
//

crates/assists/src/handlers/merge_imports.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
use ide_helpers::insert_use::{try_merge_imports, try_merge_trees, MergeBehaviour};
12
use syntax::{
23
algo::{neighbor, SyntaxRewriter},
34
ast, AstNode,
45
};
56

67
use crate::{
78
assist_context::{AssistContext, Assists},
8-
utils::{
9-
insert_use::{try_merge_imports, try_merge_trees},
10-
next_prev, MergeBehaviour,
11-
},
9+
utils::next_prev,
1210
AssistId, AssistKind,
1311
};
1412

crates/assists/src/handlers/qualify_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::iter;
22

33
use hir::AsName;
44
use ide_db::RootDatabase;
5+
use ide_helpers::mod_path_to_ast;
56
use syntax::{
67
ast,
78
ast::{make, ArgListOwner},
@@ -12,7 +13,6 @@ use test_utils::mark;
1213
use crate::{
1314
assist_context::{AssistContext, Assists},
1415
utils::import_assets::{ImportAssets, ImportCandidate},
15-
utils::mod_path_to_ast,
1616
AssistId, AssistKind, GroupLabel,
1717
};
1818

0 commit comments

Comments
 (0)