Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust actionable diagnostics for scripts (#2815)
* Adjust actionable diagnostics for scripts * Add test for 2.13, and make them run accordingly * Change test format, remove old test * Revert changes made by metalsOrganizeImports
- Loading branch information
Showing
3 changed files
with
169 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 75 additions & 1 deletion
76
modules/integration/src/test/scala/scala/cli/integration/BspTests213.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,77 @@ | ||
package scala.cli.integration | ||
|
||
class BspTests213 extends BspTestDefinitions with Test213 | ||
import ch.epfl.scala.bsp4j as b | ||
import com.eed3si9n.expecty.Expecty.expect | ||
import com.google.gson.{Gson, JsonElement} | ||
|
||
import scala.async.Async.{async, await} | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.jdk.CollectionConverters.* | ||
|
||
class BspTests213 extends BspTestDefinitions with Test213 { | ||
|
||
List(".sc", ".scala").foreach { filetype => | ||
test(s"bsp should report actionable diagnostic from bloop for $filetype files (Scala 2.13)") { | ||
val fileName = s"Hello$filetype" | ||
val inputs = TestInputs( | ||
os.rel / fileName -> | ||
s""" | ||
|object Hello { | ||
| def foo: Any = { | ||
| x: Int => x * 2 | ||
| } | ||
|} | ||
|""".stripMargin | ||
) | ||
withBsp(inputs, Seq(".", "-O", "-Xsource:3")) { | ||
(_, localClient, remoteServer) => | ||
async { | ||
// prepare build | ||
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala) | ||
// build code | ||
val targets = buildTargetsResp.getTargets.asScala.map(_.getId()).asJava | ||
await(remoteServer.buildTargetCompile(new b.CompileParams(targets)).asScala) | ||
|
||
val visibleDiagnostics = | ||
localClient.diagnostics().map(_.getDiagnostics().asScala).find(!_.isEmpty).getOrElse( | ||
Nil | ||
) | ||
|
||
expect(visibleDiagnostics.size == 1) | ||
|
||
val updateActionableDiagnostic = visibleDiagnostics.head | ||
|
||
checkDiagnostic( | ||
diagnostic = updateActionableDiagnostic, | ||
expectedMessage = "parentheses are required around the parameter of a lambda", | ||
expectedSeverity = b.DiagnosticSeverity.ERROR, | ||
expectedStartLine = 3, | ||
expectedStartCharacter = 5, | ||
expectedEndLine = 3, | ||
expectedEndCharacter = 5, | ||
expectedSource = Some("bloop"), | ||
strictlyCheckMessage = false | ||
) | ||
|
||
val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic]( | ||
updateActionableDiagnostic.getData().asInstanceOf[JsonElement], | ||
classOf[b.ScalaDiagnostic] | ||
) | ||
|
||
val actions = scalaDiagnostic.getActions().asScala.toList | ||
assert(actions.size == 1) | ||
val changes = actions.head.getEdit().getChanges().asScala.toList | ||
assert(changes.size == 1) | ||
val textEdit = changes.head | ||
|
||
expect(textEdit.getNewText().contains("(x: Int)")) | ||
expect(textEdit.getRange().getStart.getLine == 3) | ||
expect(textEdit.getRange().getStart.getCharacter == 4) | ||
expect(textEdit.getRange().getEnd.getLine == 3) | ||
expect(textEdit.getRange().getEnd.getCharacter == 10) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |