Skip to content

Commit 23a9c39

Browse files
committed
fix(#11202): special case LambdaTypeTree in syntax highlighting
This fixes #11202 and ensures that when a LambdaTypeTree is encountered we are only highlighting the actual type params.
1 parent 29f9d33 commit 23a9c39

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ object SyntaxHighlighting {
107107
case tree: ValOrDefDef =>
108108
highlightAnnotations(tree)
109109
highlightPosition(tree.nameSpan, ValDefColor)
110+
// Special case these to only highlight the actual types and not
111+
// the braces
112+
case tree: LambdaTypeTree =>
113+
tree.tparams.foreach(tparam => highlightPosition(tparam.span, TypeColor))
110114
case tree: MemberDef /* ModuleDef | TypeDef */ =>
111115
highlightAnnotations(tree)
112116
highlightPosition(tree.nameSpan, TypeColor)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class SyntaxHighlightingTests extends DottyTest {
2323

2424
if (expected != highlighted) {
2525
// assertEquals produces weird expected/found message
26-
fail(s"expected: $expected but was: $highlighted")
26+
fail(s"""|
27+
|expected: $expected
28+
|highlighted: $highlighted""".stripMargin)
2729
}
2830
}
2931

@@ -41,6 +43,8 @@ class SyntaxHighlightingTests extends DottyTest {
4143
test("type Foo = Int", "<K|type> <T|Foo> = <T|Int>")
4244
test("type A = String | Int", "<K|type> <T|A> = <T|String> <T||> <T|Int>")
4345
test("type B = String & Int", "<K|type> <T|B> = <T|String> <T|&> <T|Int>")
46+
test("type Id[A] = A", "<K|type> <T|Id>[<T|A>] = <T|A>")
47+
test("type Foo = [X] =>> List[X]", "<K|type> <T|Foo> = [<T|X>] =>> <T|List[X]>")
4448
}
4549

4650
@Test

0 commit comments

Comments
 (0)