Merge pull request #6283 from eed3si9n/wip/tab_completion

Fix configuration identifier completion
This commit is contained in:
eugene yokota 2021-01-24 12:32:20 -05:00 committed by GitHub
commit 01b5cb1bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 12 deletions

View File

@ -18,6 +18,7 @@ import java.net.URI
import sbt.internal.CommandStrings.{ MultiTaskCommand, ShowCommand, PrintCommand }
import sbt.internal.util.{ AttributeEntry, AttributeKey, AttributeMap, IMap, Settings, Util }
import sbt.util.Show
import scala.collection.mutable
final class ParsedKey(val key: ScopedKey[_], val mask: ScopeMask)
@ -73,14 +74,19 @@ object Act {
defaultConfigs: Option[ResolvedReference] => Seq[String],
keyMap: Map[String, AttributeKey[_]]
): Parser[Seq[Parser[ParsedKey]]] = {
val confParserCache: mutable.Map[Option[sbt.ResolvedReference], Parser[ParsedAxis[String]]] =
mutable.Map.empty
def fullKey =
for {
rawProject <- optProjectRef(index, current)
proj = resolveProject(rawProject, current)
confAmb <- configIdent(
index configs proj,
index configIdents proj,
index.fromConfigIdent(proj)
confAmb <- confParserCache.getOrElseUpdate(
proj,
configIdent(
index.configs(proj),
index.configIdents(proj),
index.fromConfigIdent(proj)
)
)
partialMask = ScopeMask(rawProject.isExplicit, confAmb.isExplicit, false, false)
} yield taskKeyExtra(index, defaultConfigs, keyMap, proj, confAmb, partialMask)

View File

@ -194,6 +194,7 @@ private[sbt] final class ConfigIndex(
}
def configs: Set[String] = data.keySet
private[sbt] lazy val idents: Set[String] = configIdentToName.keySet
// guess Configuration name from an identifier.
// There's a guessing involved because we could have scoped key that Project is not aware of.
@ -201,6 +202,7 @@ private[sbt] final class ConfigIndex(
configIdentToName.getOrElse(ident, Scope.unguessConfigIdent(ident))
}
private[sbt] object ConfigIndex
private[sbt] final class ProjectIndex(val data: Map[Option[String], ConfigIndex]) {
def add(
id: Option[String],
@ -234,7 +236,7 @@ private[sbt] final class KeyIndex0(val data: BuildIndex) extends ExtendableKeyIn
def configs(project: Option[ResolvedReference]): Set[String] = confIndex(project).configs
private[sbt] def configIdents(project: Option[ResolvedReference]): Set[String] =
confIndex(project).configs
confIndex(project).idents
private[sbt] def fromConfigIdent(proj: Option[ResolvedReference])(configIdent: String): String =
confIndex(proj).fromConfigIdent(configIdent)

View File

@ -28,13 +28,13 @@ object CompletionSpec extends Properties {
property("can complete any project", TestBuild.nonEmptyId.forAll.map { id =>
complete(projectID = id, line = id.head.toString, expected = id)
}),
// property(
// "can complete any configuration",
// TestBuild.nonEmptyId.forAll.map { name =>
// val cap = name.capitalize
// complete(configName = name, line = cap.head.toString, expected = cap)
// }
// ),
property(
"can complete any configuration",
TestBuild.nonEmptyId.forAll.map { name =>
val cap = name.capitalize
complete(configName = name, line = cap.head.toString, expected = cap)
}
),
// property("can complete any attribute", TestBuild.kebabIdGen.forAll.map { name =>
// complete(attributeName = name, line = name.head.toString, expected = name)
// })