Skip to content

Commit

Permalink
Merge pull request #8036 from som-snytt/issue/jline3
Browse files Browse the repository at this point in the history
REPL: upgrade to JLine 3 (benefits include multi-line editing)
  • Loading branch information
SethTisue committed Mar 25, 2020
2 parents 8ee21e7 + 712aff0 commit bc1cad4
Show file tree
Hide file tree
Showing 34 changed files with 532 additions and 761 deletions.
32 changes: 22 additions & 10 deletions build.sbt
Expand Up @@ -45,8 +45,9 @@ val junitInterfaceDep = "com.novocode" % "junit-interface"
val scalacheckDep = "org.scalacheck" %% "scalacheck" % "1.14.3" % "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 jansiDep = "org.fusesource.jansi" % "jansi" % "1.12"
val jlineDep = "org.jline" % "jline" % versionProps("jline.version")
val jnaDep = "net.java.dev.jna" % "jna" % versionProps("jna.version")
val jlineDeps = Seq(jlineDep, jnaDep)
val testInterfaceDep = "org.scala-sbt" % "test-interface" % "1.0"
val diffUtilsDep = "com.googlecode.java-diff-utils" % "diffutils" % "1.3.0"

Expand Down Expand Up @@ -635,7 +636,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, jansiDep),
libraryDependencies ++= jlineDeps,
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 @@ -676,9 +677,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.jna.*;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 @@ -714,7 +722,7 @@ lazy val replFrontend = configureAsSubproject(Project("repl-frontend", file(".")
.settings(disableDocs)
.settings(skip in publish := true)
.settings(
libraryDependencies += jlineDep,
libraryDependencies ++= jlineDeps,
name := "scala-repl-frontend",
scalacOptions in Compile += "-Xlint:-deprecation,-inaccessible,-nonlocal-return,-valpattern,-doc-detached,_",
)
Expand Down Expand Up @@ -1059,7 +1067,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 ++= jlineDeps,
apiURL := None,
fixPom(
"/project/name" -> <name>Scala Distribution Artifacts</name>,
Expand Down Expand Up @@ -1203,7 +1211,7 @@ lazy val distDependencies = Seq(replFrontend, compiler, library, reflect, scalap
lazy val dist = (project in file("dist"))
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(jlineDep),
libraryDependencies ++= jlineDeps,
mkBin := mkBinImpl.value,
mkQuick := Def.task {
val cp = (fullClasspath in IntegrationTest in testP).value
Expand All @@ -1218,7 +1226,11 @@ 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 jnaJAR = findJar((dependencyClasspath in Compile).value, jnaDep).get.data
val mappings = Seq(
(jlineJAR, targetDir / "jline.jar"),
(jnaJAR, targetDir / "jna.jar"),
)
IO.copy(mappings, CopyOptions() withOverwrite true)
targetDir
},
Expand Down
13 changes: 4 additions & 9 deletions doc/LICENSE.md
Expand Up @@ -28,20 +28,15 @@ which are also included in the `licenses/` directory:
### [Apache License](http://www.apache.org/licenses/LICENSE-2.0.html)
This license is used by the following third-party libraries:

* jansi

### [BSD License](http://www.opensource.org/licenses/bsd-license.php)
This license is used by the following third-party libraries:

* jline
* scalacheck
* JNA

### [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause)
This license is used by the following third-party libraries:

* asm
* ASM
* JLine 3

### [MIT License](http://www.opensource.org/licenses/MIT)
This license is used by the following third-party libraries:

* jquery
* jQuery
16 changes: 8 additions & 8 deletions doc/License.rtf
@@ -1,5 +1,5 @@
{\rtf1\ansi\ansicpg1252\cocoartf1671
{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;}
{\rtf1\ansi\ansicpg1252\cocoartf2511
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fswiss\fcharset0 Helvetica-Bold;}
{\colortbl;\red255\green255\blue255;\red27\green31\blue34;\red10\green77\blue204;\red0\green0\blue0;
\red21\green23\blue26;}
{\*\expandedcolortbl;;\cssrgb\c14118\c16078\c18039;\cssrgb\c1176\c40000\c83922;\csgray\c0\c0;
Expand All @@ -9,7 +9,7 @@
{\list\listtemplateid3\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid201\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid3}
{\list\listtemplateid4\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelfollow0\levelstartat1\levelspace360\levelindent0{\*\levelmarker \{disc\}}{\leveltext\leveltemplateid301\'01\uc0\u8226 ;}{\levelnumbers;}\fi-360\li720\lin720 }{\listname ;}\listid4}}
{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}{\listoverride\listid2\listoverridecount0\ls2}{\listoverride\listid3\listoverridecount0\ls3}{\listoverride\listid4\listoverridecount0\ls4}}
\paperw11900\paperh16840\margl1440\margr1440\vieww17360\viewh22480\viewkind0
\paperw11900\paperh16840\margl1440\margr1440\vieww17360\viewh20980\viewkind0
\deftab720
\pard\pardeftab720\sl360\sa320\partightenfactor0

Expand Down Expand Up @@ -48,7 +48,7 @@ Unless required by applicable law or agreed to in writing, software distributed
\f0\b0 \cf2 This license is used by the following third-party libraries:\
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl360\partightenfactor0
\ls1\ilvl0\cf2 \kerning1\expnd0\expndtw0 {\listtext \uc0\u8226 }\expnd0\expndtw0\kerning0
jansi\
JNA\
\pard\pardeftab720\sl300\partightenfactor0

\f1\b \cf3 \
Expand All @@ -59,7 +59,7 @@ jansi\
\f0\b0 \cf2 This license is used by the following third-party libraries:\
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl360\partightenfactor0
\ls2\ilvl0\cf2 \kerning1\expnd0\expndtw0 {\listtext \uc0\u8226 }\expnd0\expndtw0\kerning0
jline\
JLine 3\
\pard\pardeftab720\sl300\partightenfactor0

\f1\b \cf3 \
Expand All @@ -70,7 +70,7 @@ jline\
\f0\b0 \cf2 This license is used by the following third-party libraries:\
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl360\partightenfactor0
\ls3\ilvl0\cf2 \kerning1\expnd0\expndtw0 {\listtext \uc0\u8226 }\expnd0\expndtw0\kerning0
asm\
ASM\
\pard\pardeftab720\sl300\partightenfactor0

\f1\b \cf3 \
Expand All @@ -81,5 +81,5 @@ asm\
\f0\b0 \cf2 This license is used by the following third-party libraries:\
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl360\partightenfactor0
\ls4\ilvl0\cf2 \kerning1\expnd0\expndtw0 {\listtext \uc0\u8226 }\expnd0\expndtw0\kerning0
jquery\
}
jQuery\
}
@@ -1,4 +1,6 @@
Scala includes the JLine library, which includes the Jansi library.
Scala includes the JLine library, which includes the JNA library,
which is made available under multiple licenses, including the
Apache 2 license:

Apache License
Version 2.0, January 2004
Expand Down
6 changes: 4 additions & 2 deletions doc/licenses/bsd_jline.txt
@@ -1,8 +1,10 @@
Scala includes the JLine library:
Scala includes the JLine 3 library:

Copyright (c) 2002-2006, Marc Prud'hommeaux <mwp1@cornell.edu>
Copyright (c) 2002-2018, the original author or authors.
All rights reserved.

https://opensource.org/licenses/BSD-3-Clause

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
Expand Down
29 changes: 0 additions & 29 deletions doc/licenses/bsd_scalacheck.txt

This file was deleted.

4 changes: 2 additions & 2 deletions project/ScalaOptionParser.scala
Expand Up @@ -83,7 +83,7 @@ object ScalaOptionParser {

// TODO retrieve these 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", "-Xnojline", "-Xprint-pos", "-Xprint-types", "-Xprompt", "-Xresident", "-Xshow-phases", "-Xverify", "-Y",
"-Xno-forwarders", "-Xno-patmat-analysis", "-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
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 @@ -120,7 +120,16 @@ trait ScalaSettings extends StandardScalaSettings with Warnings {
val maxerrs = IntSetting ("-Xmaxerrs", "Maximum errors to print", 100, None, _ => None)
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 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

0 comments on commit bc1cad4

Please sign in to comment.