mirror of https://github.com/sbt/sbt.git
Add SourcePosition to setting.
This commit is contained in:
parent
b5c4e5290e
commit
c2304b512f
|
|
@ -8,8 +8,9 @@ package sbt
|
|||
import compiler.{Eval, EvalImports}
|
||||
import complete.DefaultParsers.validID
|
||||
import Compiler.Compilers
|
||||
import Project.{ScopedKey, Setting}
|
||||
import Keys.{globalBaseDirectory, globalPluginsDirectory, globalSettingsDirectory, stagingDirectory, Streams}
|
||||
import Project.{ScopedKey, Setting, SourceCoord}
|
||||
import Keys.{globalBaseDirectory, Streams}
|
||||
import Scope.GlobalScope
|
||||
import scala.annotation.tailrec
|
||||
|
||||
|
|
@ -137,7 +138,10 @@ object EvaluateConfigurations
|
|||
} catch {
|
||||
case e: sbt.compiler.EvalException => throw new MessageOnlyException(e.getMessage)
|
||||
}
|
||||
loader => result.getValue(loader).asInstanceOf[Project.SettingsDefinition].settings
|
||||
loader => {
|
||||
val coord = SourceCoord(name, line + 1)
|
||||
result.getValue(loader).asInstanceOf[Project.SettingsDefinition].settings map (_ setPos coord)
|
||||
}
|
||||
}
|
||||
private[this] def isSpace = (c: Char) => Character isWhitespace c
|
||||
private[this] def fstS(f: String => Boolean): ((String,Int)) => Boolean = { case (s,i) => f(s) }
|
||||
|
|
|
|||
|
|
@ -267,20 +267,34 @@ object Project extends Init[Scope] with ProjectExtra
|
|||
|
||||
val data = scopedKeyData(structure, scope, key) map {_.description} getOrElse {"No entry for key."}
|
||||
val description = key.description match { case Some(desc) => "Description:\n\t" + desc + "\n"; case None => "" }
|
||||
val definedIn = structure.data.definingScope(scope, key) match {
|
||||
|
||||
val providedBy = structure.data.definingScope(scope, key) match {
|
||||
case Some(sc) => "Provided by:\n\t" + Scope.display(sc, key.label) + "\n"
|
||||
case None => ""
|
||||
}
|
||||
val cMap = flattenLocals(compiled(structure.settings, actual)(structure.delegates, structure.scopeLocal, display))
|
||||
val comp = compiled(structure.settings, actual)(structure.delegates, structure.scopeLocal, display)
|
||||
val definedAt = comp get scoped map { c =>
|
||||
if (c.settings forall (_.pos ne NoPosition)) {
|
||||
def fmt(s: Setting[_]) = s.pos match {
|
||||
case SourceCoord(fileName, line) => fileName + ":" + line
|
||||
}
|
||||
"Defined at:" + (c.settings map fmt mkString ("\n\t", "\n\t", "\n"))
|
||||
} else ""
|
||||
} getOrElse ""
|
||||
|
||||
|
||||
val cMap = flattenLocals(comp)
|
||||
val related = cMap.keys.filter(k => k.key == key && k.scope != scope)
|
||||
val depends = cMap.get(scoped) match { case Some(c) => c.dependencies.toSet; case None => Set.empty }
|
||||
|
||||
val reverse = reverseDependencies(cMap, scoped)
|
||||
def printScopes(label: String, scopes: Iterable[ScopedKey[_]]) =
|
||||
if(scopes.isEmpty) "" else scopes.map(display.apply).mkString(label + ":\n\t", "\n\t", "\n")
|
||||
|
||||
data + "\n" +
|
||||
description +
|
||||
definedIn +
|
||||
providedBy +
|
||||
definedAt +
|
||||
printScopes("Dependencies", depends) +
|
||||
printScopes("Reverse dependencies", reverse) +
|
||||
printScopes("Delegates", delegates(structure, scope, key)) +
|
||||
|
|
@ -332,7 +346,7 @@ object Project extends Init[Scope] with ProjectExtra
|
|||
{
|
||||
val akey = setting.key.key
|
||||
val global = ScopedKey(Global, akey)
|
||||
val globalSetting = resolve( Project.setting(global, setting.init) )
|
||||
val globalSetting = resolve( Project.setting(global, setting.init, setting.pos) )
|
||||
globalSetting ++ allDefs.flatMap { d =>
|
||||
if(d.key == akey)
|
||||
Seq( SettingKey(akey) in d.scope <<= global)
|
||||
|
|
|
|||
|
|
@ -58,10 +58,10 @@ trait Init[Scope]
|
|||
type ScopeLocal = ScopedKey[_] => Seq[Setting[_]]
|
||||
type MapConstant = ScopedKey ~> Option
|
||||
|
||||
def setting[T](key: ScopedKey[T], init: Initialize[T]): Setting[T] = new Setting[T](key, init)
|
||||
def setting[T](key: ScopedKey[T], init: Initialize[T], pos: SourcePosition = NoPosition): Setting[T] = new Setting[T](key, init, pos)
|
||||
def value[T](value: => T): Initialize[T] = new Value(value _)
|
||||
def optional[T,U](i: Initialize[T])(f: Option[T] => U): Initialize[U] = new Optional(Some(i), f)
|
||||
def update[T](key: ScopedKey[T])(f: T => T): Setting[T] = new Setting[T](key, app(key :^: KNil)(hl => f(hl.head)))
|
||||
def update[T](key: ScopedKey[T])(f: T => T): Setting[T] = new Setting[T](key, app(key :^: KNil)(hl => f(hl.head)), NoPosition)
|
||||
def bind[S,T](in: Initialize[S])(f: S => Initialize[T]): Initialize[T] = new Bind(f, in)
|
||||
def app[HL <: HList, T](inputs: KList[Initialize, HL])(f: HL => T): Initialize[T] = new Apply(f, inputs)
|
||||
def uniform[S,T](inputs: Seq[Initialize[S]])(f: Seq[S] => T): Initialize[T] = new Uniform(f, inputs)
|
||||
|
|
@ -245,19 +245,32 @@ trait Init[Scope]
|
|||
def settings: Seq[Setting[_]]
|
||||
}
|
||||
final class SettingList(val settings: Seq[Setting[_]]) extends SettingsDefinition
|
||||
final class Setting[T](val key: ScopedKey[T], val init: Initialize[T]) extends SettingsDefinition
|
||||
final class Setting[T](val key: ScopedKey[T], val init: Initialize[T], val pos: SourcePosition) extends SettingsDefinition
|
||||
{
|
||||
def settings = this :: Nil
|
||||
def definitive: Boolean = !init.dependencies.contains(key)
|
||||
def dependencies: Seq[ScopedKey[_]] = remove(init.dependencies, key)
|
||||
def mapReferenced(g: MapScoped): Setting[T] = new Setting(key, init mapReferenced g)
|
||||
def validateReferenced(g: ValidateRef): Either[Seq[Undefined], Setting[T]] = (init validateReferenced g).right.map(newI => new Setting(key, newI))
|
||||
def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init)
|
||||
def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t)))
|
||||
def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g)
|
||||
override def toString = "setting(" + key + ")"
|
||||
def mapReferenced(g: MapScoped): Setting[T] = new Setting(key, init mapReferenced g, pos)
|
||||
def validateReferenced(g: ValidateRef): Either[Seq[Undefined], Setting[T]] = (init validateReferenced g).right.map(newI => new Setting(key, newI, pos))
|
||||
def mapKey(g: MapScoped): Setting[T] = new Setting(g(key), init, pos)
|
||||
def mapInit(f: (ScopedKey[T], T) => T): Setting[T] = new Setting(key, init(t => f(key,t)), pos)
|
||||
def mapConstant(g: MapConstant): Setting[T] = new Setting(key, init mapConstant g, pos)
|
||||
def setPos(pos: SourceCoord) = new Setting(key, init, pos)
|
||||
override def toString = "setting(" + key + ") at " + pos
|
||||
}
|
||||
|
||||
trait SourcePosition {
|
||||
def fileName: String
|
||||
def line: Int
|
||||
}
|
||||
|
||||
case object NoPosition extends SourcePosition {
|
||||
override def fileName = throw new UnsupportedOperationException("NoPosition")
|
||||
override def line = throw new UnsupportedOperationException("NoPosition")
|
||||
}
|
||||
|
||||
case class SourceCoord(fileName: String, line: Int) extends SourcePosition
|
||||
|
||||
// mainly for reducing generated class count
|
||||
private[this] def validateReferencedT(g: ValidateRef) =
|
||||
new (Initialize ~> ValidatedInit) { def apply[T](i: Initialize[T]) = i validateReferenced g }
|
||||
|
|
|
|||
Loading…
Reference in New Issue