From f4ae3650d855554575f866264a3c8197dfd12835 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 24 Nov 2020 23:25:13 +0200 Subject: Extract the import code into the shared module --- crates/completion/Cargo.toml | 2 +- crates/completion/src/completions/record.rs | 4 ++-- crates/completion/src/completions/unqualified_path.rs | 2 +- crates/completion/src/config.rs | 2 +- crates/completion/src/item.rs | 7 +++++-- crates/completion/src/render.rs | 2 +- crates/completion/src/render/enum_variant.rs | 2 +- crates/completion/src/render/function.rs | 2 +- crates/completion/src/render/macro_.rs | 3 ++- 9 files changed, 15 insertions(+), 11 deletions(-) (limited to 'crates/completion') diff --git a/crates/completion/Cargo.toml b/crates/completion/Cargo.toml index e7df9d955..102de33f8 100644 --- a/crates/completion/Cargo.toml +++ b/crates/completion/Cargo.toml @@ -15,7 +15,6 @@ log = "0.4.8" rustc-hash = "1.1.0" either = "1.6.1" -assists = { path = "../assists", version = "0.0.0" } stdx = { path = "../stdx", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" } text_edit = { path = "../text_edit", version = "0.0.0" } @@ -23,6 +22,7 @@ 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 2049b9d09..218a1923c 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 assists::utils::FamousDefs; +use ide_helpers::FamousDefs; use syntax::ast::Expr; use crate::{ @@ -45,8 +45,8 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> #[cfg(test)] mod tests { - use assists::utils::FamousDefs; use expect_test::{expect, Expect}; + use ide_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 3bd776905..db5dbb7dd 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -1,9 +1,9 @@ //! Completion of names from the current scope, e.g. locals and imported items. -use assists::utils::ImportScope; use either::Either; use hir::{Adt, ModuleDef, ScopeDef, Type}; 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 f50735372..1995b0754 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 assists::utils::MergeBehaviour; +use ide_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 7b62c2c4e..675cef8c4 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs @@ -2,8 +2,11 @@ use std::fmt; -use assists::utils::{insert_use, mod_path_to_ast, ImportScope, MergeBehaviour}; use hir::{Documentation, ModPath, Mutability}; +use ide_helpers::{ + insert_use::{self, ImportScope, MergeBehaviour}, + mod_path_to_ast, +}; use syntax::{algo, TextRange}; use text_edit::TextEdit; @@ -300,7 +303,7 @@ impl Builder { label = format!("{}::{}", import_path_without_last_segment, label); } - let rewriter = insert_use(&import_scope, import, merge_behaviour); + let rewriter = insert_use::insert_use(&import_scope, import, merge_behaviour); if let Some(old_ast) = rewriter.rewrite_root() { algo::diff(&old_ast, &rewriter.rewrite(&old_ast)).into_text_edit(&mut text_edits); } diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index bce02f577..e9704c27c 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -9,9 +9,9 @@ pub(crate) mod type_alias; mod builder_ext; -use assists::utils::{ImportScope, MergeBehaviour}; use hir::{Documentation, HasAttrs, HirDisplay, ModPath, Mutability, ScopeDef, Type}; use ide_db::RootDatabase; +use ide_helpers::insert_use::{ImportScope, MergeBehaviour}; use syntax::TextRange; use test_utils::mark; diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs index 64e742b77..5d4fbb641 100644 --- a/crates/completion/src/render/enum_variant.rs +++ b/crates/completion/src/render/enum_variant.rs @@ -1,7 +1,7 @@ //! Renderer for `enum` variants. -use assists::utils::{ImportScope, MergeBehaviour}; use hir::{HasAttrs, HirDisplay, ModPath, StructKind}; +use ide_helpers::insert_use::{ImportScope, MergeBehaviour}; use itertools::Itertools; use test_utils::mark; diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index e8b726ad6..07e99058a 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs @@ -1,7 +1,7 @@ //! Renderer for function calls. -use assists::utils::{ImportScope, MergeBehaviour}; use hir::{HasSource, ModPath, Type}; +use ide_helpers::insert_use::{ImportScope, MergeBehaviour}; use syntax::{ast::Fn, display::function_declaration}; use crate::{ diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 91055a296..b1284f201 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs @@ -1,7 +1,7 @@ //! Renderer for macro invocations. -use assists::utils::{ImportScope, MergeBehaviour}; use hir::{Documentation, HasSource, ModPath}; +use ide_helpers::insert_use::{ImportScope, MergeBehaviour}; use syntax::display::macro_label; use test_utils::mark; @@ -12,6 +12,7 @@ use crate::{ pub(crate) fn render_macro<'a>( ctx: RenderContext<'a>, + // TODO kb add some object instead of a tuple? import_data: Option<(ModPath, ImportScope, Option)>, name: String, macro_: hir::MacroDef, -- cgit v1.2.3