Skip to content

Commit

Permalink
improvement: sort abstract members for auto implement
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Jun 12, 2024
1 parent 32d8642 commit a13edd4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a13edd4

Please sign in to comment.