completions command

The completions command is meant for dump terminals that cannot use
the default tab completion. It has been built for use by the emacs
sbt-mode (see https://github.com/hvesalai/sbt-mode), but is equally
useful for other code editors that can integrate with sbt.
This commit is contained in:
Heikki Vesalainen 2013-11-13 11:47:37 +02:00 committed by Mark Harrah
parent e7d5cd1bd2
commit b2980b913f
3 changed files with 22 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import Path._
object BasicCommandStrings
{
val HelpCommand = "help"
val CompletionsCommand = "completions"
val Exit = "exit"
val Quit = "quit"
@ -32,6 +33,9 @@ object BasicCommandStrings
Searches the help according to the provided regular expression.
"""
def CompletionsDetailed = "Displays a list of completions for the given argument string (run 'completions <string>')."
def CompletionsBrief = (CompletionsCommand, CompletionsDetailed)
def HistoryHelpBrief = (HistoryCommands.Start -> "History command help. Lists and describes all history commands.")
def historyHelp = Help(Nil, (HistoryHelpBrief +: HistoryCommands.descriptions).toMap, Set(HistoryCommands.Start))

View File

@ -15,7 +15,7 @@ package sbt
object BasicCommands
{
lazy val allBasicCommands = Seq(nop, ignore, help, multi, ifLast, append, setOnFailure, clearOnFailure, stashOnFailure, popOnFailure, reboot, call, early, exit, continuous, history, shell, read, alias) ++ compatCommands
lazy val allBasicCommands = Seq(nop, ignore, help, completionsCommand, multi, ifLast, append, setOnFailure, clearOnFailure, stashOnFailure, popOnFailure, reboot, call, early, exit, continuous, history, shell, read, alias) ++ compatCommands
def nop = Command.custom(s => success(() => s))
def ignore = Command.command(FailureWall)(idFun)
@ -43,6 +43,21 @@ object BasicCommands
@deprecated("Use Help.moreMessage", "0.13.0")
def moreHelp(more: Seq[String]): String = Help.moreMessage(more)
def completionsCommand = Command.make(CompletionsCommand, CompletionsBrief, CompletionsDetailed)(completionsParser)
def completionsParser(state: State) =
{
applyEffect(singleArgument(Set.empty).?)(runCompletions(state))
}
def runCompletions(state: State)(input: Option[String]): State = {
val str = input.getOrElse("")
Parser.completions(state.combinedParser, str, 9).get map {
c => if (c.isEmpty) str else str + c.append
} foreach { c =>
System.out.println("[completions] " + c.replaceAll("\n", " "))
}
state
}
def multiParser(s: State): Parser[Seq[String]] =
{
@ -256,4 +271,4 @@ object BasicCommands
}
val CommandAliasKey = AttributeKey[(String,String)]("is-command-alias", "Internal: marker for Commands created as aliases for another command.")
}
}

View File

@ -87,7 +87,7 @@ object BuiltinCommands
def ConsoleCommands: Seq[Command] = Seq(ignore, exit, IvyConsole.command, setLogLevel, early, act, nop)
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, setLogLevel, early, act, nop)
def DefaultCommands: Seq[Command] = Seq(ignore, help, about, tasks, settingsCommand, loadProject,
def DefaultCommands: Seq[Command] = Seq(ignore, help, completionsCommand, about, tasks, settingsCommand, loadProject,
projects, project, reboot, read, history, set, sessionCommand, inspect, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
setOnFailure, clearOnFailure, stashOnFailure, popOnFailure, setLogLevel,
ifLast, multi, shell, continuous, eval, alias, append, last, lastGrep, export, boot, nop, call, exit, early, initialize, act) ++