Skip to content
This repository
Browse code

better fix for tab completion on invalid project IDs

  • Loading branch information...
commit 3d0eb1ac11f2c580d7f1fa189a622850dda31219 1 parent 113fdba
Mark Harrah authored

Showing 2 changed files with 11 additions and 2 deletions. Show diff stats Hide diff stats

  1. +4 2 main/Act.scala
  2. +7 0 main/KeyIndex.scala
6 main/Act.scala
@@ -120,10 +120,12 @@ object Act
120 120 def configs(explicit: ParsedAxis[String], defaultConfigs: Option[ResolvedReference] => Seq[String], proj: Option[ResolvedReference], index: KeyIndex): Seq[Option[String]] =
121 121 explicit match
122 122 {
123   - case Omitted => None +: defaultConfigs(proj).flatMap(nonEmptyConfig(index, proj))
  123 + case Omitted => None +: defaultConfigurations(proj, index, defaultConfigs).flatMap(nonEmptyConfig(index, proj))
124 124 case ParsedGlobal => None :: Nil
125 125 case pv: ParsedValue[String] => Some(pv.value) :: Nil
126 126 }
  127 + def defaultConfigurations(proj: Option[ResolvedReference], index: KeyIndex, defaultConfigs: Option[ResolvedReference] => Seq[String]): Seq[String] =
  128 + if(index exists proj) defaultConfigs(proj) else Nil
127 129 def nonEmptyConfig(index: KeyIndex, proj: Option[ResolvedReference]): String => Seq[Option[String]] = config =>
128 130 if(index.isEmpty(proj, Some(config))) Nil else Some(config) :: Nil
129 131
@@ -196,7 +198,7 @@ object Act
196 198 }
197 199 def resolvedReference(index: KeyIndex, currentBuild: URI, trailing: Parser[_]): Parser[ResolvedReference] =
198 200 {
199   - def projectID(uri: URI) = token( examplesStrict(ID, index projects uri, "project ID") <~ trailing )
  201 + def projectID(uri: URI) = token( examples(ID, index projects uri, "project ID") <~ trailing )
200 202 def projectRef(uri: URI) = projectID(uri) map { id => ProjectRef(uri, id) }
201 203
202 204 val uris = index.buildURIs
7 main/KeyIndex.scala
@@ -20,6 +20,7 @@ object KeyIndex
20 20 def combine(indices: Seq[KeyIndex]): KeyIndex = new KeyIndex {
21 21 def buildURIs = concat(_.buildURIs)
22 22 def projects(uri: URI) = concat(_.projects(uri))
  23 + def exists(project: Option[ResolvedReference]): Boolean = indices.exists(_ exists project)
23 24 def configs(proj: Option[ResolvedReference]) = concat(_.configs(proj))
24 25 def tasks(proj: Option[ResolvedReference], conf: Option[String]) = concat(_.tasks(proj, conf))
25 26 def tasks(proj: Option[ResolvedReference], conf: Option[String], key: String) = concat(_.tasks(proj, conf, key))
@@ -46,6 +47,7 @@ trait KeyIndex
46 47
47 48 def buildURIs: Set[URI]
48 49 def projects(uri: URI): Set[String]
  50 + def exists(project: Option[ResolvedReference]): Boolean
49 51 def configs(proj: Option[ResolvedReference]): Set[String]
50 52 def tasks(proj: Option[ResolvedReference], conf: Option[String]): Set[AttributeKey[_]]
51 53 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
92 94 {
93 95 def buildURIs: Set[URI] = data.builds
94 96 def projects(uri: URI): Set[String] = data.projectIndex(Some(uri)).projects
  97 + def exists(proj: Option[ResolvedReference]): Boolean =
  98 + {
  99 + val (build, project) = parts(proj)
  100 + data.data.get(build).flatMap(_.data.get(project)).isDefined
  101 + }
95 102 def configs(project: Option[ResolvedReference]): Set[String] = confIndex(project).configs
96 103 def tasks(proj: Option[ResolvedReference], conf: Option[String]): Set[AttributeKey[_]] = keyIndex(proj, conf).tasks
97 104 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.
Something went wrong with that request. Please try again.