Skip to content

Commit 5e7e205

Browse files
committed
Avoid re-parse and change errors messages
1 parent 49d3c62 commit 5e7e205

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

scaladoc/src/dotty/tools/scaladoc/site/SidebarParser.scala

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ object Sidebar:
3232

3333
private object RawInputTypeRef extends TypeReference[RawInput]
3434

35-
private def pageWithNoTitle(content: String | java.io.File): String =
36-
val fileContent = content match {
37-
case file: java.io.File => Source.fromFile(file).getLines().mkString("\n")
38-
case str: String => str
39-
}
40-
val lines = fileContent.split("\n")
41-
lines.zipWithIndex
42-
.find { case (line, i) => line.trim.startsWith("page:") && !lines(i - 1).contains("- title:") }
43-
.map(_._1.trim.stripPrefix("page:"))
44-
.getOrElse("")
45-
4635
private def toSidebar(r: RawInput, content: String | java.io.File)(using CompilerContext): Sidebar = r match
4736
case RawInput(title, page, index, subsection, dir, hidden) if page.nonEmpty && index.isEmpty && subsection.isEmpty() =>
4837
val sidebarPath = content match
@@ -57,14 +46,13 @@ object Sidebar:
5746
Sidebar.Category(Option.when(title.nonEmpty)(title), Option.when(index.nonEmpty)(index), subsection.asScala.map(toSidebar(_, content)).toList, Option.when(dir.nonEmpty)(dir))
5847
case RawInput(title, page, index, subsection, dir, hidden) =>
5948
if title.isEmpty() && index.isEmpty() then
60-
val page = pageWithNoTitle(content).trim()
61-
val msg = s"Error parsing YAML configuration file: 'title' is not provided for page '$page'."
49+
val msg = "`title` property is missing for some page."
6250
report.error(s"$msg\n$schemaMessage")
6351
else if title.nonEmpty && (page.isEmpty() || index.isEmpty()) then
6452
val msg = s"Error parsing YAML configuration file: 'index' or 'page' path is missing for title '$title'."
6553
report.error(s"$msg\n$schemaMessage")
6654
else
67-
val msg = s"Error parsing YAML configuration file."
55+
val msg = "Problem when parsing YAML configuration file."
6856
report.warning(s"$msg\n$schemaMessage")
6957
Sidebar.Page(None, page, hidden)
7058

scaladoc/test/dotty/tools/scaladoc/site/SidebarParserTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class SidebarParserTest:
9191
| - page: my-page6/my-page6/my-page6.md
9292
""".stripMargin
9393

94-
private val msgNoTitle = "Error parsing YAML configuration file: 'title' is not provided for page 'my-page7/my-page7.md'."
94+
private val msgNoTitle = "`title` property is missing for some page."
9595
private val msgNoPage = "Error parsing YAML configuration file: 'index' or 'page' path is missing for title 'My title'."
9696

9797
private def schemaMessage: String = Sidebar.schemaMessage

0 commit comments

Comments
 (0)