Skip to content

Commit

Permalink
Update scala3-presentation-compiler to 39e349e (#18296)
Browse files Browse the repository at this point in the history
Update presentation compiler to mtags: 39e349e
  • Loading branch information
rochala authored Jul 27, 2023
1 parent 989c55c commit c04d2db
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ object OverrideCompletions:
.sortBy(_.sourcePos.start)
val source = indexedContext.ctx.source

val shouldCompleteBraces = decls.isEmpty && hasBraces(text, defn).isEmpty
val shouldCompleteBraces = decls.isEmpty && hasBracesOrColon(text, defn).isEmpty

val (startIndent, indent, lastIndent) =
calcIndent(defn, decls, source, text, shouldCompleteBraces)
Expand Down Expand Up @@ -470,7 +470,7 @@ object OverrideCompletions:
private def inferEditPosition(text: String, defn: TargetDef)(using
Context
): SourcePosition =
val span = hasBraces(text, defn)
val span = hasBracesOrColon(text, defn)
.map { offset =>
defn.sourcePos.span.withStart(offset + 1).withEnd(offset + 1)
}
Expand All @@ -480,7 +480,9 @@ object OverrideCompletions:
defn.sourcePos.withSpan(span)
end inferEditPosition

private def hasBraces(text: String, defn: TargetDef): Option[Int] =
private def hasBracesOrColon(text: String, defn: TargetDef)(using
Context
): Option[Int] =
def hasSelfTypeAnnot = defn match
case td: TypeDef =>
td.rhs match
Expand All @@ -489,12 +491,20 @@ object OverrideCompletions:
case _ => false
case _ => false
val start = defn.span.start
val offset =
val braceOffset =
if hasSelfTypeAnnot then text.indexOf("=>", start) + 1
else text.indexOf("{", start)
if offset > 0 && offset < defn.span.end then Some(offset)
else None
end hasBraces
if braceOffset > 0 && braceOffset < defn.span.end then Some(braceOffset)
else hasColon(text, defn)
end hasBracesOrColon

private def hasColon(text: String, defn: TargetDef)(using
Context
): Option[Int] =
defn match
case td: TypeDef if text.charAt(td.rhs.span.end) == ':' =>
Some(td.rhs.span.end)
case _ => None

private def fallbackFromParent(parent: Tree, name: String)(using Context) =
val stats = parent match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ScalaCliCompletions(
// generated script file will end with .sc.scala
case (_: TypeDef) :: Nil if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case (_: Template) :: (_: TypeDef) :: Nil
if pos.source.file.path.endsWith(".sc.scala") =>
scalaCliDep
case head :: next => None

def contribute(dependency: String) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,20 @@ class CompletionArgSuite extends BaseCompletionSuite:
|""".stripMargin,
topLines = Some(4)
)

@Test def `recursive` =
check(
"""|
|object Main {
| def foo(value: Int): Int = {
| foo(valu@@)
| }
|}
|""".stripMargin,
"""|value = : Int
|value = value : Int
|value: Int
|""".stripMargin,
topLines = Some(4),
)

Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ class CompletionScalaCliSuite extends BaseCompletionSuite:
"0.14.1"
)

// We don't to add `::` before version if `sjs1` is specified
@Test def `version-edit` =
checkEdit(
"""|//> using lib "io.circe::circe-core_sjs1:0.14.1@@"
|package A
|""".stripMargin,
"""|//> using lib "io.circe::circe-core_sjs1:0.14.1"
|package A
|""".stripMargin,
)

@Test def `multiple-libs` =
check(
"""|//> using lib "io.circe::circe-core:0.14.0", "io.circe::circe-core_na@@"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,76 @@ class AutoImplementAbstractMembersSuite extends BaseCodeActionSuite:
|""".stripMargin
)

@Test def `end-marker` =
checkEdit(
"""|package a
|
|object A {
| trait Base:
| def foo(x: Int): Int
| def bar(x: String): String
|
| class <<Concrete>> extends Base:
|
| end Concrete
|
|}
|""".stripMargin,
"""|package a
|
|object A {
| trait Base:
| def foo(x: Int): Int
| def bar(x: String): String
|
| class Concrete extends Base:
|
| override def foo(x: Int): Int = ???
|
| override def bar(x: String): String = ???
|
|
| end Concrete
|
|}
|""".stripMargin,
)

@Test def `end-marker2` =
checkEdit(
"""|package a
|
|object A {
| trait Base:
| def foo(x: Int): Int
| def bar(x: String): String
|
| class <<Concrete>>(x: Int, y: String) extends Base:
|
| end Concrete
|
|}
|""".stripMargin,
"""|package a
|
|object A {
| trait Base:
| def foo(x: Int): Int
| def bar(x: String): String
|
| class Concrete(x: Int, y: String) extends Base:
|
| override def foo(x: Int): Int = ???
|
| override def bar(x: String): String = ???
|
|
| end Concrete
|
|}
|""".stripMargin,
)

def checkEdit(
original: String,
expected: String
Expand Down

0 comments on commit c04d2db

Please sign in to comment.