Skip to content

Commit e3a5f15

Browse files
committed
Add help to choices
1 parent f6345c6 commit e3a5f15

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

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

69+
private def enabledLanguageFeaturesBySetting(using Context): List[String] =
70+
ctx.settings.language.value.asInstanceOf
71+
5472
/** Is `feature` enabled by by a command-line setting? The enabling setting is
5573
*
5674
* -language:<prefix>feature
@@ -59,7 +77,7 @@ object Feature:
5977
* but subtracting the prefix `scala.language.` at the front.
6078
*/
6179
def enabledBySetting(feature: TermName)(using Context): Boolean =
62-
ctx.base.settings.language.value.contains(feature.toString)
80+
enabledLanguageFeaturesBySetting.contains(feature.toString)
6381

6482
/** Is `feature` enabled by by an import? This is the case if the feature
6583
* 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 */
@@ -492,3 +492,4 @@ private sealed trait YSettings:
492492
@deprecated(message = "Scheduled for removal.", since = "3.5.0")
493493
val YoutputOnlyTasty: Setting[Boolean] = BooleanSetting(ForkSetting, "Youtput-only-tasty", "Used to only generate the TASTy file without the classfiles", deprecation = Deprecation.removed())
494494
end YSettings
495+

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)