Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update scala3-presentation-compiler to 39e349e #18296

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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