From 3f612d37c68a6e4c09e407b7cd2ad8a1d17ab4e6 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 28 Nov 2020 16:30:39 +0200 Subject: [PATCH] Move the helpers into ide_db --- Cargo.lock | 18 +-------------- crates/assists/Cargo.toml | 1 - crates/assists/src/assist_config.rs | 2 +- crates/assists/src/ast_transform.rs | 2 +- crates/assists/src/handlers/auto_import.rs | 2 +- .../extract_struct_from_enum_variant.rs | 6 ++--- .../assists/src/handlers/fill_match_arms.rs | 4 ++-- .../handlers/generate_from_impl_for_enum.rs | 2 +- crates/assists/src/handlers/merge_imports.rs | 2 +- crates/assists/src/handlers/qualify_path.rs | 2 +- .../replace_derive_with_manual_impl.rs | 2 +- .../replace_qualified_name_with_use.rs | 2 +- crates/completion/Cargo.toml | 1 - crates/completion/src/completions/record.rs | 4 ++-- .../src/completions/unqualified_path.rs | 2 +- crates/completion/src/config.rs | 2 +- crates/completion/src/item.rs | 2 +- crates/completion/src/render.rs | 2 +- crates/ide/Cargo.toml | 1 - crates/ide/src/inlay_hints.rs | 4 ++-- crates/ide_db/Cargo.toml | 3 ++- .../src/lib.rs => ide_db/src/helpers.rs} | 2 +- .../src => ide_db/src/helpers}/insert_use.rs | 2 +- crates/ide_db/src/lib.rs | 1 + crates/ide_helpers/Cargo.toml | 23 ------------------- crates/rust-analyzer/Cargo.toml | 3 +-- crates/rust-analyzer/src/config.rs | 2 +- 27 files changed, 29 insertions(+), 70 deletions(-) rename crates/{ide_helpers/src/lib.rs => ide_db/src/helpers.rs} (99%) rename crates/{ide_helpers/src => ide_db/src/helpers}/insert_use.rs (99%) delete mode 100644 crates/ide_helpers/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index e7d1782cccf..f50e9edd66a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,7 +53,6 @@ dependencies = [ "either", "hir", "ide_db", - "ide_helpers", "itertools", "profile", "rustc-hash", @@ -259,7 +258,6 @@ dependencies = [ "expect-test", "hir", "ide_db", - "ide_helpers", "itertools", "log", "profile", @@ -658,7 +656,6 @@ dependencies = [ "expect-test", "hir", "ide_db", - "ide_helpers", "indexmap", "itertools", "log", @@ -684,6 +681,7 @@ dependencies = [ "expect-test", "fst", "hir", + "itertools", "log", "once_cell", "profile", @@ -695,19 +693,6 @@ dependencies = [ "text_edit", ] -[[package]] -name = "ide_helpers" -version = "0.0.0" -dependencies = [ - "either", - "hir", - "ide_db", - "itertools", - "profile", - "syntax", - "test_utils", -] - [[package]] name = "idna" version = "0.2.0" @@ -1376,7 +1361,6 @@ dependencies = [ "hir_ty", "ide", "ide_db", - "ide_helpers", "itertools", "jod-thread", "log", diff --git a/crates/assists/Cargo.toml b/crates/assists/Cargo.toml index 91d9b6e3f71..3fd8327d6a3 100644 --- a/crates/assists/Cargo.toml +++ b/crates/assists/Cargo.toml @@ -21,4 +21,3 @@ profile = { path = "../profile", version = "0.0.0" } ide_db = { path = "../ide_db", version = "0.0.0" } hir = { path = "../hir", version = "0.0.0" } test_utils = { path = "../test_utils", version = "0.0.0" } -ide_helpers = { path = "../ide_helpers", version = "0.0.0" } diff --git a/crates/assists/src/assist_config.rs b/crates/assists/src/assist_config.rs index 6d9934e931c..786224cfa1c 100644 --- a/crates/assists/src/assist_config.rs +++ b/crates/assists/src/assist_config.rs @@ -5,7 +5,7 @@ //! assists if we are allowed to. use hir::PrefixKind; -use ide_helpers::insert_use::MergeBehaviour; +use ide_db::helpers::insert_use::MergeBehaviour; use crate::AssistKind; diff --git a/crates/assists/src/ast_transform.rs b/crates/assists/src/ast_transform.rs index 95b0605993b..66e4634b1d3 100644 --- a/crates/assists/src/ast_transform.rs +++ b/crates/assists/src/ast_transform.rs @@ -1,6 +1,6 @@ //! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined. use hir::{HirDisplay, PathResolution, SemanticsScope}; -use ide_helpers::mod_path_to_ast; +use ide_db::helpers::mod_path_to_ast; use rustc_hash::FxHashMap; use syntax::{ algo::SyntaxRewriter, diff --git a/crates/assists/src/handlers/auto_import.rs b/crates/assists/src/handlers/auto_import.rs index 0b2d508d594..bd5bba64601 100644 --- a/crates/assists/src/handlers/auto_import.rs +++ b/crates/assists/src/handlers/auto_import.rs @@ -1,4 +1,4 @@ -use ide_helpers::{ +use ide_db::helpers::{ insert_use::{insert_use, ImportScope}, mod_path_to_ast, }; diff --git a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs index fddd5354aa0..d85767b4ecd 100644 --- a/crates/assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/assists/src/handlers/extract_struct_from_enum_variant.rs @@ -2,11 +2,11 @@ use either::Either; use hir::{AsName, EnumVariant, Module, ModuleDef, Name}; -use ide_db::{defs::Definition, search::Reference, RootDatabase}; -use ide_helpers::{ +use ide_db::helpers::{ insert_use::{insert_use, ImportScope}, mod_path_to_ast, }; +use ide_db::{defs::Definition, search::Reference, RootDatabase}; use rustc_hash::{FxHashMap, FxHashSet}; use syntax::{ algo::{find_node_at_offset, SyntaxRewriter}, @@ -237,7 +237,7 @@ fn update_reference( #[cfg(test)] mod tests { - use ide_helpers::FamousDefs; + use ide_db::helpers::FamousDefs; use crate::tests::{check_assist, check_assist_not_applicable}; diff --git a/crates/assists/src/handlers/fill_match_arms.rs b/crates/assists/src/handlers/fill_match_arms.rs index bd42e0f1662..ef12ef0cf1a 100644 --- a/crates/assists/src/handlers/fill_match_arms.rs +++ b/crates/assists/src/handlers/fill_match_arms.rs @@ -1,8 +1,8 @@ use std::iter; use hir::{Adt, HasSource, ModuleDef, Semantics}; +use ide_db::helpers::{mod_path_to_ast, FamousDefs}; use ide_db::RootDatabase; -use ide_helpers::{mod_path_to_ast, FamousDefs}; use itertools::Itertools; use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; use test_utils::mark; @@ -213,7 +213,7 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O #[cfg(test)] mod tests { - use ide_helpers::FamousDefs; + use ide_db::helpers::FamousDefs; use test_utils::mark; use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; diff --git a/crates/assists/src/handlers/generate_from_impl_for_enum.rs b/crates/assists/src/handlers/generate_from_impl_for_enum.rs index 01b14d94d5f..3c374e5d95b 100644 --- a/crates/assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/assists/src/handlers/generate_from_impl_for_enum.rs @@ -1,5 +1,5 @@ +use ide_db::helpers::FamousDefs; use ide_db::RootDatabase; -use ide_helpers::FamousDefs; use syntax::ast::{self, AstNode, NameOwner}; use test_utils::mark; diff --git a/crates/assists/src/handlers/merge_imports.rs b/crates/assists/src/handlers/merge_imports.rs index 8207f0e6eba..b7e853994b3 100644 --- a/crates/assists/src/handlers/merge_imports.rs +++ b/crates/assists/src/handlers/merge_imports.rs @@ -1,4 +1,4 @@ -use ide_helpers::insert_use::{try_merge_imports, try_merge_trees, MergeBehaviour}; +use ide_db::helpers::insert_use::{try_merge_imports, try_merge_trees, MergeBehaviour}; use syntax::{ algo::{neighbor, SyntaxRewriter}, ast, AstNode, diff --git a/crates/assists/src/handlers/qualify_path.rs b/crates/assists/src/handlers/qualify_path.rs index c0ee7ea0b8d..6f9810fe88d 100644 --- a/crates/assists/src/handlers/qualify_path.rs +++ b/crates/assists/src/handlers/qualify_path.rs @@ -1,8 +1,8 @@ use std::iter; use hir::AsName; +use ide_db::helpers::mod_path_to_ast; use ide_db::RootDatabase; -use ide_helpers::mod_path_to_ast; use syntax::{ ast, ast::{make, ArgListOwner}, diff --git a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs index fe262377c92..4d6a1956bb1 100644 --- a/crates/assists/src/handlers/replace_derive_with_manual_impl.rs +++ b/crates/assists/src/handlers/replace_derive_with_manual_impl.rs @@ -1,5 +1,5 @@ +use ide_db::helpers::mod_path_to_ast; use ide_db::imports_locator; -use ide_helpers::mod_path_to_ast; use itertools::Itertools; use syntax::{ ast::{self, make, AstNode}, diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs index 5e5c41a6fe3..8bdf9eea5e4 100644 --- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs @@ -1,4 +1,4 @@ -use ide_helpers::insert_use::{insert_use, ImportScope}; +use ide_db::helpers::insert_use::{insert_use, ImportScope}; use syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SyntaxNode}; use test_utils::mark; diff --git a/crates/completion/Cargo.toml b/crates/completion/Cargo.toml index 102de33f8fc..35e169a28c1 100644 --- a/crates/completion/Cargo.toml +++ b/crates/completion/Cargo.toml @@ -22,7 +22,6 @@ base_db = { path = "../base_db", version = "0.0.0" } ide_db = { path = "../ide_db", version = "0.0.0" } profile = { path = "../profile", version = "0.0.0" } test_utils = { path = "../test_utils", version = "0.0.0" } -ide_helpers = { path = "../ide_helpers", version = "0.0.0" } # completions crate should depend only on the top-level `hir` package. if you need # something from some `hir_xxx` subpackage, reexport the API via `hir`. diff --git a/crates/completion/src/completions/record.rs b/crates/completion/src/completions/record.rs index 218a1923c5f..eaa44c97d1f 100644 --- a/crates/completion/src/completions/record.rs +++ b/crates/completion/src/completions/record.rs @@ -1,5 +1,5 @@ //! Complete fields in record literals and patterns. -use ide_helpers::FamousDefs; +use ide_db::helpers::FamousDefs; use syntax::ast::Expr; use crate::{ @@ -46,7 +46,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> #[cfg(test)] mod tests { use expect_test::{expect, Expect}; - use ide_helpers::FamousDefs; + use ide_db::helpers::FamousDefs; use crate::{test_utils::completion_list, CompletionKind}; diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index db5dbb7ddbc..81691cd7f23 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -2,8 +2,8 @@ use either::Either; use hir::{Adt, ModuleDef, ScopeDef, Type}; +use ide_db::helpers::insert_use::ImportScope; use ide_db::imports_locator; -use ide_helpers::insert_use::ImportScope; use syntax::AstNode; use test_utils::mark; diff --git a/crates/completion/src/config.rs b/crates/completion/src/config.rs index 1995b075482..654a76f7b33 100644 --- a/crates/completion/src/config.rs +++ b/crates/completion/src/config.rs @@ -4,7 +4,7 @@ //! module, and we use to statically check that we only produce snippet //! completions if we are allowed to. -use ide_helpers::insert_use::MergeBehaviour; +use ide_db::helpers::insert_use::MergeBehaviour; #[derive(Clone, Debug, PartialEq, Eq)] pub struct CompletionConfig { diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index 3bfee1b3f96..e85549fef4d 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs @@ -3,7 +3,7 @@ use std::fmt; use hir::{Documentation, ModPath, Mutability}; -use ide_helpers::{ +use ide_db::helpers::{ insert_use::{self, ImportScope, MergeBehaviour}, mod_path_to_ast, }; diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index e84aef0e4a9..504757a6ae2 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -10,8 +10,8 @@ mod builder_ext; use hir::{Documentation, HasAttrs, HirDisplay, ModPath, Mutability, ScopeDef, Type}; +use ide_db::helpers::insert_use::{ImportScope, MergeBehaviour}; use ide_db::RootDatabase; -use ide_helpers::insert_use::{ImportScope, MergeBehaviour}; use syntax::TextRange; use test_utils::mark; diff --git a/crates/ide/Cargo.toml b/crates/ide/Cargo.toml index 92d4e5e9fa0..4d483580df3 100644 --- a/crates/ide/Cargo.toml +++ b/crates/ide/Cargo.toml @@ -24,7 +24,6 @@ stdx = { path = "../stdx", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" } text_edit = { path = "../text_edit", version = "0.0.0" } ide_db = { path = "../ide_db", version = "0.0.0" } -ide_helpers = { path = "../ide_helpers", version = "0.0.0" } cfg = { path = "../cfg", version = "0.0.0" } profile = { path = "../profile", version = "0.0.0" } test_utils = { path = "../test_utils", version = "0.0.0" } diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 9c8bb7c45cf..65df7979cfa 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -1,7 +1,7 @@ use either::Either; use hir::{known, Callable, HirDisplay, Semantics}; +use ide_db::helpers::FamousDefs; use ide_db::RootDatabase; -use ide_helpers::FamousDefs; use stdx::to_lower_snake_case; use syntax::{ ast::{self, ArgListOwner, AstNode, NameOwner}, @@ -428,7 +428,7 @@ fn get_callable(sema: &Semantics, expr: &ast::Expr) -> Option