From a9d3a965ef4424f4d1f9cfbde3be0b64c409f113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Zyba=C5=82a?= Date: Thu, 14 Jul 2022 14:12:44 +0200 Subject: [PATCH] Add error tooltips to snippets --- .../src/code-snippets/CodeSnippets.scala | 2 ++ .../styles/theme/components/code-snippet.css | 34 +++++++++++++++++++ .../comments/markdown/SnippetRenderer.scala | 7 +++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/scaladoc-js/common/src/code-snippets/CodeSnippets.scala b/scaladoc-js/common/src/code-snippets/CodeSnippets.scala index 4cc8145c597e..c857d7d7df98 100644 --- a/scaladoc-js/common/src/code-snippets/CodeSnippets.scala +++ b/scaladoc-js/common/src/code-snippets/CodeSnippets.scala @@ -130,6 +130,8 @@ class CodeSnippets: scastie.Embedded(popup.querySelector("pre"), scastieConfig) + popup.querySelector("li.btn.run-button").asInstanceOf[html.Element].click() + e.stopPropagation() ) diff --git a/scaladoc/resources/dotty_res/styles/theme/components/code-snippet.css b/scaladoc/resources/dotty_res/styles/theme/components/code-snippet.css index 7730461e856a..b2e009b813ac 100644 --- a/scaladoc/resources/dotty_res/styles/theme/components/code-snippet.css +++ b/scaladoc/resources/dotty_res/styles/theme/components/code-snippet.css @@ -150,6 +150,40 @@ width: unset !important; } +.tooltip-container { + display: none; +} +.tooltip:hover .tooltip-container { + display: unset; +} +.tooltip:hover .tooltip-container::after { + content: attr(label); + padding: 4px 8px; + color: white; + background-color:black; + position: absolute; + z-index:10; + box-shadow:0 0 3px #444; + opacity: 0.8; +} + +.snippet .buttons .tooltip::after { + top: 32px; +} + +.snippet-error { + border-bottom: 2px dotted red; +} +.snippet-warn { + border-bottom: 2px dotted orange; +} +.snippet-info { + border-bottom: 2px dotted teal; +} +.snippet-debug { + border-bottom: 2px dotted pink; +} + .hljs-keyword { color: var(--code-method-highlighting-keyword); } diff --git a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala index 36f23603149e..312d30a6ca19 100644 --- a/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala +++ b/scaladoc/src/dotty/tools/scaladoc/tasty/comments/markdown/SnippetRenderer.scala @@ -94,6 +94,11 @@ object SnippetRenderer: line.copy(content = begin + s"""$comment""" + end) case _ => line + private def reindexLines(lines: Seq[SnippetLine]) = + lines.zipWithIndex.map { + case (line, newIdx) => line.copy(lineNo = newIdx) + } + private def wrapCodeLines(codeLines: Seq[String]): Seq[SnippetLine] = val snippetLines = codeLines.zipWithIndex.map { case (content, idx) => SnippetLine(content.escapeReservedTokens, idx) @@ -133,7 +138,7 @@ object SnippetRenderer: ).toString def renderSnippetWithMessages(snippetName: Option[String], codeLines: Seq[String], messages: Seq[SnippetCompilerMessage], success: Boolean): String = - val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).apply(codeLines).map(_.toHTML) + val transformedLines = wrapCodeLines.andThen(addCompileMessages(messages)).andThen(reindexLines).apply(codeLines).map(_.toHTML) val codeHTML = s"""${transformedLines.mkString("")}""" val isRunnable = success val attrs = Seq(