mirror of
https://github.com/sbt/sbt.git
synced 2026-08-22 14:17:13 +02:00
show definitions and uses of a key (not a full scoped key, just a key)
This commit is contained in:
+4
-1
@@ -146,7 +146,10 @@ sealed trait InspectOption
|
|||||||
object InspectOption
|
object InspectOption
|
||||||
{
|
{
|
||||||
final case class Details(actual: Boolean) extends InspectOption
|
final case class Details(actual: Boolean) extends InspectOption
|
||||||
case object DependencyTree extends InspectOption
|
private[this] final class Opt(override val toString: String) extends InspectOption
|
||||||
|
val DependencyTree: InspectOption = new Opt("tree")
|
||||||
|
val Uses: InspectOption = new Opt("inspect")
|
||||||
|
val Definitions: InspectOption = new Opt("definitions")
|
||||||
}
|
}
|
||||||
|
|
||||||
trait Help
|
trait Help
|
||||||
|
|||||||
+33
-13
@@ -395,16 +395,26 @@ object BuiltinCommands
|
|||||||
val newSession = session.appendSettings( append map (a => (a, arg)))
|
val newSession = session.appendSettings( append map (a => (a, arg)))
|
||||||
reapply(newSession, structure, s)
|
reapply(newSession, structure, s)
|
||||||
}
|
}
|
||||||
def inspect = Command(InspectCommand, inspectBrief, inspectDetailed)(inspectParser) {
|
def inspect = Command(InspectCommand, inspectBrief, inspectDetailed)(inspectParser) { case (s, (option, sk)) =>
|
||||||
case (s, (InspectOption.DependencyTree, sk)) =>
|
logger(s).info(inspectOutput(s, option, sk))
|
||||||
val basedir = new File(Project.session(s).current.build)
|
s
|
||||||
val treeString = Project.settingGraph(Project.structure(s), basedir, sk)( Project.showContextKey(s) ).dependsAscii
|
}
|
||||||
logger(s).info(treeString)
|
def inspectOutput(s: State, option: InspectOption, sk: Project.ScopedKey[_]): String =
|
||||||
s
|
{
|
||||||
case (s, (InspectOption.Details(actual), sk)) =>
|
val extracted = Project.extract(s)
|
||||||
val detailString = Project.details(Project.structure(s), actual, sk.scope, sk.key)( Project.showContextKey(s) )
|
import extracted._
|
||||||
logger(s).info(detailString)
|
option match
|
||||||
s
|
{
|
||||||
|
case InspectOption.Details(actual) =>
|
||||||
|
Project.details(structure, actual, sk.scope, sk.key)
|
||||||
|
case InspectOption.DependencyTree =>
|
||||||
|
val basedir = new File(Project.session(s).current.build)
|
||||||
|
Project.settingGraph(structure, basedir, sk).dependsAscii
|
||||||
|
case InspectOption.Uses =>
|
||||||
|
Project.showUses(Project.usedBy(structure, true, sk.key))
|
||||||
|
case InspectOption.Definitions =>
|
||||||
|
Project.showDefinitions(sk.key, Project.definitions(structure, true, sk.key))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
def lastGrep = Command(LastGrepCommand, lastGrepBrief, lastGrepDetailed)(lastGrepParser) {
|
def lastGrep = Command(LastGrepCommand, lastGrepBrief, lastGrepDetailed)(lastGrepParser) {
|
||||||
case (s, (pattern,Some(sk))) =>
|
case (s, (pattern,Some(sk))) =>
|
||||||
@@ -420,12 +430,22 @@ object BuiltinCommands
|
|||||||
val ext = Project.extract(s)
|
val ext = Project.extract(s)
|
||||||
(ext.structure, Select(ext.currentRef), ext.showKey)
|
(ext.structure, Select(ext.currentRef), ext.showKey)
|
||||||
}
|
}
|
||||||
def inspectParser = (s: State) => spacedInspectOptionParser(s) ~ spacedKeyParser(s)
|
|
||||||
val spacedInspectOptionParser: (State => Parser[InspectOption]) = (s: State) => {
|
|
||||||
import InspectOption._
|
import InspectOption._
|
||||||
|
def inspectParser = (s: State) => spacedInspectOptionParser(s) flatMap {
|
||||||
|
case opt @ (Uses | Definitions) => allKeyParser(s).map(key => (opt, Project.ScopedKey(Global, key)))
|
||||||
|
case opt @ (DependencyTree | Details(_)) => spacedKeyParser(s).map(key => (opt, key))
|
||||||
|
}
|
||||||
|
val spacedInspectOptionParser: (State => Parser[InspectOption]) = (s: State) => {
|
||||||
val actual = "actual" ^^^ Details(true)
|
val actual = "actual" ^^^ Details(true)
|
||||||
val tree = "tree" ^^^ DependencyTree
|
val tree = "tree" ^^^ DependencyTree
|
||||||
token(Space ~> (tree | actual)) ?? Details(false)
|
val uses = "uses" ^^^ Uses
|
||||||
|
val definitions = "definitions" ^^^ Definitions
|
||||||
|
token(Space ~> (tree | actual | uses | definitions)) ?? Details(false)
|
||||||
|
}
|
||||||
|
def allKeyParser(s: State): Parser[AttributeKey[_]] =
|
||||||
|
{
|
||||||
|
val keyMap = Project.structure(s).index.keyMap
|
||||||
|
token((Space ~> ID) !!! "Expected key" examples keyMap.keySet) flatMap { key => Act.getKey(keyMap, key, idFun) }
|
||||||
}
|
}
|
||||||
val spacedKeyParser = (s: State) => Act.requireSession(s, token(Space) ~> Act.scopedKeyParser(s))
|
val spacedKeyParser = (s: State) => Act.requireSession(s, token(Space) ~> Act.scopedKeyParser(s))
|
||||||
val optSpacedKeyParser = (s: State) => spacedKeyParser(s).?
|
val optSpacedKeyParser = (s: State) => spacedKeyParser(s).?
|
||||||
|
|||||||
@@ -303,6 +303,17 @@ object Project extends Init[Scope] with ProjectExtra
|
|||||||
r + (key, value.dependencies)
|
r + (key, value.dependencies)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def showDefinitions(key: AttributeKey[_], defs: Seq[Scope])(implicit display: Show[ScopedKey[_]]): String =
|
||||||
|
defs.map(scope => display(ScopedKey(scope, key))).sorted.mkString("\n\t", "\n\t", "\n\n")
|
||||||
|
def showUses(defs: Seq[ScopedKey[_]])(implicit display: Show[ScopedKey[_]]): String =
|
||||||
|
defs.map(display.apply).sorted.mkString("\n\t", "\n\t", "\n\n")
|
||||||
|
|
||||||
|
def definitions(structure: BuildStructure, actual: Boolean, key: AttributeKey[_])(implicit display: Show[ScopedKey[_]]): Seq[Scope] =
|
||||||
|
relation(structure, actual)(display)._1s.toSeq flatMap { sk => if(sk.key == key) sk.scope :: Nil else Nil }
|
||||||
|
def usedBy(structure: BuildStructure, actual: Boolean, key: AttributeKey[_])(implicit display: Show[ScopedKey[_]]): Seq[ScopedKey[_]] =
|
||||||
|
relation(structure, actual)(display).all.toSeq flatMap { case (a,b) => if(b.key == key) List[ScopedKey[_]](a) else Nil }
|
||||||
|
|
||||||
def reverseDependencies(cMap: Map[ScopedKey[_],Flattened], scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =
|
def reverseDependencies(cMap: Map[ScopedKey[_],Flattened], scoped: ScopedKey[_]): Iterable[ScopedKey[_]] =
|
||||||
for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key
|
for( (key,compiled) <- cMap; dep <- compiled.dependencies if dep == scoped) yield key
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user