Skip to content

Commit 3989e7e

Browse files
committed
Fix positions in static sites. Enchance snippet wrapping
1 parent 67e5114 commit 3989e7e

File tree

8 files changed

+31
-21
lines changed

8 files changed

+31
-21
lines changed

docs/css/dottydoc.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,6 @@ h5:hover a.anchor:hover {
180180
font-family: var(--font-family-monospace);
181181
}
182182

183-
/* code */
184-
pre, code {
185-
font-variant-ligatures: none;
186-
}
187-
pre {
188-
padding: 0;
189-
font-size: 13px;
190-
background: var(--pre-bg);
191-
border-radius: 2px;
192-
border: 1px solid rgba(0, 0, 0, 0.1);
193-
}
194-
195183
/* admonitions */
196184
blockquote {
197185
padding: 0 1em;

project/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,8 @@ object Build {
13501350
s"-source-links:docs=github://lampepfl/dotty/master#docs",
13511351
"-doc-root-content", docRootFile.toString,
13521352
"-snippet-compiler:" +
1353-
s"$dottyLibRoot=compile"
1353+
s"$dottyLibRoot=compile" +
1354+
"docs=compile"
13541355
)
13551356
))
13561357
}.evaluated,

scaladoc-testcases/docs/docs/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77
2 + List(0)
88
```
99

10+
```scala sc:compile
11+
new snippetCompiler.Snippet0 { }
12+
```
13+

scaladoc/resources/dotty_res/styles/scalastyle.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ code {
9393
padding: 0 .3em;
9494
}
9595
pre {
96+
overflow: visible;
9697
scrollbar-width: thin;
9798
margin: 0px;
9899
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def emptyTemplate(file: File, title: String): TemplateFile = TemplateFile(
4949
title = title,
5050
hasFrame = true,
5151
resources = List.empty,
52-
layout = None
52+
layout = None,
53+
configOffset = 0
5354
)
5455

5556
final val ConfigSeparator = "---"
@@ -107,6 +108,7 @@ def loadTemplateFile(file: File): TemplateFile = {
107108
title = stringSetting(allSettings, "title").getOrElse(name),
108109
hasFrame = !stringSetting(allSettings, "hasFrame").contains("false"),
109110
resources = (listSetting(allSettings, "extraCSS") ++ listSetting(allSettings, "extraJS")).flatten.toList,
110-
layout = stringSetting(allSettings, "layout")
111+
layout = stringSetting(allSettings, "layout"),
112+
configOffset = config.size
111113
)
112114
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ case class TemplateFile(
5353
hasFrame: Boolean,
5454
resources: List[String],
5555
layout: Option[String],
56+
configOffset: Int
5657
):
5758
def isIndexPage() = file.isFile && (file.getName == "index.md" || file.getName == "index.html")
5859

@@ -63,7 +64,13 @@ case class TemplateFile(
6364
val pathBasedArg = ssctx.snippetCompilerArgs.get(path)
6465
(str: String, lineOffset: SnippetChecker.LineOffset, argOverride: Option[SCFlags]) => {
6566
val arg = argOverride.fold(pathBasedArg)(pathBasedArg.overrideFlag(_))
66-
ssctx.snippetChecker.checkSnippet(str, None, arg, lineOffset).collect {
67+
val compilerData = SnippetCompilerData(
68+
"staticsitesnippet",
69+
Seq(SnippetCompilerData.ClassInfo(None, Nil, None)),
70+
Nil,
71+
SnippetCompilerData.Position(configOffset - 1, 0)
72+
)
73+
ssctx.snippetChecker.checkSnippet(str, Some(compilerData), arg, lineOffset).collect {
6774
case r: SnippetCompilationResult if !r.isSuccessful =>
6875
val msg = s"In static site (${file.getAbsolutePath}):\n${r.getSummary}"
6976
report.error(msg)(using ssctx.outerCtx)

scaladoc/src/dotty/tools/scaladoc/snippets/SnippetCompilerDataCollector.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SnippetCompilerDataCollector[Q <: Quotes](val qctx: Q):
4343
}
4444
}
4545
val classType =
46-
val ct = cSym.classInfo.selfType.toText(printer).show.replace(".this","").stripPrefix(s"$packageName.")
46+
val ct = cSym.classInfo.selfType.toText(printer).show.replace(".this","").replace("\n", " ").stripPrefix(s"$packageName.")
4747
Some(ct)
4848
val classNames = collectNames(cSym.classInfo.selfType)
4949
val classGenerics = Option.when(

scaladoc/src/dotty/tools/scaladoc/snippets/WrappedSnippet.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,22 @@ object WrappedSnippet:
3131
val ps = new PrintStream(baos)
3232
ps.println(s"package ${packageName.getOrElse("snippets")}")
3333
imports.foreach(i => ps.println(s"import $i"))
34-
classInfos.zipWithIndex.foreach { (info, i) =>
34+
val notEmptyClassInfos = if classInfos.isEmpty then Seq(SnippetCompilerData.ClassInfo(None, Nil, None)) else classInfos
35+
notEmptyClassInfos.zipWithIndex.foreach { (info, i) =>
3536
ps.printlnWithIndent(2 * i, s"trait Snippet$i${info.generics.getOrElse("")} { ${info.tpe.fold("")(cn => s"self: $cn =>")}")
3637
info.names.foreach{ name =>
3738
ps.printlnWithIndent(2 * i + 2, s"val $name = self")
3839
}
3940
}
40-
str.split('\n').foreach(ps.printlnWithIndent(classInfos.size * 2, _))
41-
(0 to classInfos.size -1).reverse.foreach( i => ps.printlnWithIndent(i * 2, "}"))
42-
WrappedSnippet(baos.toString, lineOffset, columnOffset, classInfos.size + classInfos.flatMap(_.names).size, classInfos.size * 2 + 2)
41+
str.split('\n').foreach(ps.printlnWithIndent(notEmptyClassInfos.size * 2, _))
42+
(0 to notEmptyClassInfos.size -1).reverse.foreach( i => ps.printlnWithIndent(i * 2, "}"))
43+
WrappedSnippet(
44+
baos.toString,
45+
lineOffset,
46+
columnOffset,
47+
notEmptyClassInfos.size + notEmptyClassInfos.flatMap(_.names).size + packageName.size,
48+
notEmptyClassInfos.size * 2 + 2
49+
)
4350

4451
extension (ps: PrintStream) private def printlnWithIndent(indent: Int, str: String) =
4552
ps.println((" " * indent) + str)

0 commit comments

Comments
 (0)