Skip to content

Commit 3d3d2ab

Browse files
committed
Enhance help message for language flag
1 parent cb554eb commit 3d3d2ab

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

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

Lines changed: 5 additions & 2 deletions
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.
@@ -67,7 +67,10 @@ trait CliCommand:
6767
val ss = settings.allSettings.filter(p).toList.sortBy(_.name)
6868
val formatter = Columnator("", "", maxField = 30)
6969
val fresh = ContextBase().initialCtx.fresh.setSettings(summon[SettingsState])
70-
formatter(List(ss.map(help) :+ ("@<file>", "A text file containing compiler arguments (options and source files).")))(using fresh)
70+
var msg = ss.map(help)
71+
if showArgFileMsg then
72+
msg = msg :+ ("@<file>", "A text file containing compiler arguments (options and source files).")
73+
formatter(List(msg))(using fresh)
7174
end availableOptionsMsg
7275

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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ object Feature:
3838
defn.languageExperimentalFeatures
3939
.map(sym => experimental(sym.name))
4040
.filterNot(_ == captureChecking) // TODO is this correct?
41+
42+
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
49+
)
4150

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

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

Lines changed: 1 addition & 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]] = 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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ object Settings:
352352
def ChoiceSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[String], default: String, aliases: List[String] = Nil, legacyArgs: Boolean = false): Setting[String] =
353353
publish(Setting(category, prependName(name), descr, default, helpArg, Some(choices), aliases = aliases, legacyArgs = legacyArgs))
354354

355-
def MultiChoiceSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[String], default: List[String], aliases: List[String] = Nil): Setting[List[String]] =
355+
def MultiChoiceSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[String], default: List[String] = Nil, aliases: List[String] = Nil): Setting[List[String]] =
356356
publish(Setting(category, prependName(name), descr, default, helpArg, Some(choices), aliases = aliases))
357357

358358
def MultiChoiceHelpSetting(category: SettingCategory, name: String, helpArg: String, descr: String, choices: List[ChoiceWithHelp[String]], default: List[ChoiceWithHelp[String]], aliases: List[String] = Nil): Setting[List[ChoiceWithHelp[String]]] =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ object StdNames {
502502
val _hashCode_ : N = "_hashCode"
503503
val hash_ : N = "hash"
504504
val head: N = "head"
505+
val help: N = "help"
505506
val higherKinds: N = "higherKinds"
506507
val idx: N = "idx"
507508
val identity: N = "identity"

0 commit comments

Comments
 (0)