mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
refactor: search for enum semantically
This commit is contained in:
parent
120526ad68
commit
c4bcec214a
@ -462,12 +462,15 @@ fn add_enum_def(
|
|||||||
target_node: SyntaxNode,
|
target_node: SyntaxNode,
|
||||||
target_module: &hir::Module,
|
target_module: &hir::Module,
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
|
let insert_before = node_to_insert_before(target_node);
|
||||||
|
|
||||||
if ctx
|
if ctx
|
||||||
.find_node_at_offset::<ast::SourceFile>()?
|
.sema
|
||||||
.syntax()
|
.scope(&insert_before)?
|
||||||
.children()
|
.module()
|
||||||
.filter_map(|node| ast::Enum::cast(node).and_then(|e| ctx.sema.to_def(&e)))
|
.scope(ctx.db(), Some(*target_module))
|
||||||
.any(|def| def.name(ctx.db()).as_str() == Some("Bool"))
|
.iter()
|
||||||
|
.any(|(name, _)| name.as_str() == Some("Bool"))
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@ -482,7 +485,6 @@ fn add_enum_def(
|
|||||||
.any(|module| module.nearest_non_block_module(ctx.db()) != *target_module);
|
.any(|module| module.nearest_non_block_module(ctx.db()) != *target_module);
|
||||||
let enum_def = make_bool_enum(make_enum_pub);
|
let enum_def = make_bool_enum(make_enum_pub);
|
||||||
|
|
||||||
let insert_before = node_to_insert_before(target_node);
|
|
||||||
let indent = IndentLevel::from_node(&insert_before);
|
let indent = IndentLevel::from_node(&insert_before);
|
||||||
enum_def.reindent_to(indent);
|
enum_def.reindent_to(indent);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user