Skip to content

Added ability to highlight comments in repl #5301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ object Scanners {
/** All doc comments kept by their end position in a `Map` */
private[this] var docstringMap: SortedMap[Int, Comment] = SortedMap.empty

/* A Buffer for comment positions */
private[this] val commentPosBuf = new mutable.ListBuffer[Position]

/** Return a list of all the comment positions */
def commentPositions: List[Position] = commentPosBuf.toList

private[this] def addComment(comment: Comment): Unit = {
val lookahead = lookaheadReader()
def nextPos: Int = (lookahead.getc(): @switch) match {
Expand Down Expand Up @@ -616,6 +622,7 @@ object Scanners {
if (keepComments) {
val pos = Position(start, charOffset - 1, start)
val comment = Comment(pos, flushBuf(commentBuf))
commentPosBuf += pos

if (comment.isDocComment) {
addComment(comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ object SyntaxHighlighting {
}
}

for (pos <- scanner.commentPositions)
highlightPosition(pos, CommentColor)

object TreeHighlighter extends untpd.UntypedTreeTraverser {
import untpd._

Expand Down
9 changes: 1 addition & 8 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,7 @@ class ReplDriver(settings: Array[String],
x.symbol
}
.foreach { sym =>
// FIXME syntax highlighting on comment is currently not working
// out.println(SyntaxHighlighting.highlight("// defined " + sym.showUser))
val message = "// defined " + sym.showUser
if (ctx.settings.color.value != "never") {
println(SyntaxHighlighting.CommentColor + message + SyntaxHighlighting.NoColor)
} else {
println(message)
}
out.println(SyntaxHighlighting.highlight("// defined " + sym.showUser))
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SyntaxHighlightingTests extends DottyTest {
}

@Test
@Ignore("Comments are currently not supported")
def comments = {
test("// a", "<C|// a>")
test("/** a */", "<C|/** a */>")
Expand Down