diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 4e8e3cdce803..e026b7fad9a2 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -177,8 +177,11 @@ object Scanners { /** All doc comments kept by their end position in a `Map` */ private[this] var docstringMap: SortedMap[Int, Comment] = SortedMap.empty - /* All comments positions will be stored in this */ - var commentPositions:mutable.MutableList[Position] = mutable.MutableList() + /* 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() @@ -619,7 +622,7 @@ object Scanners { if (keepComments) { val pos = Position(start, charOffset - 1, start) val comment = Comment(pos, flushBuf(commentBuf)) - commentPositions += pos + 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 6ab82e22c397..a7a8ea420df5 100644 --- a/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala +++ b/compiler/src/dotty/tools/dotc/printing/SyntaxHighlighting.scala @@ -49,11 +49,6 @@ object SyntaxHighlighting { highlightRange(pos.start, pos.end, color) } - def highlightComments(commentsPos: mutable.MutableList[Position]): Unit = { - for (pos <- commentsPos) - highlightPosition(pos,CommentColor) - } - val scanner = new Scanner(source) while (scanner.token != EOF) { val start = scanner.offset @@ -87,7 +82,9 @@ object SyntaxHighlighting { } } - highlightComments(scanner.commentPositions) + scanner.commentPositions.foreach { + highlightPosition(_,CommentColor) + } object TreeHighlighter extends untpd.UntypedTreeTraverser { import untpd._