-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add support for Scala-CLI #919
Closed
Closed
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
a431f46
draft of scli runner
Maeeen ed66eb4
Scli actor runs scripts as an SbtActor
Maeeen 4de24bd
Add instrumentation
Maeeen 20c0255
beginning of bsp
Maeeen 84bf730
blabla
Maeeen e224425
Bsp incomprehension
Maeeen 0346e55
ca
Maeeen e676e9c
wow bsp runs!
Maeeen 970a914
Refactoring
Maeeen b12439a
Refactor using Future
Maeeen 4311e11
Handle user directives from code
Maeeen 07eb170
Add correct compilation error handling
Maeeen f4aa8a7
Remove debug code + add todo
Maeeen f00cbbb
Handle every issue
Maeeen 49edcaf
Add instrumentation result
Maeeen 88f1c3d
Small refactor
Maeeen 4c77e80
Beginning of tests
Maeeen 7d24174
Refactor instrumentation and add some test
Maeeen de8903f
Add instrumentation test + some fixes
Maeeen 37b169b
Run now directly by the runner, add cancelation (#1)
Maeeen f2a0d67
Added log and diagnostics even if it did compile (#2)
Maeeen b2065f8
better (#3)
Maeeen 9556dce
Fix of `ScastieOffsetParams`
Maeeen 94e7f09
Reload metals option
Maeeen 723b9b2
Fix
Maeeen ac050e7
UI (#5)
Maeeen e59c43c
Tests (#4)
Maeeen 3e644ff
Added reconnect and timeout parameter
Maeeen f82d309
Updated build.sbt
Maeeen aa6460e
Made compilable + rebased on scalacenter/scastie
Maeeen 31f1052
Fixed rebasing, now prorperly rebased to scalacenter/scastie
Maeeen 294f7a8
Fix test of ScliRunner
Maeeen 37b435e
Update the LB to handle SBT and SCli snippets differently (#6)
Maeeen 34a8bfa
Scli lb (#8)
Maeeen 0898f6b
Remove dead letter case of Scli runner
Maeeen de70093
Update build.sbt to start ScliRunner
Maeeen c84790a
Merge branch 'main' into main
Maeeen 7484a05
Make ScastieMetalsOption's code argument default to None
Maeeen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,7 @@ object ScalaTarget { | |
formatNative.writes(native) ++ JsObject(Seq("tpe" -> JsString("Native"))) | ||
case dotty: Scala3 => | ||
formatScala3.writes(dotty) ++ JsObject(Seq("tpe" -> JsString("Scala3"))) | ||
case scli: ScalaCli => JsObject(Seq("tpe" -> JsString("ScalaCli"))) | ||
} | ||
} | ||
|
||
|
@@ -91,6 +92,7 @@ object ScalaTarget { | |
case "Typelevel" => formatTypelevel.reads(json) | ||
case "Native" => formatNative.reads(json) | ||
case "Scala3" | "Dotty" => formatScala3.reads(json) | ||
case "ScalaCli" => JsSuccess(ScalaCli()) | ||
case _ => JsError(Seq()) | ||
} | ||
case _ => JsError(Seq()) | ||
|
@@ -109,6 +111,29 @@ object ScalaTarget { | |
) | ||
) | ||
|
||
def fromScalaVersion(version: String): Option[ScalaTarget] = { | ||
if (version.startsWith("3")) { | ||
if (version == "3") | ||
Some(ScalaTarget.Scala3(BuildInfo.latest3)) | ||
else | ||
Some(ScalaTarget.Scala3(version)) | ||
} else if (version.startsWith("2")) { | ||
if (version == "2") | ||
Some(ScalaTarget.Jvm(BuildInfo.latest213)) | ||
else if (version == "2.13") | ||
Some(ScalaTarget.Jvm(BuildInfo.latest213)) | ||
else if (version == "2.12") | ||
Some(ScalaTarget.Jvm(BuildInfo.latest212)) | ||
else if (version == "2.11") | ||
Some(ScalaTarget.Jvm(BuildInfo.latest211)) | ||
else if (version == "2.10") | ||
Some(ScalaTarget.Jvm(BuildInfo.latest210)) | ||
else | ||
Some(ScalaTarget.Jvm(version)) | ||
} else | ||
None | ||
} | ||
|
||
object Jvm { | ||
def default: ScalaTarget = ScalaTarget.Jvm(scalaVersion = BuildInfo.latest213) | ||
} | ||
|
@@ -299,4 +324,37 @@ object ScalaTarget { | |
override def toString: String = | ||
s"Scala $scalaVersion" | ||
} | ||
|
||
object ScalaCli { | ||
def default: ScalaTarget = ScalaCli() | ||
|
||
def defaultCode: String = | ||
"""|// Hello! | ||
|// Scastie is compatible with Scala CLI! You can use | ||
|// directives: https://scala-cli.virtuslab.org/docs/guides/using-directives/ | ||
| | ||
|println("Hi Scala CLI <3") | ||
""".stripMargin | ||
} | ||
|
||
case class ScalaCli(scalaBinaryVersion0: String = "") extends ScalaTarget { | ||
override def binaryScalaVersion: String = scalaBinaryVersion0 | ||
Maeeen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
override def scalaVersion: String = "" | ||
|
||
override def targetType: ScalaTargetType = ScalaTargetType.ScalaCli | ||
|
||
override def scaladexRequest: Map[String,String] = | ||
Map("target" -> "JVM") | ||
|
||
override def renderSbt(lib: ScalaDependency): String = "// Non-applicable" | ||
|
||
override def sbtConfig: String = "// Non-applicable" | ||
|
||
override def sbtPluginsConfig: String = "// Non-applicable" | ||
|
||
override def sbtRunCommand(worksheetMode: Boolean): String = ??? | ||
Comment on lines
+352
to
+356
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would be better to remove it from parent trait and make it only present in SBT compatible BuildTarget's |
||
|
||
override def toString: String = "Scala-CLI" | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
api/src/main/scala/com.olegych.scastie.api/ScliState.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.olegych.scastie.api | ||
|
||
import play.api.libs.json._ | ||
|
||
sealed trait ScliState extends ServerState | ||
object ScliState { | ||
case object Unknown extends ScliState { | ||
override def toString: String = "Unknown" | ||
def isReady: Boolean = true | ||
} | ||
|
||
case object Disconnected extends ScliState { | ||
override def toString: String = "Disconnected" | ||
def isReady: Boolean = false | ||
} | ||
|
||
implicit object ScliStateFormat extends Format[ScliState] { | ||
def writes(state: ScliState): JsValue = { | ||
JsString(state.toString) | ||
} | ||
|
||
private val values = | ||
List( | ||
Unknown, | ||
Disconnected | ||
).map(v => (v.toString, v)).toMap | ||
|
||
def reads(json: JsValue): JsResult[ScliState] = { | ||
json match { | ||
case JsString(tpe) => { | ||
values.get(tpe) match { | ||
case Some(v) => JsSuccess(v) | ||
case _ => JsError(Seq()) | ||
} | ||
} | ||
case _ => JsError(Seq()) | ||
} | ||
} | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
balancer/src/main/scala/com.olegych.scastie.balancer/BaseDispatcher.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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.olegych.scastie.balancer | ||
|
||
import com.typesafe.config.Config | ||
import akka.actor.ActorSelection | ||
import com.olegych.scastie.api.ActorConnected | ||
import akka.actor.ActorLogging | ||
import akka.actor.Actor | ||
import akka.actor.ActorRef | ||
import scala.concurrent.Future | ||
import akka.pattern.ask | ||
import akka.util.Timeout | ||
import scala.concurrent.duration._ | ||
import com.olegych.scastie.api.RunnerPing | ||
|
||
abstract class BaseDispatcher[R, S](config: Config) extends Actor with ActorLogging { | ||
case class SocketAddress(host: String, port: Int) | ||
|
||
import context._ | ||
|
||
private def getRemoteActorsPath( | ||
key: String, | ||
runnerName: String, | ||
actorName: String | ||
): Map[SocketAddress, String] = { | ||
val host = config.getString(s"remote-$key-hostname") | ||
val portStart = config.getInt(s"remote-$key-ports-start") | ||
val portSize = config.getInt(s"remote-$key-ports-size") | ||
(0 until portSize).map(_ + portStart) | ||
.map(port => { | ||
val addr = SocketAddress(host, port) | ||
(addr, getRemoteActorPath(runnerName, addr, actorName)) | ||
}) | ||
.toMap | ||
} | ||
|
||
def getRemoteActorPath( | ||
runnerName: String, | ||
runnerAddress: SocketAddress, | ||
actorName: String | ||
) = s"akka://$runnerName@${runnerAddress.host}:${runnerAddress.port}/user/$actorName" | ||
|
||
def connectRunner(path: String): ActorSelection = { | ||
val selection = context.actorSelection(path) | ||
selection ! ActorConnected | ||
selection | ||
} | ||
|
||
def getRemoteServers( | ||
key: String, | ||
runnerName: String, | ||
actorName: String | ||
): Map[SocketAddress, ActorSelection] = { | ||
getRemoteActorsPath(key, runnerName, actorName).map { | ||
case (address, url) => (address, connectRunner(url)) | ||
} | ||
} | ||
|
||
def ping(servers: List[ActorSelection]): Future[List[Boolean]] = { | ||
implicit val timeout: Timeout = Timeout(10.seconds) | ||
val futures = servers.map { s => | ||
(s ? RunnerPing).map { _ => | ||
log.info(s"pinged $s") | ||
true | ||
}.recover { e => | ||
log.error(e, s"could not ping $s") | ||
false | ||
} | ||
} | ||
Future.sequence(futures) | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I see this code is used to parse Scala version for metals. If that is the case, you can't fallback to latest 3 if Scala version starts with 3. Each version of Scala has a fully cross versioned dependency and has to be the proper version e.g. Let's imagine if there is some bugfix in latest3, but the real version is < latest3. The code won't compile resulting in no completions at all even tho it is valid code according to selected version. You should use the full version e.g 3.3.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not actually how it handles the Scala version.
But now that we actually talk about it, I thought that the format 3.x is illegal. Is it the case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I didnt' notice. So is there any reason we are using the latest version for 2.13, 2.12 etc ? I think we shouldn't use latest version for example what will happen if user sets 2.13.10 and wants to show something specific to this version ?