Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/reorder_fields.rs')
-rw-r--r--crates/ide-assists/src/handlers/reorder_fields.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/crates/ide-assists/src/handlers/reorder_fields.rs b/crates/ide-assists/src/handlers/reorder_fields.rs
index 58dcaf9a22..cd977a68a6 100644
--- a/crates/ide-assists/src/handlers/reorder_fields.rs
+++ b/crates/ide-assists/src/handlers/reorder_fields.rs
@@ -20,9 +20,10 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// const test: Foo = Foo {foo: 1, bar: 0}
// ```
pub(crate) fn reorder_fields(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
- let record = ctx.find_node_at_offset::<Either<ast::RecordExpr, ast::RecordPat>>()?;
+ let path = ctx.find_node_at_offset::<ast::Path>()?;
+ let record =
+ path.syntax().parent().and_then(<Either<ast::RecordExpr, ast::RecordPat>>::cast)?;
- let path = record.as_ref().either(|it| it.path(), |it| it.path())?;
let ranks = compute_fields_ranks(&path, ctx)?;
let get_rank_of_field =
|of: Option<_>| *ranks.get(&of.unwrap_or_default()).unwrap_or(&usize::MAX);