All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dotty.tools.dotc.semanticdb.DiagnosticOps.scala Maven / Gradle / Ivy

There is a newer version: 3.6.4-RC1-bin-20241220-0bfa1af-NIGHTLY
Show newest version
package dotty.tools.dotc.semanticdb

import dotty.tools.dotc.reporting.Diagnostic
import dotty.tools.dotc.{semanticdb => s}
import dotty.tools.dotc.interfaces.Diagnostic.{ERROR, INFO, WARNING}
import dotty.tools.dotc.core.Contexts.Context
import scala.annotation.internal.sharable

object DiagnosticOps:
  @sharable private val asciiColorCodes = "\u001B\\[[;\\d]*m".r
  extension (d: Diagnostic)
    def toSemanticDiagnostic: s.Diagnostic =
      val severity = d.level match
        case ERROR => s.Diagnostic.Severity.ERROR
        case WARNING => s.Diagnostic.Severity.WARNING
        case INFO => s.Diagnostic.Severity.INFORMATION
        case _ => s.Diagnostic.Severity.INFORMATION
      val msg = asciiColorCodes.replaceAllIn(d.msg.message, m => "")
      s.Diagnostic(
        range = Scala3.range(d.pos.span, d.pos.source),
        severity = severity,
        message = msg
      )




© 2015 - 2025 Weber Informatics LLC | Privacy Policy