Skip to content

Commit

Permalink
Merge pull request sbt#6283 from eed3si9n/wip/tab_completion
Browse files Browse the repository at this point in the history
Fix configuration identifier completion
  • Loading branch information
eed3si9n authored Jan 24, 2021
2 parents 151c170 + c5d65fe commit 01b5cb1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
14 changes: 10 additions & 4 deletions main/src/main/scala/sbt/internal/Act.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion main/src/main/scala/sbt/internal/KeyIndex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ 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.
private[sbt] def fromConfigIdent(ident: String): String =
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],
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions main/src/test/scala/testpkg/CompletionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// })
Expand Down

0 comments on commit 01b5cb1

Please sign in to comment.