Skip to content

Commit d695788

Browse files
rochalaKordyjan
authored andcommitted
Update scala3-presentation-compiler to 39e349e (#18296)
Update presentation compiler to mtags: 39e349e [Cherry-picked c04d2db]
1 parent edf718b commit d695788

File tree

5 files changed

+118
-7
lines changed

5 files changed

+118
-7
lines changed

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

+17-7
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ object OverrideCompletions:
317317
.sortBy(_.sourcePos.start)
318318
val source = indexedContext.ctx.source
319319

320-
val shouldCompleteBraces = decls.isEmpty && hasBraces(text, defn).isEmpty
320+
val shouldCompleteBraces = decls.isEmpty && hasBracesOrColon(text, defn).isEmpty
321321

322322
val (startIndent, indent, lastIndent) =
323323
calcIndent(defn, decls, source, text, shouldCompleteBraces)
@@ -470,7 +470,7 @@ object OverrideCompletions:
470470
private def inferEditPosition(text: String, defn: TargetDef)(using
471471
Context
472472
): SourcePosition =
473-
val span = hasBraces(text, defn)
473+
val span = hasBracesOrColon(text, defn)
474474
.map { offset =>
475475
defn.sourcePos.span.withStart(offset + 1).withEnd(offset + 1)
476476
}
@@ -480,7 +480,9 @@ object OverrideCompletions:
480480
defn.sourcePos.withSpan(span)
481481
end inferEditPosition
482482

483-
private def hasBraces(text: String, defn: TargetDef): Option[Int] =
483+
private def hasBracesOrColon(text: String, defn: TargetDef)(using
484+
Context
485+
): Option[Int] =
484486
def hasSelfTypeAnnot = defn match
485487
case td: TypeDef =>
486488
td.rhs match
@@ -489,12 +491,20 @@ object OverrideCompletions:
489491
case _ => false
490492
case _ => false
491493
val start = defn.span.start
492-
val offset =
494+
val braceOffset =
493495
if hasSelfTypeAnnot then text.indexOf("=>", start) + 1
494496
else text.indexOf("{", start)
495-
if offset > 0 && offset < defn.span.end then Some(offset)
496-
else None
497-
end hasBraces
497+
if braceOffset > 0 && braceOffset < defn.span.end then Some(braceOffset)
498+
else hasColon(text, defn)
499+
end hasBracesOrColon
500+
501+
private def hasColon(text: String, defn: TargetDef)(using
502+
Context
503+
): Option[Int] =
504+
defn match
505+
case td: TypeDef if text.charAt(td.rhs.span.end) == ':' =>
506+
Some(td.rhs.span.end)
507+
case _ => None
498508

499509
private def fallbackFromParent(parent: Tree, name: String)(using Context) =
500510
val stats = parent match

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

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class ScalaCliCompletions(
2020
// generated script file will end with .sc.scala
2121
case (_: TypeDef) :: Nil if pos.source.file.path.endsWith(".sc.scala") =>
2222
scalaCliDep
23+
case (_: Template) :: (_: TypeDef) :: Nil
24+
if pos.source.file.path.endsWith(".sc.scala") =>
25+
scalaCliDep
2326
case head :: next => None
2427

2528
def contribute(dependency: String) =

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala

+17
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,20 @@ class CompletionArgSuite extends BaseCompletionSuite:
659659
|""".stripMargin,
660660
topLines = Some(4)
661661
)
662+
663+
@Test def `recursive` =
664+
check(
665+
"""|
666+
|object Main {
667+
| def foo(value: Int): Int = {
668+
| foo(valu@@)
669+
| }
670+
|}
671+
|""".stripMargin,
672+
"""|value = : Int
673+
|value = value : Int
674+
|value: Int
675+
|""".stripMargin,
676+
topLines = Some(4),
677+
)
678+

presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionScalaCliSuite.scala

+11
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ class CompletionScalaCliSuite extends BaseCompletionSuite:
6161
"0.14.1"
6262
)
6363

64+
// We don't to add `::` before version if `sjs1` is specified
65+
@Test def `version-edit` =
66+
checkEdit(
67+
"""|//> using lib "io.circe::circe-core_sjs1:0.14.1@@"
68+
|package A
69+
|""".stripMargin,
70+
"""|//> using lib "io.circe::circe-core_sjs1:0.14.1"
71+
|package A
72+
|""".stripMargin,
73+
)
74+
6475
@Test def `multiple-libs` =
6576
check(
6677
"""|//> using lib "io.circe::circe-core:0.14.0", "io.circe::circe-core_na@@"

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

+70
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,76 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite:
12011201
|""".stripMargin
12021202
)
12031203

1204+
@Test def `end-marker` =
1205+
checkEdit(
1206+
"""|package a
1207+
|
1208+
|object A {
1209+
| trait Base:
1210+
| def foo(x: Int): Int
1211+
| def bar(x: String): String
1212+
|
1213+
| class <<Concrete>> extends Base:
1214+
|
1215+
| end Concrete
1216+
|
1217+
|}
1218+
|""".stripMargin,
1219+
"""|package a
1220+
|
1221+
|object A {
1222+
| trait Base:
1223+
| def foo(x: Int): Int
1224+
| def bar(x: String): String
1225+
|
1226+
| class Concrete extends Base:
1227+
|
1228+
| override def foo(x: Int): Int = ???
1229+
|
1230+
| override def bar(x: String): String = ???
1231+
|
1232+
|
1233+
| end Concrete
1234+
|
1235+
|}
1236+
|""".stripMargin,
1237+
)
1238+
1239+
@Test def `end-marker2` =
1240+
checkEdit(
1241+
"""|package a
1242+
|
1243+
|object A {
1244+
| trait Base:
1245+
| def foo(x: Int): Int
1246+
| def bar(x: String): String
1247+
|
1248+
| class <<Concrete>>(x: Int, y: String) extends Base:
1249+
|
1250+
| end Concrete
1251+
|
1252+
|}
1253+
|""".stripMargin,
1254+
"""|package a
1255+
|
1256+
|object A {
1257+
| trait Base:
1258+
| def foo(x: Int): Int
1259+
| def bar(x: String): String
1260+
|
1261+
| class Concrete(x: Int, y: String) extends Base:
1262+
|
1263+
| override def foo(x: Int): Int = ???
1264+
|
1265+
| override def bar(x: String): String = ???
1266+
|
1267+
|
1268+
| end Concrete
1269+
|
1270+
|}
1271+
|""".stripMargin,
1272+
)
1273+
12041274
def checkEdit(
12051275
original: String,
12061276
expected: String

0 commit comments

Comments
 (0)