Permalink
Browse files

better fix for tab completion on invalid project IDs

  • Loading branch information...
1 parent 113fdba commit 3d0eb1ac11f2c580d7f1fa189a622850dda31219 @harrah committed Jul 1, 2012
Showing with 11 additions and 2 deletions.
  1. +4 −2 main/Act.scala
  2. +7 −0 main/KeyIndex.scala
View
6 main/Act.scala
@@ -120,10 +120,12 @@ object Act
def configs(explicit: ParsedAxis[String], defaultConfigs: Option[ResolvedReference] => Seq[String], proj: Option[ResolvedReference], index: KeyIndex): Seq[Option[String]] =
explicit match
{
- case Omitted => None +: defaultConfigs(proj).flatMap(nonEmptyConfig(index, proj))
+ case Omitted => None +: defaultConfigurations(proj, index, defaultConfigs).flatMap(nonEmptyConfig(index, proj))
case ParsedGlobal => None :: Nil
case pv: ParsedValue[String] => Some(pv.value) :: Nil
}
+ def defaultConfigurations(proj: Option[ResolvedReference], index: KeyIndex, defaultConfigs: Option[ResolvedReference] => Seq[String]): Seq[String] =
+ if(index exists proj) defaultConfigs(proj) else Nil
def nonEmptyConfig(index: KeyIndex, proj: Option[ResolvedReference]): String => Seq[Option[String]] = config =>
if(index.isEmpty(proj, Some(config))) Nil else Some(config) :: Nil
@@ -196,7 +198,7 @@ object Act
}
def resolvedReference(index: KeyIndex, currentBuild: URI, trailing: Parser[_]): Parser[ResolvedReference] =
{
- def projectID(uri: URI) = token( examplesStrict(ID, index projects uri, "project ID") <~ trailing )
+ def projectID(uri: URI) = token( examples(ID, index projects uri, "project ID") <~ trailing )
def projectRef(uri: URI) = projectID(uri) map { id => ProjectRef(uri, id) }
val uris = index.buildURIs
View
7 main/KeyIndex.scala
@@ -20,6 +20,7 @@ object KeyIndex
def combine(indices: Seq[KeyIndex]): KeyIndex = new KeyIndex {
def buildURIs = concat(_.buildURIs)
def projects(uri: URI) = concat(_.projects(uri))
+ def exists(project: Option[ResolvedReference]): Boolean = indices.exists(_ exists project)
def configs(proj: Option[ResolvedReference]) = concat(_.configs(proj))
def tasks(proj: Option[ResolvedReference], conf: Option[String]) = concat(_.tasks(proj, conf))
def tasks(proj: Option[ResolvedReference], conf: Option[String], key: String) = concat(_.tasks(proj, conf, key))
@@ -46,6 +47,7 @@ trait KeyIndex
def buildURIs: Set[URI]
def projects(uri: URI): Set[String]
+ def exists(project: Option[ResolvedReference]): Boolean
def configs(proj: Option[ResolvedReference]): Set[String]
def tasks(proj: Option[ResolvedReference], conf: Option[String]): Set[AttributeKey[_]]
def tasks(proj: Option[ResolvedReference], conf: Option[String], key: String): Set[AttributeKey[_]]
@@ -92,6 +94,11 @@ private final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIndex
{
def buildURIs: Set[URI] = data.builds
def projects(uri: URI): Set[String] = data.projectIndex(Some(uri)).projects
+ def exists(proj: Option[ResolvedReference]): Boolean =
+ {
+ val (build, project) = parts(proj)
+ data.data.get(build).flatMap(_.data.get(project)).isDefined
+ }
def configs(project: Option[ResolvedReference]): Set[String] = confIndex(project).configs
def tasks(proj: Option[ResolvedReference], conf: Option[String]): Set[AttributeKey[_]] = keyIndex(proj, conf).tasks
def tasks(proj: Option[ResolvedReference], conf: Option[String], key: String): Set[AttributeKey[_]] = keyIndex(proj, conf).tasks(key)

0 comments on commit 3d0eb1a

Please sign in to comment.