mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Remove AsName import
This commit is contained in:
parent
a6d3c77bdd
commit
b0c8a2be7b
3 changed files with 21 additions and 8 deletions
|
@ -9,11 +9,11 @@ use ra_syntax::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_context::{AssistBuilder, AssistDirector},
|
assist_context::{AssistBuilder, AssistDirector},
|
||||||
utils::insert_use_statement,
|
utils::insert_use::insert_use_statement_with_string_path,
|
||||||
AssistContext, AssistId, Assists,
|
AssistContext, AssistId, Assists,
|
||||||
};
|
};
|
||||||
use ast::{ArgListOwner, VisibilityOwner};
|
use ast::{ArgListOwner, VisibilityOwner};
|
||||||
use hir::{AsName, EnumVariant, Module, ModuleDef};
|
use hir::{EnumVariant, Module, ModuleDef};
|
||||||
use ra_db::FileId;
|
use ra_db::FileId;
|
||||||
use ra_fmt::leading_indent;
|
use ra_fmt::leading_indent;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
@ -109,8 +109,13 @@ fn insert_import(
|
||||||
let mod_path = module.find_use_path(db, module_def.clone());
|
let mod_path = module.find_use_path(db, module_def.clone());
|
||||||
if let Some(mut mod_path) = mod_path {
|
if let Some(mut mod_path) = mod_path {
|
||||||
mod_path.segments.pop();
|
mod_path.segments.pop();
|
||||||
mod_path.segments.push(path_segment.as_name());
|
let use_path = format!("{}::{}", mod_path.to_string(), path_segment.to_string());
|
||||||
insert_use_statement(path.syntax(), &mod_path, ctx, builder.text_edit_builder());
|
insert_use_statement_with_string_path(
|
||||||
|
path.syntax(),
|
||||||
|
&use_path,
|
||||||
|
ctx,
|
||||||
|
builder.text_edit_builder(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,16 @@ pub(crate) fn insert_use_statement(
|
||||||
ctx: &AssistContext,
|
ctx: &AssistContext,
|
||||||
builder: &mut TextEditBuilder,
|
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| {
|
let container = ctx.sema.ancestors_with_macros(position.clone()).find_map(|n| {
|
||||||
if let Some(module) = ast::Module::cast(n.clone()) {
|
if let Some(module) = ast::Module::cast(n.clone()) {
|
||||||
return module.item_list().map(|it| it.syntax().clone());
|
return module.item_list().map(|it| it.syntax().clone());
|
||||||
|
|
|
@ -71,8 +71,7 @@ pub use hir_def::{
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
};
|
};
|
||||||
pub use hir_expand::{
|
pub use hir_expand::{
|
||||||
hygiene::Hygiene,
|
hygiene::Hygiene, name::Name, HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId,
|
||||||
name::{AsName, Name},
|
MacroFile, Origin,
|
||||||
HirFileId, InFile, MacroCallId, MacroCallLoc, MacroDefId, MacroFile, Origin,
|
|
||||||
};
|
};
|
||||||
pub use hir_ty::{display::HirDisplay, CallableDef};
|
pub use hir_ty::{display::HirDisplay, CallableDef};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue