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 10260be
Show file tree
Hide file tree
Showing 26 changed files with 443 additions and 676 deletions.
34 changes: 25 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions project/ScalaOptionParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object ScalaOptionParser {

// TODO retrieve this data programmatically, ala https://github.com/scala/scala-tool-support/blob/master/bash-completion/src/main/scala/BashCompletion.scala
private def booleanSettingNames = List("-X", "-Xcheckinit", "-Xdev", "-Xdisable-assertions", "-Xexperimental", "-Xfatal-warnings", "-Xlog-free-terms", "-Xlog-free-types", "-Xlog-implicit-conversions", "-Xlog-implicits", "-Xlog-reflective-calls",
"-Xno-forwarders", "-Xno-patmat-analysis", "-Xno-uescape", "-Xnojline", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y",
"-Xno-forwarders", "-Xno-patmat-analysis", "-Xno-uescape", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y",
"-Ybreak-cycles", "-Ydebug", "-Ycompact-trees", "-YdisableFlatCpCaching", "-Ydoc-debug",
"-Yide-debug",
"-Yissue-debug", "-Ylog-classpath", "-Ymacro-debug-lite", "-Ymacro-debug-verbose", "-Ymacro-no-expand",
Expand All @@ -93,7 +93,7 @@ object ScalaOptionParser {
"-Yrepl-sync", "-Yshow-member-pos", "-Yshow-symkinds", "-Yshow-symowners", "-Yshow-syms", "-Yshow-trees", "-Yshow-trees-compact", "-Yshow-trees-stringified", "-Ytyper-debug",
"-Ywarn-dead-code", "-Ywarn-numeric-widen", "-Ywarn-value-discard", "-Ywarn-extra-implicit", "-Ywarn-self-implicit",
"-deprecation", "-explaintypes", "-feature", "-help", "-no-specialization", "-nobootcp", "-nowarn", "-optimise", "-print", "-unchecked", "-uniqid", "-usejavacp", "-usemanifestcp", "-verbose", "-version")
private def stringSettingNames = List("-Xgenerate-phase-graph", "-Xmain-class", "-Xpluginsdir", "-Xshow-class", "-Xshow-object", "-Xsource-reader", "-Ydump-classes", "-Ygen-asmp",
private def stringSettingNames = List("-Xjline", "-Xgenerate-phase-graph", "-Xmain-class", "-Xpluginsdir", "-Xshow-class", "-Xshow-object", "-Xsource-reader", "-Ydump-classes", "-Ygen-asmp",
"-Ypresentation-log", "-Ypresentation-replay", "-Yrepl-outdir", "-d", "-dependencyfile", "-encoding", "-Xscript")
private def pathSettingNames = List("-bootclasspath", "-classpath", "-extdirs", "-javabootclasspath", "-javaextdirs", "-sourcepath", "-toolcp")
private val phases = List("all", "parser", "namer", "packageobjects", "typer", "patmat", "superaccessors", "extmethods", "pickler", "refchecks", "uncurry", "tailcalls", "specialize", "explicitouter", "erasure", "posterasure", "fields", "lambdalift", "constructors", "flatten", "mixin", "cleanup", "delambdafy", "icode", "jvm", "terminal")
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions src/manual/scala/man1/scalac.scala
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ object scalac extends Command {
CmdOption("Xno-uescape"),
"Disable handling of " & BSlash & "u unicode escapes"),
Definition(
CmdOption("Xnojline"),
"Do not use JLine for editing."),
CmdOption("Xjline"),
"The JLine keybindings to use: emacs/vi/off."),
Definition(
CmdOptionBound("Xplugin:", Argument("paths")),
"Load a plugin from each classpath."),
Expand Down
2 changes: 1 addition & 1 deletion src/partest/scala/tools/partest/ReplTest.scala
Original file line number Diff line number Diff line change
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 10260be

Please sign in to comment.