diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 731a280f0407..e026b7fad9a2 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -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 { @@ -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) diff --git a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala index 36659544d6ff..58d1cc3bbcec 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -81,6 +81,9 @@ object SyntaxHighlighting { } } + for (pos <- scanner.commentPositions) + highlightPosition(pos, CommentColor) + object TreeHighlighter extends untpd.UntypedTreeTraverser { import untpd._ diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 4717d38deef5..bd76310b7656 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -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)) } diff --git a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala index 1d0eaa031d4f..c53a2cd773e9 100644 --- a/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala +++ b/compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala @@ -28,7 +28,6 @@ class SyntaxHighlightingTests extends DottyTest { } @Test - @Ignore("Comments are currently not supported") def comments = { test("// a", "") test("/** a */", "")