@@ -5,8 +5,10 @@ import scala.math.Ordering.Implicits.seqOrdering
55/**
66 * Models a path with the Mill build hierarchy, e.g. `amm.util[2.11].test.compile`.
77 *
8- * `.`-separated segments are [[Segment.Label ]]s,
9- * while `[]`-delimited segments are [[Segment.Cross ]]s
8+ * - `.`-separated segments are [[Segment.Label ]]s,
9+ * - `[]`-delimited segments are [[Segment.Cross ]]s
10+ * - If the first segment starts with `./`, it refers to a single-file script
11+ * - If the first segment ends with `/`, it refers to an external module
1012 */
1113final case class Segments private (value : Seq [Segment ]) {
1214
@@ -30,7 +32,7 @@ final case class Segments private (value: Seq[Segment]) {
3032
3133 def render : String = {
3234 def renderCross (cross : Segment .Cross ): String = " [" + cross.value.mkString(" ," ) + " ]"
33- value.toList match {
35+ def renderValue ( valueList : List [ Segment ]) = valueList match {
3436 case Nil => " "
3537 case head :: rest =>
3638 val headSegment = head match
@@ -42,6 +44,15 @@ final case class Segments private (value: Seq[Segment]) {
4244 }
4345 headSegment + stringSegments.mkString
4446 }
47+
48+ value.toList match {
49+ // ScriptModule segments always starts with `./`
50+ case Segment .Label (s " ./ $first" ) :: Nil => s " ./ $first"
51+ case Segment .Label (s " ./ $first" ) :: next :: rest => s " ./ $first: ${renderValue(next :: rest)}"
52+ // ExternalModule segments always ends with '/'
53+ case Segment .Label (s " $first/ " ) :: next :: rest => s " $first/ ${renderValue(next :: rest)}"
54+ case valueList => renderValue(valueList)
55+ }
4556 }
4657 override lazy val hashCode : Int = value.hashCode()
4758}
0 commit comments