mirror of
https://github.com/sbt/sbt.git
synced 2026-08-22 06:07:24 +02:00
Fix reporting Java diagnostics through BSP
Java diagnostics don't have a pointer but we should report them. Copied implementation from Bloop to translate the position of an xsbti.Problem to a BSP range.
This commit is contained in:
@@ -108,7 +108,7 @@ final class BuildServerReporterImpl(
|
|||||||
val hadProblems = bspCompileState.hasAnyProblems.remove(filePath)
|
val hadProblems = bspCompileState.hasAnyProblems.remove(filePath)
|
||||||
|
|
||||||
val reportedProblems = infos.getReportedProblems.toVector
|
val reportedProblems = infos.getReportedProblems.toVector
|
||||||
val diagnostics = reportedProblems.flatMap(toDiagnostic)
|
val diagnostics = reportedProblems.map(toDiagnostic)
|
||||||
|
|
||||||
// publish diagnostics if:
|
// publish diagnostics if:
|
||||||
// 1. file had any problems previously - we might want to update them with new ones
|
// 1. file had any problems previously - we might want to update them with new ones
|
||||||
@@ -165,9 +165,9 @@ final class BuildServerReporterImpl(
|
|||||||
protected override def publishDiagnostic(problem: Problem): Unit = {
|
protected override def publishDiagnostic(problem: Problem): Unit = {
|
||||||
for {
|
for {
|
||||||
id <- problem.position.sourcePath.toOption
|
id <- problem.position.sourcePath.toOption
|
||||||
diagnostic <- toDiagnostic(problem)
|
|
||||||
filePath <- toSafePath(VirtualFileRef.of(id))
|
filePath <- toSafePath(VirtualFileRef.of(id))
|
||||||
} {
|
} {
|
||||||
|
val diagnostic = toDiagnostic(problem)
|
||||||
problemsByFile(filePath) = problemsByFile.getOrElse(filePath, Vector.empty) :+ diagnostic
|
problemsByFile(filePath) = problemsByFile.getOrElse(filePath, Vector.empty) :+ diagnostic
|
||||||
val params = PublishDiagnosticsParams(
|
val params = PublishDiagnosticsParams(
|
||||||
TextDocumentIdentifier(filePath.toUri),
|
TextDocumentIdentifier(filePath.toUri),
|
||||||
@@ -180,23 +180,19 @@ final class BuildServerReporterImpl(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def toDiagnostic(problem: Problem): Option[Diagnostic] = {
|
private def toDiagnostic(problem: Problem): Diagnostic = {
|
||||||
val pos = problem.position
|
val pos = problem.position
|
||||||
for {
|
val startLineOpt = pos.startLine.toOption.map(_.toLong - 1)
|
||||||
line <- pos.line.toOption.map(_.toLong - 1L)
|
val startColumnOpt = pos.startColumn.toOption.map(_.toLong)
|
||||||
pointer <- pos.pointer.toOption.map(_.toLong)
|
val endLineOpt = pos.endLine.toOption.map(_.toLong - 1)
|
||||||
} yield {
|
val endColumnOpt = pos.endColumn.toOption.map(_.toLong)
|
||||||
val range = (
|
|
||||||
pos.startLine.toOption,
|
def toPosition(lineOpt: Option[Long], columnOpt: Option[Long]): Option[Position] =
|
||||||
pos.startColumn.toOption,
|
lineOpt.map(line => Position(line, columnOpt.getOrElse(0L)))
|
||||||
pos.endLine.toOption,
|
|
||||||
pos.endColumn.toOption
|
val startPos = toPosition(startLineOpt, startColumnOpt).getOrElse(Position(0L, 0L))
|
||||||
) match {
|
val endPosOpt = toPosition(endLineOpt, endColumnOpt)
|
||||||
case (Some(sl), Some(sc), Some(el), Some(ec)) =>
|
val range = Range(startPos, endPosOpt.getOrElse(startPos))
|
||||||
Range(Position(sl.toLong - 1, sc.toLong), Position(el.toLong - 1, ec.toLong))
|
|
||||||
case _ =>
|
|
||||||
Range(Position(line, pointer), Position(line, pointer + 1))
|
|
||||||
}
|
|
||||||
|
|
||||||
Diagnostic(
|
Diagnostic(
|
||||||
range,
|
range,
|
||||||
@@ -206,7 +202,6 @@ final class BuildServerReporterImpl(
|
|||||||
problem.message
|
problem.message
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private def toDiagnosticSeverity(severity: Severity): Long = severity match {
|
private def toDiagnosticSeverity(severity: Severity): Long = severity match {
|
||||||
case Severity.Info => DiagnosticSeverity.Information
|
case Severity.Info => DiagnosticSeverity.Information
|
||||||
|
|||||||
Reference in New Issue
Block a user