diff options
| author | winstxnhdw <winstxnhdw@gmail.com> | 2024-07-10 21:13:13 +0100 |
|---|---|---|
| committer | winstxnhdw <winstxnhdw@gmail.com> | 2024-07-10 21:13:13 +0100 |
| commit | d33e96ba008a04796bcd3ae964df04f4ef0bb450 (patch) | |
| tree | bc2aac329999ac0bcb0fca4ea360ca119d4239c3 | |
| parent | 15f08032bfd91fe260ecaa3cd2506d4a0263dc1a (diff) | |
| download | rust-d33e96ba008a04796bcd3ae964df04f4ef0bb450.tar.gz rust-d33e96ba008a04796bcd3ae964df04f4ef0bb450.zip | |
refactor: search for enum semantically
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs index 0534a7139e4..ab25e0167bf 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/bool_to_enum.rs @@ -462,12 +462,15 @@ fn add_enum_def( target_node: SyntaxNode, target_module: &hir::Module, ) -> Option<()> { + let insert_before = node_to_insert_before(target_node); + if ctx - .find_node_at_offset::<ast::SourceFile>()? - .syntax() - .children() - .filter_map(|node| ast::Enum::cast(node).and_then(|e| ctx.sema.to_def(&e))) - .any(|def| def.name(ctx.db()).as_str() == Some("Bool")) + .sema + .scope(&insert_before)? + .module() + .scope(ctx.db(), Some(*target_module)) + .iter() + .any(|(name, _)| name.as_str() == Some("Bool")) { return None; } @@ -482,7 +485,6 @@ fn add_enum_def( .any(|module| module.nearest_non_block_module(ctx.db()) != *target_module); 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); enum_def.reindent_to(indent); |
