Remove AsName import

This commit is contained in:
Mikhail Rakhmanov 2020-06-04 10:03:44 +02:00
parent a6d3c77bdd
commit b0c8a2be7b
3 changed files with 21 additions and 8 deletions

View File

@ -9,11 +9,11 @@ use ra_syntax::{
use crate::{
assist_context::{AssistBuilder, AssistDirector},
utils::insert_use_statement,
utils::insert_use::insert_use_statement_with_string_path,
AssistContext, AssistId, Assists,
};
use ast::{ArgListOwner, VisibilityOwner};
use hir::{AsName, EnumVariant, Module, ModuleDef};
use hir::{EnumVariant, Module, ModuleDef};
use ra_db::FileId;
use ra_fmt::leading_indent;
use rustc_hash::FxHashSet;
@ -109,8 +109,13 @@ fn insert_import(
let mod_path = module.find_use_path(db, module_def.clone());
if let Some(mut mod_path) = mod_path {
mod_path.segments.pop();
mod_path.segments.push(path_segment.as_name());
insert_use_statement(path.syntax(), &mod_path, ctx, builder.text_edit_builder());
let use_path = format!("{}::{}", mod_path.to_string(), path_segment.to_string());
insert_use_statement_with_string_path(
path.syntax(),
&use_path,
ctx,
builder.text_edit_builder(),
);
}
Some(())
}

View File

@ -23,7 +23,16 @@ pub(crate) fn insert_use_statement(
ctx: &AssistContext,
builder: &mut TextEditBuilder,
) {
let target = path_to_import.to_string().split("::").map(SmolStr::new).collect::<Vec<_>>();
insert_use_statement_with_string_path(position, &path_to_import.to_string(), ctx, builder);
}
pub(crate) fn insert_use_statement_with_string_path(
position: &SyntaxNode,
path_to_import: &str,
ctx: &AssistContext,
builder: &mut TextEditBuilder,
) {
let target = path_to_import.split("::").map(SmolStr::new).collect::<Vec<_>>();
let container = ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| {
if let Some(module) = ast::Module::cast(n.clone()) {
return module.item_list().map(|it| it.syntax().clone());

View File

@ -71,8 +71,7 @@ pub use hir_def::{
type_ref::Mutability,
};
pub use hir_expand::{
hygiene::Hygiene,
name::{AsName, Name},
HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId,
MacroFile, Origin,
};
pub use hir_ty::{display::HirDisplay, CallableDef};