Skip to content

Commit 29dc892

Browse files
committed
fix: insert missing members in correct place for case classes
1 parent 04ada79 commit 29dc892

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

presentation-compiler/src/main/dotty/tools/pc/completions/OverrideCompletions.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ object OverrideCompletions:
506506
defn match
507507
case td: TypeDef if text.charAt(td.rhs.span.end) == ':' =>
508508
Some(td.rhs.span.end)
509+
case TypeDef(_, temp : Template) =>
510+
temp.parentsOrDerived.lastOption.map(_.span.end).filter(text.charAt(_) == ':')
509511
case _ => None
510512

511513
private def fallbackFromParent(parent: Tree, name: String)(using Context) =

presentation-compiler/test/dotty/tools/pc/tests/edit/AutoImplementAbstractMembersSuite.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,35 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite:
12721272
|""".stripMargin,
12731273
)
12741274

1275+
@Test def `braceless-case-class` =
1276+
checkEdit(
1277+
"""|package a
1278+
|
1279+
|trait Base:
1280+
| def foo(x: Int): Int
1281+
| def bar(x: String): String
1282+
|
1283+
|case class <<Concrete>>() extends Base:
1284+
| def aaa = "aaa"
1285+
|end Concrete
1286+
|""".stripMargin,
1287+
"""|package a
1288+
|
1289+
|trait Base:
1290+
| def foo(x: Int): Int
1291+
| def bar(x: String): String
1292+
|
1293+
|case class Concrete() extends Base:
1294+
|
1295+
| override def bar(x: String): String = ???
1296+
|
1297+
| override def foo(x: Int): Int = ???
1298+
|
1299+
| def aaa = "aaa"
1300+
|end Concrete
1301+
|""".stripMargin
1302+
)
1303+
12751304
def checkEdit(
12761305
original: String,
12771306
expected: String

0 commit comments

Comments
 (0)