Skip to content

Commit 2af448e

Browse files
committed
Add help to choices
1 parent 3d3d2ab commit 2af448e

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SourceVersion.*
1111
import reporting.Message
1212
import NameKinds.QualifiedName
1313
import Annotations.ExperimentalAnnotation
14+
import Settings.Setting.ChoiceWithHelp
1415

1516
object Feature:
1617

@@ -38,16 +39,33 @@ object Feature:
3839
defn.languageExperimentalFeatures
3940
.map(sym => experimental(sym.name))
4041
.filterNot(_ == captureChecking) // TODO is this correct?
41-
42+
4243
val values = List(
43-
nme.help,
44-
nme.noAutoTupling, nme.dynamics, nme.unsafeNulls, nme.postfixOps, nme.strictEquality,
45-
nme.implicitConversions, nme.adhocExtensions,
46-
namedTypeArguments, genericNumberLiterals, scala2macros,
47-
dependent, erasedDefinitions, symbolLiterals, fewerBraces, saferExceptions,
48-
clauseInterleaving, pureFunctions, captureChecking, into
44+
(nme.help, "Display all available features"),
45+
(nme.noAutoTupling, "Disable automatic tupling"),
46+
(nme.dynamics, "Allow direct or indirect subclasses of scala.Dynamic"),
47+
(nme.unsafeNulls, "Enable unsafe nulls for explicit nulls"),
48+
(nme.postfixOps, "Allow postfix operator notation"),
49+
(nme.strictEquality, "Enable strict equality (=== and !==)"),
50+
(nme.implicitConversions, "Allow implicit conversions without warnings"),
51+
(nme.adhocExtensions, "Allow ad-hoc extension methods"),
52+
(namedTypeArguments, "Allow named type arguments"),
53+
(genericNumberLiterals, "Allow generic number literals"),
54+
(scala2macros, "Allow Scala 2 macros"),
55+
(dependent, "Allow dependent method types"),
56+
(erasedDefinitions, "Allow erased definitions"),
57+
(symbolLiterals, "Allow symbol literals"),
58+
(fewerBraces, "Allow fewer braces"),
59+
(saferExceptions, "Enable safer exceptions"),
60+
(clauseInterleaving, "Enable clause interleaving"),
61+
(pureFunctions, "Enable pure functions"),
62+
(captureChecking, "Enable experimental capture checking"),
63+
(into, "Allow into clauses in pattern matches")
4964
)
5065

66+
private def enabledLanguageFeaturesBySetting(using Context): List[String] =
67+
ctx.settings.language.value.asInstanceOf
68+
5169
/** Is `feature` enabled by by a command-line setting? The enabling setting is
5270
*
5371
* -language:<prefix>feature
@@ -56,7 +74,7 @@ object Feature:
5674
* but subtracting the prefix `scala.language.` at the front.
5775
*/
5876
def enabledBySetting(feature: TermName)(using Context): Boolean =
59-
ctx.base.settings.language.value.contains(feature.toString)
77+
enabledLanguageFeaturesBySetting.contains(feature.toString)
6078

6179
/** Is `feature` enabled by by an import? This is the case if the feature
6280
* is imported by a named import

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ trait CommonScalaSettings:
114114
val explainTypes: Setting[Boolean] = BooleanSetting(RootSetting, "explain-types", "Explain type errors in more detail (deprecated, use -explain instead).", aliases = List("--explain-types", "-explaintypes"))
115115
val explainCyclic: Setting[Boolean] = BooleanSetting(RootSetting, "explain-cyclic", "Explain cyclic reference errors in more detail.", aliases = List("--explain-cyclic"))
116116
val unchecked: Setting[Boolean] = BooleanSetting(RootSetting, "unchecked", "Enable additional warnings where generated code depends on assumptions.", initialValue = true, aliases = List("--unchecked"))
117-
val language: Setting[List[String]] = MultiChoiceSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, aliases = List("--language"))
117+
val language: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, default = Nil, aliases = List("--language"))
118118
val experimental: Setting[Boolean] = BooleanSetting(RootSetting, "experimental", "Annotate all top-level definitions with @experimental. This enables the use of experimental features anywhere in the project.")
119119

120120
/* Coverage settings */
@@ -451,3 +451,4 @@ private sealed trait YSettings:
451451
val YearlyTastyOutput: Setting[AbstractFile] = OutputSetting(ForkSetting, "Yearly-tasty-output", "directory|jar", "Destination to write generated .tasty files to for use in pipelined compilation.", NoAbstractFile, aliases = List("-Ypickle-write"), preferPrevious = true)
452452
val YallowOutlineFromTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Yallow-outline-from-tasty", "Allow outline TASTy to be loaded with the -from-tasty option.")
453453
end YSettings
454+

compiler/src/dotty/tools/dotc/config/ScalaSettingsProperties.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dotty.tools.dotc
22
package config
33

4+
import Settings.Setting.ChoiceWithHelp
45
import dotty.tools.backend.jvm.BackendUtils.classfileVersionMap
56
import dotty.tools.io.{AbstractFile, Directory, JDK9Reflectors, PlainDirectory, NoAbstractFile}
67
import scala.language.unsafeNulls
@@ -26,8 +27,8 @@ object ScalaSettingsProperties:
2627
def supportedSourceVersions: List[String] =
2728
SourceVersion.values.toList.map(_.toString)
2829

29-
def supportedLanguageFeatures: List[String] =
30-
Feature.values.toList.map(_.toString)
30+
def supportedLanguageFeatures: List[ChoiceWithHelp[String]] =
31+
Feature.values.map((n, d) => ChoiceWithHelp(n.toString, d))
3132

3233
def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")
3334

0 commit comments

Comments
 (0)