Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 71 lines (62 sloc) 2.345 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
/* sbt -- Simple Build Tool
* Copyright 2008, 2009, 2010, 2011 Mark Harrah
*/
package sbt

import ProjectNavigation._
import Project.updateCurrent
import Keys.sessionSettings
import complete.{DefaultParsers, Parser}
import DefaultParsers._
import java.net.URI

object ProjectNavigation
{
def command(s: State): Parser[() => State] =
if(s get sessionSettings isEmpty) failure("No project loaded") else (new ProjectNavigation(s)).command
}
final class ProjectNavigation(s: State)
{
val extracted = Project extract s
import extracted.{currentRef, structure, session}

def setProject(nuri: URI, nid: String) =
{
val neval = if(currentRef.build == nuri) session.currentEval else mkEval(nuri)
updateCurrent(s.put(sessionSettings, session.setCurrent(nuri, nid, neval)))
}
def mkEval(nuri: URI) = Load.lazyEval(structure.units(nuri).unit)
def getRoot(uri: URI) = Load.getRootProject(structure.units)(uri)

def apply(action: Option[ResolvedReference]): State =
action match
{
case None => show(); s
case Some(BuildRef(uri)) => changeBuild(uri)
case Some(ProjectRef(uri, id)) => selectProject(uri, id)
/* else if(to.forall(_ == '.'))
if(to.length > 1) gotoParent(to.length - 1, nav, s) else s */ // semantics currently undefined
}

def show(): Unit = s.log.info(currentRef.project + " (in build " + currentRef.build + ")")
def selectProject(uri: URI, to: String): State =
if( structure.units(uri).defined.contains(to) )
setProject(uri, to)
else
fail("Invalid project name '" + to + "' in build " + uri + " (type 'projects' to list available projects).")

def changeBuild(newBuild: URI): State =
if(structure.units contains newBuild)
setProject(newBuild, getRoot(newBuild))
else
fail("Invalid build unit '" + newBuild + "' (type 'projects' to list available builds).")

def fail(msg: String): State =
{
s.log.error(msg)
s.fail
}

import complete.Parser._
import complete.Parsers._

val parser: Parser[Option[ResolvedReference]] =
{
val reference = Act.resolvedReference(structure.index.keyIndex, currentRef.build, success(()))
val root = token('/' ^^^ rootRef)
success(None) | some( token(Space) ~> (root | reference) )
}
def rootRef = ProjectRef(currentRef.build, getRoot(currentRef.build))
val command: Parser[() => State] = Command.applyEffect(parser)(apply)
}
Something went wrong with that request. Please try again.