@@ -374,17 +374,12 @@ object SyntaxHighlighting {
374374 override def doReport (m : MessageContainer )(implicit ctx : Context ): Unit = ()
375375 }
376376
377- private val ignoredKwds = Set (nme.ARROWkw , nme.EQ , nme.EQL , nme.COLONkw )
378-
379377 def highlight (in : String )(ctx0 : Context ): String = {
380378 import dotty .tools .dotc .ast .untpd ._
381379
382380 implicit val ctx : Context = ctx0.fresh.setReporter(new NoReporter )
383381
384382 val source = new SourceFile (" <highlighting>" , in.toCharArray)
385- val parser = new Parser (source)
386- val trees = parser.blockStatSeq()
387-
388383 val colorAt = Array .fill(in.length)(NoColor )
389384
390385 def highlightRange (from : Int , to : Int , color : String ) = {
@@ -399,18 +394,39 @@ object SyntaxHighlighting {
399394 def highlightPosition (pos : Position , color : String ) =
400395 if (pos.exists) highlightRange(pos.start, pos.end, color)
401396
397+ val scanner = new Scanner (source)
398+
399+ while (scanner.token != EOF ) {
400+ val isKwd = alphaKeywords.contains(scanner.token)
401+ val offsetStart = scanner.offset
402+
403+ if (scanner.token == IDENTIFIER && scanner.name == nme.??? ) {
404+ highlightRange(scanner.offset, scanner.offset + scanner.name.length, Console .RED_B )
405+ }
406+ scanner.nextToken()
407+
408+ if (isKwd) {
409+ val offsetEnd = scanner.lastOffset
410+ highlightPosition(Position (offsetStart, offsetEnd), KeywordColor )
411+ }
412+ }
413+
402414 val treeHighlighter = new UntypedTreeTraverser {
403415 def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
404416 tree match {
405- case id : Ident if id.isType =>
417+ case id : Ident if id.isType =>
406418 highlightPosition(id.pos, TypeColor )
407419 case tpe : TypeDef =>
420+ for (annotation <- tpe.rawMods.annotations)
421+ highlightPosition(annotation.pos, AnnotationColor )
408422 highlightPosition(tpe.namePos, TypeColor )
409423 case _ : TypTree =>
410424 highlightPosition(tree.pos, TypeColor )
411425 case mod : ModuleDef =>
412426 highlightPosition(mod.namePos, TypeColor )
413427 case v : ValOrDefDef =>
428+ for (annotation <- v.rawMods.annotations)
429+ highlightPosition(annotation.pos, AnnotationColor )
414430 highlightPosition(v.namePos, ValDefColor )
415431 highlightPosition(v.tpt.pos, TypeColor )
416432 case _ : Literal =>
@@ -421,26 +437,12 @@ object SyntaxHighlighting {
421437 }
422438 }
423439
440+ val parser = new Parser (source)
441+ val trees = parser.blockStatSeq()
442+
424443 for (tree <- trees)
425444 treeHighlighter.traverse(tree)
426445
427- val scanner = new Scanner (source)
428-
429- while (scanner.token != EOF ) {
430- val isKwd = isKeyword(scanner.token) && ! ignoredKwds.contains(scanner.name)
431- val offsetStart = scanner.offset
432-
433- if (scanner.token == IDENTIFIER && scanner.name == nme.??? ) {
434- highlightRange(scanner.offset, scanner.offset + scanner.name.length, Console .RED_B )
435- }
436- scanner.nextToken()
437-
438- if (isKwd) {
439- val offsetEnd = scanner.lastOffset
440- highlightPosition(Position (offsetStart, offsetEnd), KeywordColor )
441- }
442- }
443-
444446 val sb = new mutable.StringBuilder ()
445447
446448 for (idx <- colorAt.indices) {
0 commit comments