Skip to content

Commit bf5ba46

Browse files
authored
Merge pull request #5301 from veera83372/repl_comments_highlight
Added ability to highlight comments in repl
2 parents 7824363 + 49394e0 commit bf5ba46

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ object Scanners {
177177
/** All doc comments kept by their end position in a `Map` */
178178
private[this] var docstringMap: SortedMap[Int, Comment] = SortedMap.empty
179179

180+
/* A Buffer for comment positions */
181+
private[this] val commentPosBuf = new mutable.ListBuffer[Position]
182+
183+
/** Return a list of all the comment positions */
184+
def commentPositions: List[Position] = commentPosBuf.toList
185+
180186
private[this] def addComment(comment: Comment): Unit = {
181187
val lookahead = lookaheadReader()
182188
def nextPos: Int = (lookahead.getc(): @switch) match {
@@ -616,6 +622,7 @@ object Scanners {
616622
if (keepComments) {
617623
val pos = Position(start, charOffset - 1, start)
618624
val comment = Comment(pos, flushBuf(commentBuf))
625+
commentPosBuf += pos
619626

620627
if (comment.isDocComment) {
621628
addComment(comment)

compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ object SyntaxHighlighting {
8181
}
8282
}
8383

84+
for (pos <- scanner.commentPositions)
85+
highlightPosition(pos, CommentColor)
86+
8487
object TreeHighlighter extends untpd.UntypedTreeTraverser {
8588
import untpd._
8689

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,7 @@ class ReplDriver(settings: Array[String],
282282
x.symbol
283283
}
284284
.foreach { sym =>
285-
// FIXME syntax highlighting on comment is currently not working
286-
// out.println(SyntaxHighlighting.highlight("// defined " + sym.showUser))
287-
val message = "// defined " + sym.showUser
288-
if (ctx.settings.color.value != "never") {
289-
println(SyntaxHighlighting.CommentColor + message + SyntaxHighlighting.NoColor)
290-
} else {
291-
println(message)
292-
}
285+
out.println(SyntaxHighlighting.highlight("// defined " + sym.showUser))
293286
}
294287

295288

compiler/test/dotty/tools/dotc/printing/SyntaxHighlightingTests.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class SyntaxHighlightingTests extends DottyTest {
2828
}
2929

3030
@Test
31-
@Ignore("Comments are currently not supported")
3231
def comments = {
3332
test("// a", "<C|// a>")
3433
test("/** a */", "<C|/** a */>")

0 commit comments

Comments
 (0)