Skip to content

Commit

Permalink
Add error tooltips to snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
pikinier20 committed Jul 14, 2022
1 parent 3be1eac commit a9d3a96
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 2 additions & 0 deletions scaladoc-js/common/src/code-snippets/CodeSnippets.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class CodeSnippets:

scastie.Embedded(popup.querySelector("pre"), scastieConfig)

popup.querySelector("li.btn.run-button").asInstanceOf[html.Element].click()

e.stopPropagation()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ object SnippetRenderer:
line.copy(content = begin + s"""<span class="hideable">$comment</span>""" + 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)
Expand Down Expand Up @@ -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"""<code class="language-scala">${transformedLines.mkString("")}</code>"""
val isRunnable = success
val attrs = Seq(
Expand Down

0 comments on commit a9d3a96

Please sign in to comment.