Skip to content

Commit 950be93

Browse files
committed
List matching commands when given ambiguous command prefix
1 parent fda3dd6 commit 950be93

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

compiler/src/dotty/tools/repl/ParseResult.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ sealed trait Command extends ParseResult
4242
case class UnknownCommand(cmd: String) extends Command
4343

4444
/** An ambiguous prefix that matches multiple commands */
45-
case class AmbiguousCommand(cmd: String) extends Command
45+
case class AmbiguousCommand(cmd: String, matchingCommands: List[String]) extends Command
4646

4747
/** `:load <path>` interprets a scala file as if entered line-by-line into
4848
* the REPL
@@ -134,13 +134,11 @@ object ParseResult {
134134
sourceCode match {
135135
case "" => Newline
136136
case CommandExtract(cmd, arg) => {
137-
val matchingParsers = commands.collect {
138-
case (command, f) if command.startsWith(cmd) => f
139-
}
140-
matchingParsers match {
137+
val matchingCommands = commands.filter((command, _) => command.startsWith(cmd))
138+
matchingCommands match {
141139
case Nil => UnknownCommand(cmd)
142-
case f :: Nil => f(arg)
143-
case _ => AmbiguousCommand(cmd)
140+
case (_, f) :: Nil => f(arg)
141+
case multiple => AmbiguousCommand(cmd, multiple.map(_._1))
144142
}
145143
}
146144
case _ =>

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ class ReplDriver(settings: Array[String],
329329
out.println(s"""Unknown command: "$cmd", run ":help" for a list of commands""")
330330
state
331331

332-
case AmbiguousCommand(cmd) =>
333-
out.println(s""""$cmd" matches more than one command. Try typing a few more characters. Run ":help" for a list of commands""")
332+
case AmbiguousCommand(cmd, matching) =>
333+
out.println(s""""$cmd" matches ${matching.mkString(", ")}. Try typing a few more characters. Run ":help" for a list of commands""")
334334
state
335335

336336
case Help =>

0 commit comments

Comments
 (0)