fix: remove redundant use node insertion
This commit is contained in:
parent
418056597b
commit
02214a6d12
@ -1,10 +1,12 @@
|
|||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use hir::{HasSource, HirFileIdExt, ModuleSource};
|
use hir::{HirFileIdExt, ModuleSource};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
assists::{AssistId, AssistKind},
|
assists::{AssistId, AssistKind},
|
||||||
base_db::FileId,
|
base_db::FileId,
|
||||||
defs::{Definition, NameClass, NameRefClass},
|
defs::{Definition, NameClass, NameRefClass},
|
||||||
|
helpers::item_name,
|
||||||
|
items_locator::items_with_name,
|
||||||
search::{FileReference, SearchScope},
|
search::{FileReference, SearchScope},
|
||||||
FxHashMap, FxHashSet,
|
FxHashMap, FxHashSet,
|
||||||
};
|
};
|
||||||
@ -433,7 +435,7 @@ impl Module {
|
|||||||
fn process_def_in_sel(
|
fn process_def_in_sel(
|
||||||
&mut self,
|
&mut self,
|
||||||
def: Definition,
|
def: Definition,
|
||||||
node_syntax: &SyntaxNode,
|
use_node: &SyntaxNode,
|
||||||
curr_parent_module: &Option<ast::Module>,
|
curr_parent_module: &Option<ast::Module>,
|
||||||
ctx: &AssistContext<'_>,
|
ctx: &AssistContext<'_>,
|
||||||
) -> Option<TextRange> {
|
) -> Option<TextRange> {
|
||||||
@ -491,7 +493,7 @@ impl Module {
|
|||||||
|
|
||||||
//If use_stmt exists, find the use_tree_str, reconstruct it inside new module
|
//If use_stmt exists, find the use_tree_str, reconstruct it inside new module
|
||||||
//If not, insert a use stmt with super and the given nameref
|
//If not, insert a use stmt with super and the given nameref
|
||||||
match self.process_use_stmt_for_import_resolve(use_stmt, node_syntax) {
|
match self.process_use_stmt_for_import_resolve(use_stmt, use_node) {
|
||||||
Some((use_tree_str, _)) => use_tree_str_opt = Some(use_tree_str),
|
Some((use_tree_str, _)) => use_tree_str_opt = Some(use_tree_str),
|
||||||
None if def_in_mod && def_out_sel => {
|
None if def_in_mod && def_out_sel => {
|
||||||
//Considered only after use_stmt is not present
|
//Considered only after use_stmt is not present
|
||||||
@ -502,7 +504,7 @@ impl Module {
|
|||||||
// mod -> ust_stmt transversal
|
// mod -> ust_stmt transversal
|
||||||
// true | false -> super import insertion
|
// true | false -> super import insertion
|
||||||
// true | true -> super import insertion
|
// true | true -> super import insertion
|
||||||
self.make_use_stmt_of_node_with_super(node_syntax);
|
self.make_use_stmt_of_node_with_super(use_node);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
@ -510,7 +512,7 @@ impl Module {
|
|||||||
//Changes to be made inside new module, and remove import from outside
|
//Changes to be made inside new module, and remove import from outside
|
||||||
|
|
||||||
if let Some((mut use_tree_str, text_range_opt)) =
|
if let Some((mut use_tree_str, text_range_opt)) =
|
||||||
self.process_use_stmt_for_import_resolve(use_stmt, node_syntax)
|
self.process_use_stmt_for_import_resolve(use_stmt, use_node)
|
||||||
{
|
{
|
||||||
if let Some(text_range) = text_range_opt {
|
if let Some(text_range) = text_range_opt {
|
||||||
import_path_to_be_removed = Some(text_range);
|
import_path_to_be_removed = Some(text_range);
|
||||||
@ -530,7 +532,7 @@ impl Module {
|
|||||||
|
|
||||||
use_tree_str_opt = Some(use_tree_str);
|
use_tree_str_opt = Some(use_tree_str);
|
||||||
} else if def_in_mod && def_out_sel {
|
} else if def_in_mod && def_out_sel {
|
||||||
self.make_use_stmt_of_node_with_super(node_syntax);
|
self.make_use_stmt_of_node_with_super(use_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,7 +552,20 @@ impl Module {
|
|||||||
make::use_(None, make::use_tree(make::join_paths(use_tree_str), None, None, false));
|
make::use_(None, make::use_tree(make::join_paths(use_tree_str), None, None, false));
|
||||||
let item = ast::Item::from(use_);
|
let item = ast::Item::from(use_);
|
||||||
|
|
||||||
if def_out_sel {
|
let is_item = match def {
|
||||||
|
Definition::Macro(_) => true,
|
||||||
|
Definition::Module(_) => true,
|
||||||
|
Definition::Function(_) => true,
|
||||||
|
Definition::Adt(_) => true,
|
||||||
|
Definition::Const(_) => true,
|
||||||
|
Definition::Static(_) => true,
|
||||||
|
Definition::Trait(_) => true,
|
||||||
|
Definition::TraitAlias(_) => true,
|
||||||
|
Definition::TypeAlias(_) => true,
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if def_out_sel || !is_item {
|
||||||
self.use_items.insert(0, item.clone());
|
self.use_items.insert(0, item.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user