Skip to content

Commit

Permalink
Use JLine3
Browse files Browse the repository at this point in the history
Minimal changes to support new API,
with basic completion and history.
JLine handles continuation line edit.
  • Loading branch information
som-snytt authored and adriaanm committed Jun 20, 2019
1 parent 9fe2c17 commit c9f4bf7
Show file tree
Hide file tree
Showing 24 changed files with 440 additions and 673 deletions.
34 changes: 25 additions & 9 deletions build.sbt
Expand Up @@ -44,7 +44,9 @@ val junitDep = "junit" % "junit"
val junitInterfaceDep = "com.novocode" % "junit-interface" % "0.11" % "test"
val jolDep = "org.openjdk.jol" % "jol-core" % "0.9"
val asmDep = "org.scala-lang.modules" % "scala-asm" % versionProps("scala-asm.version")
val jlineDep = "jline" % "jline" % versionProps("jline.version")
val jlineDep = "org.jline" % "jline" % versionProps("jline.version")
val jansiDep = "org.fusesource.jansi" % "jansi" % versionProps("jansi.version")
val jnaDep = "net.java.dev.jna" % "jna" % versionProps("jna.version")
val testInterfaceDep = "org.scala-sbt" % "test-interface" % "1.0"
val diffUtilsDep = "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0"

