Move the helpers into ide_db

This commit is contained in:
Kirill Bulatov 2020-11-28 16:30:39 +02:00
parent 7b145bd99c
commit 3f612d37c6
27 changed files with 29 additions and 70 deletions

18
Cargo.lock generated
View file

@ -53,7 +53,6 @@ dependencies = [
"either", "either",
"hir", "hir",
"ide_db", "ide_db",
"ide_helpers",
"itertools", "itertools",
"profile", "profile",
"rustc-hash", "rustc-hash",
@ -259,7 +258,6 @@ dependencies = [
"expect-test", "expect-test",
"hir", "hir",
"ide_db", "ide_db",
"ide_helpers",
"itertools", "itertools",
"log", "log",
"profile", "profile",
@ -658,7 +656,6 @@ dependencies = [
"expect-test", "expect-test",
"hir", "hir",
"ide_db", "ide_db",
"ide_helpers",
"indexmap", "indexmap",
"itertools", "itertools",
"log", "log",
@ -684,6 +681,7 @@ dependencies = [
"expect-test", "expect-test",
"fst", "fst",
"hir", "hir",
"itertools",
"log", "log",
"once_cell", "once_cell",
"profile", "profile",
@ -695,19 +693,6 @@ dependencies = [
"text_edit", "text_edit",
] ]
[[package]]
name = "ide_helpers"
version = "0.0.0"
dependencies = [
"either",
"hir",
"ide_db",
"itertools",
"profile",
"syntax",
"test_utils",
]
[[package]] [[package]]
name = "idna" name = "idna"
version = "0.2.0" version = "0.2.0"
@ -1376,7 +1361,6 @@ dependencies = [
"hir_ty", "hir_ty",
"ide", "ide",
"ide_db", "ide_db",
"ide_helpers",
"itertools", "itertools",
"jod-thread", "jod-thread",
"log", "log",

View file

@ -21,4 +21,3 @@ profile = { path = "../profile", version = "0.0.0" }
ide_db = { path = "../ide_db", version = "0.0.0" } ide_db = { path = "../ide_db", version = "0.0.0" }
hir = { path = "../hir", version = "0.0.0" } hir = { path = "../hir", version = "0.0.0" }
test_utils = { path = "../test_utils", version = "0.0.0" } test_utils = { path = "../test_utils", version = "0.0.0" }
ide_helpers = { path = "../ide_helpers", version = "0.0.0" }

View file

@ -5,7 +5,7 @@
//! assists if we are allowed to. //! assists if we are allowed to.
use hir::PrefixKind; use hir::PrefixKind;
use ide_helpers::insert_use::MergeBehaviour; use ide_db::helpers::insert_use::MergeBehaviour;
use crate::AssistKind; use crate::AssistKind;

View file

@ -1,6 +1,6 @@
//! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined. //! `AstTransformer`s are functions that replace nodes in an AST and can be easily combined.
use hir::{HirDisplay, PathResolution, SemanticsScope}; 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 rustc_hash::FxHashMap;
use syntax::{ use syntax::{
algo::SyntaxRewriter, algo::SyntaxRewriter,

View file

@ -1,4 +1,4 @@
use ide_helpers::{ use ide_db::helpers::{
insert_use::{insert_use, ImportScope}, insert_use::{insert_use, ImportScope},
mod_path_to_ast, mod_path_to_ast,
}; };

View file

@ -2,11 +2,11 @@ use std::iter;
use either::Either; use either::Either;
use hir::{AsName, EnumVariant, Module, ModuleDef, Name}; use hir::{AsName, EnumVariant, Module, ModuleDef, Name};
use ide_db::{defs::Definition, search::Reference, RootDatabase}; use ide_db::helpers::{
use ide_helpers::{
insert_use::{insert_use, ImportScope}, insert_use::{insert_use, ImportScope},
mod_path_to_ast, mod_path_to_ast,
}; };
use ide_db::{defs::Definition, search::Reference, RootDatabase};
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use syntax::{ use syntax::{
algo::{find_node_at_offset, SyntaxRewriter}, algo::{find_node_at_offset, SyntaxRewriter},
@ -237,7 +237,7 @@ fn update_reference(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ide_helpers::FamousDefs; use ide_db::helpers::FamousDefs;
use crate::tests::{check_assist, check_assist_not_applicable}; use crate::tests::{check_assist, check_assist_not_applicable};

View file

@ -1,8 +1,8 @@
use std::iter; use std::iter;
use hir::{Adt, HasSource, ModuleDef, Semantics}; use hir::{Adt, HasSource, ModuleDef, Semantics};
use ide_db::helpers::{mod_path_to_ast, FamousDefs};
use ide_db::RootDatabase; use ide_db::RootDatabase;
use ide_helpers::{mod_path_to_ast, FamousDefs};
use itertools::Itertools; use itertools::Itertools;
use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; use syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
use test_utils::mark; use test_utils::mark;
@ -213,7 +213,7 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use ide_helpers::FamousDefs; use ide_db::helpers::FamousDefs;
use test_utils::mark; use test_utils::mark;
use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target}; use crate::tests::{check_assist, check_assist_not_applicable, check_assist_target};

View file

@ -1,5 +1,5 @@
use ide_db::helpers::FamousDefs;
use ide_db::RootDatabase; use ide_db::RootDatabase;
use ide_helpers::FamousDefs;
use syntax::ast::{self, AstNode, NameOwner}; use syntax::ast::{self, AstNode, NameOwner};
use test_utils::mark; use test_utils::mark;

View file

@ -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::{ use syntax::{
algo::{neighbor, SyntaxRewriter}, algo::{neighbor, SyntaxRewriter},
ast, AstNode, ast, AstNode,

View file

@ -1,8 +1,8 @@
use std::iter; use std::iter;
use hir::AsName; use hir::AsName;
use ide_db::helpers::mod_path_to_ast;
use ide_db::RootDatabase; use ide_db::RootDatabase;
use ide_helpers::mod_path_to_ast;
use syntax::{ use syntax::{
ast, ast,
ast::{make, ArgListOwner}, ast::{make, ArgListOwner},

View file

@ -1,5 +1,5 @@
use ide_db::helpers::mod_path_to_ast;
use ide_db::imports_locator; use ide_db::imports_locator;
use ide_helpers::mod_path_to_ast;
use itertools::Itertools; use itertools::Itertools;
use syntax::{ use syntax::{
ast::{self, make, AstNode}, ast::{self, make, AstNode},

View file

@ -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 syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SyntaxNode};
use test_utils::mark; use test_utils::mark;

View file

@ -22,7 +22,6 @@ base_db = { path = "../base_db", version = "0.0.0" }
ide_db = { path = "../ide_db", version = "0.0.0" } ide_db = { path = "../ide_db", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" } profile = { path = "../profile", version = "0.0.0" }
test_utils = { path = "../test_utils", 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 # 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`. # something from some `hir_xxx` subpackage, reexport the API via `hir`.

View file

@ -1,5 +1,5 @@
//! Complete fields in record literals and patterns. //! Complete fields in record literals and patterns.
use ide_helpers::FamousDefs; use ide_db::helpers::FamousDefs;
use syntax::ast::Expr; use syntax::ast::Expr;
use crate::{ use crate::{
@ -46,7 +46,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use ide_helpers::FamousDefs; use ide_db::helpers::FamousDefs;
use crate::{test_utils::completion_list, CompletionKind}; use crate::{test_utils::completion_list, CompletionKind};

View file

@ -2,8 +2,8 @@
use either::Either; use either::Either;
use hir::{Adt, ModuleDef, ScopeDef, Type}; use hir::{Adt, ModuleDef, ScopeDef, Type};
use ide_db::helpers::insert_use::ImportScope;
use ide_db::imports_locator; use ide_db::imports_locator;
use ide_helpers::insert_use::ImportScope;
use syntax::AstNode; use syntax::AstNode;
use test_utils::mark; use test_utils::mark;

View file

@ -4,7 +4,7 @@
//! module, and we use to statically check that we only produce snippet //! module, and we use to statically check that we only produce snippet
//! completions if we are allowed to. //! completions if we are allowed to.
use ide_helpers::insert_use::MergeBehaviour; use ide_db::helpers::insert_use::MergeBehaviour;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct CompletionConfig { pub struct CompletionConfig {

View file

@ -3,7 +3,7 @@
use std::fmt; use std::fmt;
use hir::{Documentation, ModPath, Mutability}; use hir::{Documentation, ModPath, Mutability};
use ide_helpers::{ use ide_db::helpers::{
insert_use::{self, ImportScope, MergeBehaviour}, insert_use::{self, ImportScope, MergeBehaviour},
mod_path_to_ast, mod_path_to_ast,
}; };

View file

@ -10,8 +10,8 @@ pub(crate) mod type_alias;
mod builder_ext; mod builder_ext;
use hir::{Documentation, HasAttrs, HirDisplay, ModPath, Mutability, ScopeDef, Type}; use hir::{Documentation, HasAttrs, HirDisplay, ModPath, Mutability, ScopeDef, Type};
use ide_db::helpers::insert_use::{ImportScope, MergeBehaviour};
use ide_db::RootDatabase; use ide_db::RootDatabase;
use ide_helpers::insert_use::{ImportScope, MergeBehaviour};
use syntax::TextRange; use syntax::TextRange;
use test_utils::mark; use test_utils::mark;

View file

@ -24,7 +24,6 @@ stdx = { path = "../stdx", version = "0.0.0" }
syntax = { path = "../syntax", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" }
text_edit = { path = "../text_edit", version = "0.0.0" } text_edit = { path = "../text_edit", version = "0.0.0" }
ide_db = { path = "../ide_db", 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" } cfg = { path = "../cfg", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" } profile = { path = "../profile", version = "0.0.0" }
test_utils = { path = "../test_utils", version = "0.0.0" } test_utils = { path = "../test_utils", version = "0.0.0" }

View file

@ -1,7 +1,7 @@
use either::Either; use either::Either;
use hir::{known, Callable, HirDisplay, Semantics}; use hir::{known, Callable, HirDisplay, Semantics};
use ide_db::helpers::FamousDefs;
use ide_db::RootDatabase; use ide_db::RootDatabase;
use ide_helpers::FamousDefs;
use stdx::to_lower_snake_case; use stdx::to_lower_snake_case;
use syntax::{ use syntax::{
ast::{self, ArgListOwner, AstNode, NameOwner}, ast::{self, ArgListOwner, AstNode, NameOwner},
@ -428,7 +428,7 @@ fn get_callable(sema: &Semantics<RootDatabase>, expr: &ast::Expr) -> Option<hir:
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use expect_test::{expect, Expect}; use expect_test::{expect, Expect};
use ide_helpers::FamousDefs; use ide_db::helpers::FamousDefs;
use test_utils::extract_annotations; use test_utils::extract_annotations;
use crate::{fixture, inlay_hints::InlayHintsConfig}; use crate::{fixture, inlay_hints::InlayHintsConfig};

View file

@ -18,7 +18,8 @@ rayon = "1.5.0"
fst = { version = "0.4", default-features = false } fst = { version = "0.4", default-features = false }
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
once_cell = "1.3.1" once_cell = "1.3.1"
either = "1.5.3" either = "1.6.1"
itertools = "0.9.0"
stdx = { path = "../stdx", version = "0.0.0" } stdx = { path = "../stdx", version = "0.0.0" }
syntax = { path = "../syntax", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" }

View file

@ -1,6 +1,6 @@
//! A module with ide helpers for high-level ide features. //! A module with ide helpers for high-level ide features.
use crate::RootDatabase;
use hir::{Crate, Enum, Module, ScopeDef, Semantics, Trait}; use hir::{Crate, Enum, Module, ScopeDef, Semantics, Trait};
use ide_db::RootDatabase;
use syntax::ast::{self, make}; use syntax::ast::{self, make};
pub mod insert_use; pub mod insert_use;

View file

@ -1,8 +1,8 @@
//! Handle syntactic aspects of inserting a new `use`. //! Handle syntactic aspects of inserting a new `use`.
use std::{cmp::Ordering, iter::successors}; use std::{cmp::Ordering, iter::successors};
use crate::RootDatabase;
use hir::Semantics; use hir::Semantics;
use ide_db::RootDatabase;
use itertools::{EitherOrBoth, Itertools}; use itertools::{EitherOrBoth, Itertools};
use syntax::{ use syntax::{
algo::SyntaxRewriter, algo::SyntaxRewriter,

View file

@ -13,6 +13,7 @@ pub mod source_change;
pub mod ty_filter; pub mod ty_filter;
pub mod traits; pub mod traits;
pub mod call_info; pub mod call_info;
pub mod helpers;
use std::{fmt, sync::Arc}; use std::{fmt, sync::Arc};

View file

@ -1,23 +0,0 @@
[package]
name = "ide_helpers"
version = "0.0.0"
description = "A set of helper methods shared between various ide-level modules"
license = "MIT OR Apache-2.0"
authors = ["rust-analyzer developers"]
edition = "2018"
[lib]
doctest = false
[features]
wasm = []
[dependencies]
either = "1.6.1"
itertools = "0.9.0"
syntax = { path = "../syntax", version = "0.0.0" }
ide_db = { path = "../ide_db", version = "0.0.0" }
hir = { path = "../hir", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" }
test_utils = { path = "../test_utils", version = "0.0.0" }

View file

@ -39,7 +39,7 @@ tracing-tree = { version = "0.1.4" }
stdx = { path = "../stdx", version = "0.0.0" } stdx = { path = "../stdx", version = "0.0.0" }
flycheck = { path = "../flycheck", version = "0.0.0" } flycheck = { path = "../flycheck", version = "0.0.0" }
ide = { path = "../ide", version = "0.0.0" } ide = { path = "../ide", version = "0.0.0" }
ide_helpers = { path = "../ide_helpers", version = "0.0.0" } ide_db = { path = "../ide_db", version = "0.0.0" }
profile = { path = "../profile", version = "0.0.0" } profile = { path = "../profile", version = "0.0.0" }
project_model = { path = "../project_model", version = "0.0.0" } project_model = { path = "../project_model", version = "0.0.0" }
syntax = { path = "../syntax", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" }
@ -50,7 +50,6 @@ cfg = { path = "../cfg", version = "0.0.0" }
toolchain = { path = "../toolchain", version = "0.0.0" } toolchain = { path = "../toolchain", version = "0.0.0" }
# This should only be used in CLI # This should only be used in CLI
ide_db = { path = "../ide_db", version = "0.0.0" }
ssr = { path = "../ssr", version = "0.0.0" } ssr = { path = "../ssr", version = "0.0.0" }
hir = { path = "../hir", version = "0.0.0" } hir = { path = "../hir", version = "0.0.0" }
hir_def = { path = "../hir_def", version = "0.0.0" } hir_def = { path = "../hir_def", version = "0.0.0" }

View file

@ -12,7 +12,7 @@ use std::{convert::TryFrom, ffi::OsString, path::PathBuf};
use flycheck::FlycheckConfig; use flycheck::FlycheckConfig;
use hir::PrefixKind; use hir::PrefixKind;
use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig}; use ide::{AssistConfig, CompletionConfig, DiagnosticsConfig, HoverConfig, InlayHintsConfig};
use ide_helpers::insert_use::MergeBehaviour; use ide_db::helpers::insert_use::MergeBehaviour;
use lsp_types::{ClientCapabilities, MarkupKind}; use lsp_types::{ClientCapabilities, MarkupKind};
use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest};
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;