Skip to content

Commit 642ebaf

Browse files
committed
Don't rewrite when syntax highlighting
The syntax highlighter creates its own copy of a parser. This parser should not apply any patches, since these would be duplicates.
1 parent 32b1ff7 commit 642ebaf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compiler/src/dotty/tools/dotc/rewrites/Rewrites.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Positions.Position
66
import core.Contexts.Context
77
import collection.mutable
88
import scala.annotation.tailrec
9+
import dotty.tools.dotc.reporting.Reporter
910

1011
/** Handles rewriting of Scala2 files to Dotty */
1112
object Rewrites {
@@ -63,10 +64,11 @@ object Rewrites {
6364
* given by `pos` in `source` by `replacement`
6465
*/
6566
def patch(source: SourceFile, pos: Position, replacement: String)(implicit ctx: Context): Unit =
66-
for (rewrites <- ctx.settings.rewrite.value)
67-
rewrites.patched
68-
.getOrElseUpdate(source, new Patches(source))
69-
.addPatch(pos, replacement)
67+
if (ctx.reporter != Reporter.NoReporter) // NoReporter is used for syntax highlighting
68+
for (rewrites <- ctx.settings.rewrite.value)
69+
rewrites.patched
70+
.getOrElseUpdate(source, new Patches(source))
71+
.addPatch(pos, replacement)
7072

7173
/** Patch position in `ctx.compilationUnit.source`. */
7274
def patch(pos: Position, replacement: String)(implicit ctx: Context): Unit =

0 commit comments

Comments
 (0)