That were spread over multiple lines since switching to scalafmt
This commit is contained in:
parent
9a19a73f9a
commit
cc1138523e
1 changed files with 20 additions and 6 deletions
|
|
@ -13,6 +13,7 @@ import org.pegdown.ast._
|
||||||
import sbt.Keys._
|
import sbt.Keys._
|
||||||
import sbt._
|
import sbt._
|
||||||
|
|
||||||
|
import scala.annotation.tailrec
|
||||||
import scala.io.{Codec, Source}
|
import scala.io.{Codec, Source}
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
|
|
@ -52,9 +53,9 @@ object ParadoxSupport {
|
||||||
} else new File(page.file.getParentFile, source)
|
} else new File(page.file.getParentFile, source)
|
||||||
|
|
||||||
val Signature = """\s*((def|val|type) (\w+)(?=[:(\[]).*)(\s+\=.*)""".r // stupid approximation to match a signature
|
val Signature = """\s*((def|val|type) (\w+)(?=[:(\[]).*)(\s+\=.*)""".r // stupid approximation to match a signature
|
||||||
//println(s"Looking for signature regex '$Signature'")
|
|
||||||
val text =
|
val text =
|
||||||
Source.fromFile(file)(Codec.UTF8).getLines.collect {
|
getDefs(file).collect {
|
||||||
case line@Signature(signature, kind, l, definition) if labels contains l.replaceAll("Mat$", "").toLowerCase() =>
|
case line@Signature(signature, kind, l, definition) if labels contains l.replaceAll("Mat$", "").toLowerCase() =>
|
||||||
//println(s"Found label '$l' with sig '$full' in line $line")
|
//println(s"Found label '$l' with sig '$full' in line $line")
|
||||||
if (kind == "type") signature + definition
|
if (kind == "type") signature + definition
|
||||||
|
|
@ -62,11 +63,9 @@ object ParadoxSupport {
|
||||||
}.mkString("\n")
|
}.mkString("\n")
|
||||||
|
|
||||||
if (text.trim.isEmpty) {
|
if (text.trim.isEmpty) {
|
||||||
logWarn(
|
throw new IllegalArgumentException(
|
||||||
s"Did not find any signatures with one of those names [${labels.mkString(", ")}] in ${node.source} " +
|
s"Did not find any signatures with one of those names [${labels.mkString(", ")}] in $source " +
|
||||||
s"(was referenced from [${page.path}])")
|
s"(was referenced from [${page.path}])")
|
||||||
|
|
||||||
new HtmlBlockNode(s"""<div style="color: red;">[Broken signature inclusion [${labels.mkString(", ")}] to [${node.source}]</div>""").accept(visitor)
|
|
||||||
} else {
|
} else {
|
||||||
val lang = Option(node.attributes.value("type")).getOrElse(Snippet.language(file))
|
val lang = Option(node.attributes.value("type")).getOrElse(Snippet.language(file))
|
||||||
new VerbatimNode(text, lang).accept(visitor)
|
new VerbatimNode(text, lang).accept(visitor)
|
||||||
|
|
@ -77,4 +76,19 @@ object ParadoxSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getDefs(file: File): Seq[String] = {
|
||||||
|
val Indented = "(\\s*)(.*)".r
|
||||||
|
|
||||||
|
@tailrec
|
||||||
|
def rec(lines: Iterator[String], currentDef: Option[String], defIndent: Integer, soFar: Seq[String]): Seq[String] = {
|
||||||
|
if (!lines.hasNext) soFar ++ currentDef
|
||||||
|
else lines.next() match {
|
||||||
|
case Indented(indent, line) =>
|
||||||
|
if (line.startsWith("def")) rec(lines, Some(line), indent.length, soFar ++ currentDef)
|
||||||
|
else if (indent.length == defIndent + 4) rec(lines, currentDef.map(_ ++ line), defIndent, soFar)
|
||||||
|
else rec(lines, None, 0, soFar ++ currentDef)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rec(Source.fromFile(file)(Codec.UTF8).getLines, None, 0, Nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue