Add build-level keys to the tab completion

Fixes #2460
Fixes #2851
Ref #2707, #2708, #2469

Unlike the previous attempts at fixing the handling of build-level
keys, this change does not change the main parsing logic, which uses
`getKey` to retrieve the key from the key map.
The fact that shell worked pre-0.13.11 means that the parsing was ok.

What this changes is just the "example" keys supplied to the parser so
the tab completion works.
This commit is contained in:
Eugene Yokota 2016-11-30 02:33:05 -05:00
parent 4ea2a99c3b
commit 569e19d03c
5 changed files with 64 additions and 1 deletions

View File

@ -134,7 +134,16 @@ object Act {
token(ID !!! "Expected key" examples dropHyphenated(keys)) flatMap { keyString =>
getKey(keyMap, keyString, idFun)
}
keyParser(index.keys(proj, conf, task))
// Fixes sbt/sbt#2460 and sbt/sbt#2851
// The parser already accepts build-level keys.
// This queries the key index so tab completion will list the build-level keys.
val buildKeys: Set[String] =
proj match {
case Some(ProjectRef(uri, id)) => index.keys(Some(BuildRef(uri)), conf, task)
case _ => Set()
}
val keys: Set[String] = index.keys(proj, conf, task) ++ buildKeys
keyParser(keys)
}
def getKey[T](keyMap: Map[String, AttributeKey[_]], keyString: String, f: AttributeKey[_] => T): Parser[T] =

View File

@ -0,0 +1,9 @@
### Bug fixes
- Fixes regressions in sbt 0.13.11 - 0.13.13 that processed build-level keys incorrectly. [#2851][2851]/[#2460][2460] by [@eed3si9n]
[#2851]: https://github.com/sbt/sbt/issues/2851
[#2460]: https://github.com/sbt/sbt/issues/2460
[@eed3si9n]: https://github.com/eed3si9n
[@dwijnand]: https://github.com/dwijnand
[@Duhemm]: https://github.com/Duhemm

View File

@ -0,0 +1,29 @@
import complete.{ Completion, Completions, DefaultParsers, Parser }
import DefaultParsers._
import Command.applyEffect
import CommandUtil._
lazy val root = (project in file(".")).
enablePlugins(FooPlugin).
settings(
commands += checkCompletionsCommand
)
// This checks the tab completion lists build-level keys
def checkCompletionsCommand = Command.make("checkCompletions")(completionsParser)
def completionsParser(state: State) =
{
val notQuoted = (NotQuoted ~ any.*) map { case (nq, s) => (nq +: s).mkString }
val quotedOrUnquotedSingleArgument = Space ~> (StringVerbatim | StringEscapable | notQuoted)
applyEffect(token(quotedOrUnquotedSingleArgument ?? "" examples ("", " ")))(runCompletions(state))
}
def runCompletions(state: State)(input: String): State = {
val xs = Parser.completions(state.combinedParser, input, 9).get map {
c => if (c.isEmpty) input else input + c.append
} map { c =>
c.replaceAll("\n", " ")
}
println(xs)
assert(xs == Set("myTask"))
state
}

View File

@ -0,0 +1,15 @@
import sbt._
import syntax._
object FooPlugin extends AutoPlugin {
override def trigger = noTrigger
object autoImport {
val myTask = taskKey[Unit]("My task")
}
import autoImport._
override def buildSettings = super.buildSettings ++ Seq(
myTask := println("Called my task")
)
}

View File

@ -0,0 +1 @@
> checkCompletions my