Skip to content

Instantly share code, notes, and snippets.

@gseitz
Created July 18, 2012 08:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gseitz/3135121 to your computer and use it in GitHub Desktop.
Save gseitz/3135121 to your computer and use it in GitHub Desktop.
SBT command for extracting completions
package sbtcomplete
import sbt._
import complete.JLineCompletion
import Keys._
object SbtComplete {
private val CompletionsCommand = "completions"
private val CompletionsBrief = ("<arg>", "The string to complete.")
private val CompletionsDetailed = "Displays completions for the specified string. The first (possibly empty) line denotes the common prefix of all results."
private def completions = Command.single(CompletionsCommand, CompletionsBrief, CompletionsDetailed) { case (s: State, source) =>
import JLineCompletion._
lazy val completor = parserAsCompletor(s.combinedParser)
val (insert, display) = completor(source, 0)
val common = commonPrefix(insert)
println(common)
display.foreach(println)
s
}
lazy val settings = Seq[Setting[_]](
commands += completions
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment