From a13edd49c900b6a2d5c5347ddcba50cff267d815 Mon Sep 17 00:00:00 2001 From: Katarzyna Marek Date: Wed, 12 Jun 2024 11:54:51 +0200 Subject: [PATCH] improvement: sort abstract members for auto implement --- .../pc/completions/OverrideCompletions.scala | 9 ++++++- .../AutoImplementAbstractMembersSuite.scala | 25 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala index 7ae4c4fae76..fc8f3cf9847 100644 --- a/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala +++ b/mtags/src/main/scala-3/scala/meta/internal/pc/completions/OverrideCompletions.scala @@ -275,7 +275,14 @@ object OverrideCompletions: else "" (indent, indent, lastIndent) end calcIndent - val abstractMembers = defn.tpe.abstractTermMembers.map(_.symbol) + val abstractMembers = + defn.tpe.abstractTermMembers.map(_.symbol).groupBy(_.owner).map { + case (owner, members) => (owner, members.sortWith{ (sym1, sym2) => + if(sym1.sourcePos.exists && sym2.sourcePos.exists) + sym1.sourcePos.start <= sym2.sourcePos.start + else !sym2.sourcePos.exists + }) + }.toSeq.sortBy(_._1.name.decoded).flatMap(_._2) val caseClassOwners = Set("Product", "Equals") val overridables = diff --git a/tests/cross/src/test/scala/tests/pc/AutoImplementAbstractMembersSuite.scala b/tests/cross/src/test/scala/tests/pc/AutoImplementAbstractMembersSuite.scala index 5f0688d04e8..b1e3c82a928 100644 --- a/tests/cross/src/test/scala/tests/pc/AutoImplementAbstractMembersSuite.scala +++ b/tests/cross/src/test/scala/tests/pc/AutoImplementAbstractMembersSuite.scala @@ -370,7 +370,26 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite { | | } |} - |""".stripMargin + |""".stripMargin, + compat = Map( + "3" -> + """|abstract class SuperAbstract { + | def foo: Int + |} + |trait Bar extends SuperAbstract { + | def bar: Int + |} + |object Main { + | class Baz extends Bar { + | + | override def bar: Int = ??? + | + | override def foo: Int = ??? + | + | } + |} + |""".stripMargin + ) ) checkEdit( @@ -1291,10 +1310,10 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite { | |case class Concrete() extends Base: | - | override def bar(x: String): String = ??? - | | override def foo(x: Int): Int = ??? | + | override def bar(x: String): String = ??? + | | def aaa = "aaa" |end Concrete |""".stripMargin