Skip to content

Commit f6345c6

Browse files
committed
Enhance help message for language flag
1 parent 4dffcc9 commit f6345c6

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ trait CliCommand:
5353
end distill
5454

5555
/** Creates a help message for a subset of options based on cond */
56-
protected def availableOptionsMsg(p: Setting[?] => Boolean)(using settings: ConcreteSettings)(using SettingsState): String =
56+
protected def availableOptionsMsg(p: Setting[?] => Boolean, showArgFileMsg: Boolean = true)(using settings: ConcreteSettings)(using SettingsState): String =
5757
// result is (Option Name, descrption\ndefault: value\nchoices: x, y, z
5858
def help(s: Setting[?]): (String, String) =
5959
// For now, skip the default values that do not make sense for the end user, such as 'false' for the version command.
@@ -68,7 +68,10 @@ trait CliCommand:
6868
val ss = settings.allSettings.filter(p).toList.sortBy(_.name)
6969
val formatter = Columnator("", "", maxField = 30)
7070
val fresh = ContextBase().initialCtx.fresh.setSettings(summon[SettingsState])
71-
formatter(List(ss.map(help) :+ ("@<file>", "A text file containing compiler arguments (options and source files).")))(using fresh)
71+
var msg = ss.map(help)
72+
if showArgFileMsg then
73+
msg = msg :+ ("@<file>", "A text file containing compiler arguments (options and source files).")
74+
formatter(List(msg))(using fresh)
7275
end availableOptionsMsg
7376

7477
protected def shortUsage: String = s"Usage: $cmdName <options> <source files>"

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class CompilerCommand extends CliCommand:
99

1010
final def helpMsg(using settings: ConcreteSettings)(using SettingsState, Context): String =
1111
settings.allSettings.find(isHelping) match
12-
case Some(s) => s.description
12+
case Some(s) => availableOptionsMsg(_ == s, showArgFileMsg = false)
1313
case _ =>
1414
if (settings.help.value) usageMessage
1515
else if (settings.Vhelp.value) vusageMessage

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

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ object Feature:
4141
defn.languageExperimentalFeatures
4242
.map(sym => experimental(sym.name))
4343
.filterNot(_ == captureChecking) // TODO is this correct?
44+
45+
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
52+
)
4453

4554
/** Is `feature` enabled by by a command-line setting? The enabling setting is
4655
*

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

+1-1
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]] = MultiStringSetting(RootSetting, "language", "feature", "Enable one or more language features.", aliases = List("--language"))
117+
val language: Setting[List[String]] = MultiChoiceSetting(RootSetting, "language", "feature", "Enable one or more language features.", choices = ScalaSettingsProperties.supportedLanguageFeatures, 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 */

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

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ object ScalaSettingsProperties:
2626
def supportedSourceVersions: List[String] =
2727
SourceVersion.values.toList.map(_.toString)
2828

29+
def supportedLanguageFeatures: List[String] =
30+
Feature.values.toList.map(_.toString)
31+
2932
def defaultClasspath: String = sys.env.getOrElse("CLASSPATH", ".")
3033

3134
def defaultPageWidth: Int = {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ object Settings:
380380
def ChoiceSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[String], default: String, aliases: List[String] = Nil, legacyArgs: Boolean = false, deprecation: Option[Deprecation] = None): Setting[String] =
381381
publish(Setting(category, prependName(name), descr, default, helpArg, Some(choices), aliases = aliases, legacyArgs = legacyArgs, deprecation = deprecation))
382382

383-
def MultiChoiceSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[String], default: List[String], aliases: List[String] = Nil, deprecation: Option[Deprecation] = None): Setting[List[String]] =
383+
def MultiChoiceSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[String], default: List[String] = Nil, aliases: List[String] = Nil, deprecation: Option[Deprecation] = None): Setting[List[String]] =
384384
publish(Setting(category, prependName(name), descr, default, helpArg, Some(choices), aliases = aliases, deprecation = deprecation))
385385

386386
def MultiChoiceHelpSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[ChoiceWithHelp[String]], default: List[ChoiceWithHelp[String]], aliases: List[String] = Nil, deprecation: Option[Deprecation] = None): Setting[List[ChoiceWithHelp[String]]] =

compiler/src/dotty/tools/dotc/core/StdNames.scala

+1
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ object StdNames {
509509
val _hashCode_ : N = "_hashCode"
510510
val hash_ : N = "hash"
511511
val head: N = "head"
512+
val help: N = "help"
512513
val higherKinds: N = "higherKinds"
513514
val idx: N = "idx"
514515
val identity: N = "identity"

0 commit comments

Comments
 (0)