Expand Down Expand Up @@ -165,6 +167,7 @@ lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories
"-doc-source-url", s"https://github.com/scala/scala/tree/${versionProperties.value.githubTree}€{FILE_PATH_EXT}#L€{FILE_LINE}"
),
//maxErrors := 10,
maxErrors := 10,
setIncOptions,
apiURL := Some(url("https://www.scala-lang.org/api/" + versionProperties.value.mavenVersion + "/")),
pomIncludeRepository := { _ => false },
Expand Down Expand Up @@ -406,7 +409,7 @@ lazy val compiler = configureAsSubproject(project)
libraryDependencies += asmDep,
// These are only needed for the POM:
// TODO: jline dependency is only needed for the REPL shell, which should move to its own jar
libraryDependencies ++= Seq(jlineDep),
libraryDependencies ++= Seq(jlineDep, jansiDep, jnaDep),
buildCharacterPropertiesFile := (resourceManaged in Compile).value / "scala-buildcharacter.properties",
resourceGenerators in Compile += generateBuildCharacterPropertiesFile.map(file => Seq(file)).taskValue,
// this a way to make sure that classes from interactive and scaladoc projects
Expand Down Expand Up @@ -444,9 +447,16 @@ lazy val compiler = configureAsSubproject(project)
"-doc-root-content", (sourceDirectory in Compile).value + "/rootdoc.txt"
),
Osgi.headers ++= Seq(
"Import-Package" -> ("jline.*;resolution:=optional," +
raw"""scala.*;version="$${range;[==,=+);$${ver}}",""" +
"*"),
"Import-Package" -> raw"""org.jline.keymap.*;resolution:=optional
|org.jline.reader.*;resolution:=optional
|org.jline.style.*;resolution:=optional
|org.jline.terminal;resolution:=optional
|org.jline.terminal.impl;resolution:=optional
|org.jline.terminal.impl.jansi.*;resolution:=optional
|org.jline.terminal.spi;resolution:=optional
|org.jline.utils;resolution:=optional
|scala.*;version="$${range;[==,=+);$${ver}}"
|*""".stripMargin.linesIterator.mkString(","),
"Class-Path" -> "scala-reflect.jar scala-library.jar"
),
// Generate the ScriptEngineFactory service definition. The old Ant build did this when building
Expand Down Expand Up @@ -481,7 +491,7 @@ lazy val replFrontend = configureAsSubproject(Project("repl-frontend", file(".")
.settings(disableDocs)
.settings(skip in publish := true)
.settings(
libraryDependencies += jlineDep,
libraryDependencies ++= Seq(jlineDep, jansiDep, jnaDep),
name := "scala-repl-frontend"
)
.settings(
Expand Down Expand Up @@ -834,7 +844,7 @@ lazy val scalaDist = Project("scala-dist", file(".") / "target" / "scala-dist-di
(htmlOut ** "*.html").get ++ (fixedManOut ** "*.1").get
}.taskValue,
managedResourceDirectories in Compile := Seq((resourceManaged in Compile).value),
libraryDependencies += jlineDep,
libraryDependencies ++= Seq(jlineDep, jansiDep, jnaDep),
apiURL := None,
fixPom(
"/project/name" -> <name>Scala Distribution Artifacts</name>,
Expand Down Expand Up @@ -973,7 +983,7 @@ lazy val distDependencies = Seq(replFrontend, compiler, library, reflect, scalap
lazy val dist = (project in file("dist"))
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(jlineDep),
libraryDependencies ++= Seq(jlineDep, jansiDep, jnaDep),
mkBin := mkBinImpl.value,
mkQuick := Def.task {
val cp = (fullClasspath in IntegrationTest in LocalProject("test")).value
Expand All @@ -988,7 +998,13 @@ lazy val dist = (project in file("dist"))
packageBin in Compile := {
val targetDir = (buildDirectory in ThisBuild).value / "pack" / "lib"
val jlineJAR = findJar((dependencyClasspath in Compile).value, jlineDep).get.data
val mappings = Seq((jlineJAR, targetDir / "jline.jar"))
val jansiJAR = findJar((dependencyClasspath in Compile).value, jansiDep).get.data
val jnaJAR = findJar((dependencyClasspath in Compile).value, jnaDep).get.data
val mappings = Seq(
(jlineJAR, targetDir / "jline.jar"),
(jansiJAR, targetDir / "jansi.jar"),
(jnaJAR, targetDir / "jna.jar"),
)
IO.copy(mappings, CopyOptions() withOverwrite true)
targetDir
},
Expand Down
Expand Up @@ -13,7 +13,6 @@
package scala.tools.nsc
package fsc

//import scala.tools.nsc.{AbstractScriptRunner, ScriptRunner, GenericRunnerSettings, Settings}
import scala.reflect.io.Path
import scala.util.control.NonFatal

Expand Down
11 changes: 10 additions & 1 deletion src/compiler/scala/tools/nsc/settings/ScalaSettings.scala
Expand Up @@ -121,7 +121,16 @@ trait ScalaSettings extends AbsScalaSettings
val maxwarns = IntSetting ("-Xmaxwarns", "Maximum warnings to print", 100, None, _ => None)
val Xmigration = ScalaVersionSetting ("-Xmigration", "version", "Warn about constructs whose behavior may have changed since version.", initial = NoScalaVersion, default = Some(AnyScalaVersion))
val nouescape = BooleanSetting ("-Xno-uescape", "Disable handling of \\u unicode escapes.")
val Xnojline = BooleanSetting ("-Xnojline", "Do not use JLine for editing.")
val Xjline = ChoiceSetting (
name = "-Xjline",
helpArg = "mode",
descr = "Select JLine mode.",
choices = List("emacs", "vi", "off"),
default = "emacs",
choicesHelp = List(
"emacs key bindings.",
"vi key bindings",
"No JLine editing."))
val Xverify = BooleanSetting ("-Xverify", "Verify generic signatures in generated bytecode.")
val plugin = MultiStringSetting ("-Xplugin", "paths", "Load a plugin from each classpath.")
val disable = MultiStringSetting ("-Xplugin-disable", "plugin", "Disable plugins by name.")
Expand Down
2 changes: 1 addition & 1 deletion src/partest/scala/tools/partest/ReplTest.scala
Expand Up @@ -26,7 +26,7 @@ abstract class ReplTest extends DirectTest {
// final because we need to enforce the existence of a couple settings.
final override def settings: Settings = {
val s = super.settings
s.Xnojline.value = true
s.Xjline.value = "off"
if (getClass.getClassLoader.getParent != null) {
s.classpath.value = s.classpath.value match {
case "" => testOutput.toString
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c9f4bf7

Please sign in to comment.