Skip to content

Commit b7ece77

Browse files
Merge #6650
6650: Make completion and assists module independent r=matklad a=SomeoneToIgnore A follow-up of #6553 (comment) Move the common code for both assists and completion modules into a separate crate. Co-authored-by: Kirill Bulatov <[email protected]>
2 parents fe2ac44 + 3f612d3 commit b7ece77

30 files changed

+305
-303
lines changed

Cargo.lock

Lines changed: 1 addition & 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: 1 addition & 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" }

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_db::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_db::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_db::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
@@ -2,6 +2,10 @@ use std::iter;
22

33
use either::Either;
44
use hir::{AsName, EnumVariant, Module, ModuleDef, Name};
5+
use ide_db::helpers::{
6+
insert_use::{insert_use, ImportScope},
7+
mod_path_to_ast,
8+
};
59
use ide_db::{defs::Definition, search::Reference, RootDatabase};
610
use rustc_hash::{FxHashMap, FxHashSet};
711
use syntax::{
@@ -10,10 +14,7 @@ use syntax::{
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_db::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
@@ -1,13 +1,14 @@
11
use std::iter;
22

33
use hir::{Adt, HasSource, ModuleDef, Semantics};
4+
use ide_db::helpers::{mod_path_to_ast, FamousDefs};
45
use ide_db::RootDatabase;
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_db::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 @@
1+
use ide_db::helpers::FamousDefs;
12
use ide_db::RootDatabase;
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_db::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
@@ -1,6 +1,7 @@
11
use std::iter;
22

33
use hir::AsName;
4+
use ide_db::helpers::mod_path_to_ast;
45
use ide_db::RootDatabase;
56
use syntax::{
67
ast,
@@ -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)