Skip to content

Commit 35b79c5

Browse files
committed
Fix #7694: Set a compilation unit for syntax highlighting
1 parent 2d780d8 commit 35b79c5

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc.printing
1+
package dotty.tools.dotc
2+
package printing
23

34
import dotty.tools.dotc.ast.untpd
45
import dotty.tools.dotc.core.Contexts.Context
@@ -32,8 +33,10 @@ object SyntaxHighlighting {
3233
def freshCtx = ctx.fresh.setReporter(Reporter.NoReporter)
3334
if (in.isEmpty || ctx.settings.color.value == "never") in
3435
else {
35-
implicit val ctx = freshCtx
3636
val source = SourceFile.virtual("<highlighting>", in)
37+
38+
implicit val ctx = freshCtx.setCompilationUnit(CompilationUnit(source, mustExist = false)(freshCtx))
39+
3740
val colorAt = Array.fill(in.length)(NoColor)
3841

3942
def highlightRange(from: Int, to: Int, color: String) =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class SyntaxHighlightingTests extends DottyTest {
110110

111111
test("def f1(x: Int) = 123", "<K|def> <V|f1>(<V|x>: <T|Int>) = <L|123>")
112112
test("def f2[T](x: T) = { 123 }", "<K|def> <V|f2>[<T|T>](<V|x>: <T|T>) = { <L|123> }")
113+
114+
test("def f3[T[_", "<K|def> <V|f3>[<T|T>[<T|_>")
113115
}
114116

115117
@Test

0 commit comments

Comments
 (0)