Skip to content

Commit

Permalink
Apply fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
MaciejG604 committed Dec 11, 2023
1 parent 345cf7b commit caedc81
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object DeprecatedDirectives {
handler.keys.flatMap(_.nameAliases)

private val deprecatedCombinationsAndReplacements = Map[DirectiveTemplate, WarningAndReplacement](
DirectiveTemplate(Seq("lib"), None) -> keyReplacement("dep")(deprecatedWarning("lib", "dep")),
DirectiveTemplate(Seq("lib"), None) -> keyReplacement("dep")(deprecatedWarning("lib", "dep")),
DirectiveTemplate(Seq("libs"), None) -> keyReplacement("dep")(deprecatedWarning("libs", "dep")),
DirectiveTemplate(Seq("compileOnly.lib"), None) -> keyReplacement("compileOnly.dep")(
deprecatedWarning("compileOnly.lib", "compileOnly.dep")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ import scala.build.Ops.EitherOptOps
import scala.build.*
import scala.build.compiler.{BloopCompilerMaker, ScalaCompilerMaker, SimpleScalaCompilerMaker}
import scala.build.directives.DirectiveDescription
import scala.build.errors.{
AmbiguousPlatformError,
BuildException,
ConfigDbException,
Severity
}
import scala.build.errors.{AmbiguousPlatformError, BuildException, ConfigDbException, Severity}
import scala.build.input.{Element, Inputs, ResourceDirectory, ScalaCliInvokeData}
import scala.build.interactive.Interactive
import scala.build.interactive.Interactive.{InteractiveAsk, InteractiveNop}
Expand Down Expand Up @@ -728,9 +723,7 @@ object SharedOptions {
toolkitVersion: Option[String],
logger: Logger
): Seq[Positioned[AnyDependency]] = {
if (
toolkitVersion.contains("latest") || toolkitVersion.contains(Toolkit.typelevel + ":latest")
)
if (toolkitVersion.contains("latest") || toolkitVersion.contains(Toolkit.typelevel + ":latest"))
logger.message(
s"""WARNING: using 'latest' for toolkit is deprecated, use 'default' to get more stable behaviour:
| --toolkit ${toolkitVersion.map(_.replace("latest", "default")).getOrElse("default")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1909,133 +1909,133 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
}

test("actionable diagnostics on deprecated using directives") {
val inputs = TestInputs(
os.rel / "test.sc" ->
"""//> using toolkit latest
|//> using test.toolkit typelevel:latest
|
|//> using lib org.typelevel::cats-core:2.6.1
|
|object Test extends App {
| println("Hello")
|}
|""".stripMargin
)
val inputs = TestInputs(
os.rel / "test.sc" ->
"""//> using toolkit latest
|//> using test.toolkit typelevel:latest
|
|//> using lib org.typelevel::cats-core:2.6.1
|
|object Test extends App {
| println("Hello")
|}
|""".stripMargin
)

withBsp(inputs, Seq(".", "--actions=false")) { (root, localClient, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val target = {
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
expect(targets.length == 2)
extractMainTargets(targets)
}
withBsp(inputs, Seq(".", "--actions=false")) { (root, localClient, remoteServer) =>
async {
val buildTargetsResp = await(remoteServer.workspaceBuildTargets().asScala)
val target = {
val targets = buildTargetsResp.getTargets.asScala.map(_.getId).toSeq
expect(targets.length == 2)
extractMainTargets(targets)
}

val targetUri = TestUtil.normalizeUri(target.getUri)
checkTargetUri(root, targetUri)
val targetUri = TestUtil.normalizeUri(target.getUri)
checkTargetUri(root, targetUri)

val targets = List(target).asJava
val targets = List(target).asJava

val compileResp = await {
remoteServer
.buildTargetCompile(new b.CompileParams(targets))
.asScala
}
expect(compileResp.getStatusCode == b.StatusCode.OK)
val compileResp = await {
remoteServer
.buildTargetCompile(new b.CompileParams(targets))
.asScala
}
expect(compileResp.getStatusCode == b.StatusCode.OK)

val diagnosticsParams = {
val diagnostics = localClient.diagnostics()
.filter(_.getReset == false)
expect(diagnostics.size == 3)
val params = diagnostics.head
expect(params.getBuildTarget.getUri == targetUri)
expect(
TestUtil.normalizeUri(params.getTextDocument.getUri) ==
TestUtil.normalizeUri((root / "test.sc").toNIO.toUri.toASCIIString)
)
diagnostics
}
val diagnosticsParams = {
val diagnostics = localClient.diagnostics()
.filter(_.getReset == false)
expect(diagnostics.size == 3)
val params = diagnostics.head
expect(params.getBuildTarget.getUri == targetUri)
expect(
TestUtil.normalizeUri(params.getTextDocument.getUri) ==
TestUtil.normalizeUri((root / "test.sc").toNIO.toUri.toASCIIString)
)
diagnostics
}

val diagnostics = diagnosticsParams.flatMap(_.getDiagnostics.asScala)
.sortBy(_.getRange().getEnd().getCharacter())

{
checkDiagnostic(
diagnostic = diagnostics.apply(0),
expectedMessage =
"Using `latest` is deprecated, use `default` instead",
expectedSeverity = b.DiagnosticSeverity.WARNING,
expectedStartLine = 0,
expectedStartCharacter = 10,
expectedEndLine = 0,
expectedEndCharacter = 24
)
val diagnostics = diagnosticsParams.flatMap(_.getDiagnostics.asScala)
.sortBy(_.getRange().getEnd().getCharacter())

checkScalaAction(
diagnostic = diagnostics.apply(0),
expectedActionsSize = 1,
expectedTitle = "Change to: toolkit default",
expectedChanges = 1,
expectedStartLine = 0,
expectedStartCharacter = 10,
expectedEndLine = 0,
expectedEndCharacter = 24,
expectedNewText = "toolkit default"
)
}
{
checkDiagnostic(
diagnostic = diagnostics.apply(0),
expectedMessage =
"Using `latest` is deprecated, use `default` instead",
expectedSeverity = b.DiagnosticSeverity.WARNING,
expectedStartLine = 0,
expectedStartCharacter = 10,
expectedEndLine = 0,
expectedEndCharacter = 24
)

{
checkDiagnostic(
diagnostic = diagnostics.apply(1),
expectedMessage =
"Using `latest` is deprecated, use `default` instead",
expectedSeverity = b.DiagnosticSeverity.WARNING,
expectedStartLine = 1,
expectedStartCharacter = 10,
expectedEndLine = 1,
expectedEndCharacter = 39
)
checkScalaAction(
diagnostic = diagnostics.apply(0),
expectedActionsSize = 1,
expectedTitle = "Change to: toolkit default",
expectedChanges = 1,
expectedStartLine = 0,
expectedStartCharacter = 10,
expectedEndLine = 0,
expectedEndCharacter = 24,
expectedNewText = "toolkit default"
)
}

checkScalaAction(
diagnostic = diagnostics.apply(1),
expectedActionsSize = 1,
expectedTitle = "Change to: test.toolkit typelevel:default",
expectedChanges = 1,
expectedStartLine = 1,
expectedStartCharacter = 10,
expectedEndLine = 1,
expectedEndCharacter = 39,
expectedNewText = "test.toolkit typelevel:default"
)
}
{
checkDiagnostic(
diagnostic = diagnostics.apply(1),
expectedMessage =
"Using `latest` is deprecated, use `default` instead",
expectedSeverity = b.DiagnosticSeverity.WARNING,
expectedStartLine = 1,
expectedStartCharacter = 10,
expectedEndLine = 1,
expectedEndCharacter = 39
)

{
checkDiagnostic(
diagnostic = diagnostics.apply(2),
expectedMessage =
"Using `lib` is deprecated, use `dep` instead",
expectedSeverity = b.DiagnosticSeverity.WARNING,
expectedStartLine = 3,
expectedStartCharacter = 10,
expectedEndLine = 3,
expectedEndCharacter = 44
)
checkScalaAction(
diagnostic = diagnostics.apply(1),
expectedActionsSize = 1,
expectedTitle = "Change to: test.toolkit typelevel:default",
expectedChanges = 1,
expectedStartLine = 1,
expectedStartCharacter = 10,
expectedEndLine = 1,
expectedEndCharacter = 39,
expectedNewText = "test.toolkit typelevel:default"
)
}

checkScalaAction(
diagnostic = diagnostics.apply(2),
expectedActionsSize = 1,
expectedTitle = "Change to: dep org.typelevel::cats-core:2.6.1",
expectedChanges = 1,
expectedStartLine = 3,
expectedStartCharacter = 10,
expectedEndLine = 3,
expectedEndCharacter = 44,
expectedNewText = "dep org.typelevel::cats-core:2.6.1"
)
}
{
checkDiagnostic(
diagnostic = diagnostics.apply(2),
expectedMessage =
"Using `lib` is deprecated, use `dep` instead",
expectedSeverity = b.DiagnosticSeverity.WARNING,
expectedStartLine = 3,
expectedStartCharacter = 10,
expectedEndLine = 3,
expectedEndCharacter = 44
)

checkScalaAction(
diagnostic = diagnostics.apply(2),
expectedActionsSize = 1,
expectedTitle = "Change to: dep org.typelevel::cats-core:2.6.1",
expectedChanges = 1,
expectedStartLine = 3,
expectedStartCharacter = 10,
expectedEndLine = 3,
expectedEndCharacter = 44,
expectedNewText = "dep org.typelevel::cats-core:2.6.1"
)
}
}
}
}

private def checkIfBloopProjectIsInitialised(
root: os.Path,
Expand Down Expand Up @@ -2099,16 +2099,16 @@ abstract class BspTestDefinitions(val scalaVersionOpt: Option[String])
}

private def checkScalaAction(
diagnostic: b.Diagnostic,
expectedActionsSize: Int,
expectedTitle: String,
expectedChanges: Int,
expectedStartLine: Int,
expectedStartCharacter: Int,
expectedEndLine: Int,
expectedEndCharacter: Int,
expectedNewText: String
) = {
diagnostic: b.Diagnostic,
expectedActionsSize: Int,
expectedTitle: String,
expectedChanges: Int,
expectedStartLine: Int,
expectedStartCharacter: Int,
expectedEndLine: Int,
expectedEndCharacter: Int,
expectedNewText: String
) = {
expect(diagnostic.getDataKind == "scala")

val gson = new com.google.gson.Gson()
Expand Down
Loading

0 comments on commit caedc81

Please sign in to comment.