Skip to content

Commit

Permalink
test: Fix worksheet tests after changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Dec 1, 2024
1 parent 3fafac4 commit 3aea43d
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,9 @@ class WorkspaceLspService(

override def inlayHints(
params: lsp4j.InlayHintParams
): CompletableFuture[java.util.List[lsp4j.InlayHint]] =
): CompletableFuture[java.util.List[lsp4j.InlayHint]] = {
getServiceFor(params.getTextDocument.getUri()).inlayHints(params)

}
override def inlayHintResolve(
inlayHint: lsp4j.InlayHint
): CompletableFuture[lsp4j.InlayHint] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ class WorksheetProvider(
} else Future.successful(Nil)

// TODO switch to only inlay hints
// TODO add tests
private def toInlayHints(
path: AbsolutePath,
worksheet: Option[EvaluatedWorksheetSnapshot],
Expand All @@ -242,7 +241,7 @@ class WorksheetProvider(
}
val hint = new InlayHint(
statEnd,
messages.Either.forLeft(" // " + stat.summary()),
messages.Either.forLeft(" // " + truncatify(stat)),
)
hint.setTooltip(stat.details())
hint
Expand Down
3 changes: 2 additions & 1 deletion tests/cross/src/main/scala/tests/BaseInlayHintsSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class BaseInlayHintsSuite extends BasePCSuite {
.asScala
.toList

val obtained = TestInlayHints.applyInlayHints(withPkg, inlayHints)
val obtained =
TestInlayHints.applyInlayHints(withPkg, inlayHints, withTooltip = false)

assertEquals(
obtained,
Expand Down
33 changes: 27 additions & 6 deletions tests/mtest/src/main/scala/tests/TestInlayHints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,37 @@ object TestInlayHints {
// |
// v
// val y<<: T/*(0:5,0:5)*/>> = x
def decorationString(inlayHint: InlayHint): String = {
def decorationString(inlayHint: InlayHint, withTooltip: Boolean): String = {
val buffer = ListBuffer.empty[String]

val labels = inlayHint.getLabel().asScala match {
case Left(label) => List(label)
case Right(labelParts) => labelParts.asScala.map(_.getValue()).toList
}

val tooltip = Option(inlayHint.getTooltip()).map(t =>
t.asScala match {
case Left(tooltip) => tooltip
case Right(markdown) => markdown.getValue()
}
)
val data =
inlayHint.getData().asInstanceOf[Array[Any]]
buffer += "/*"
labels.zip(data).foreach { case (label, data) =>
buffer += label
buffer ++= readData(data)
if (data != null) {
labels.zip(data).foreach { case (label, data) =>
buffer += label
buffer ++= readData(data)
}
} else {
buffer += labels.mkString
}
if (withTooltip)
tooltip.foreach { tooltip =>
buffer += "| "
buffer += tooltip.replace("\n", "\\n")
buffer += " |"
}
buffer += "*/"
buffer.toList.mkString
}
Expand All @@ -52,9 +69,13 @@ object TestInlayHints {
}
}

def applyInlayHints(text: String, inlayHints: List[InlayHint]): String = {
def applyInlayHints(
text: String,
inlayHints: List[InlayHint],
withTooltip: Boolean
): String = {
val textEdits = inlayHints.map { hint =>
val newText = decorationString(hint)
val newText = decorationString(hint, withTooltip)
val range = new l.Range(hint.getPosition(), hint.getPosition())
new TextEdit(
range,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ abstract class BaseInlayHintsExpectSuite(
)
val inlayHints =
compiler.inlayHints(pcParams).get().asScala.toList
TestInlayHints.applyInlayHints(file.code, inlayHints)
TestInlayHints.applyInlayHints(
file.code,
inlayHints,
withTooltip = false,
)
},
)
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/src/main/scala/tests/BaseInlayHintsLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ abstract class BaseInlayHintsLspSuite(name: String, scalaVersion: String)
code,
expected,
workspace,
withTooltip = false,
postprocessObtained = identity,
)
} yield ()
}
Expand Down
Loading

0 comments on commit 3aea43d

Please sign in to comment.