Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/src/main/scala/bloop/reporter/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ abstract class Reporter(
p.message,
mappedPos,
p.category,
p.rendered(),
p.diagnosticCode(),
p.diagnosticRelatedInformation(),
p.actions()
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ final class BloopBspServices(

val isPipeline = compileArgs.exists(_ == "--pipeline")
val bestEffortAllowed = compileArgs.exists(_ == "--best-effort")
val showRenderedMessage = compileArgs.exists(_ == "--show-rendered-message")
def compile(projects: List[Project]): Task[State] = {
val config = ReporterConfig.defaultFormat.copy(reverseOrder = false)

Expand All @@ -553,7 +554,8 @@ final class BloopBspServices(
inputs.logger,
inputs.cwd,
config,
reportAllPreviousProblems
reportAllPreviousProblems,
showRenderedMessage
)
}

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/main/scala/bloop/logging/BspServerLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ final class BspServerLogger private (
}

def diagnostic(event: CompilationEvent.Diagnostic): Unit = {
val message = event.problem.message
val message0 = event.problem.message
val message =
if (event.showRenderedMessage)
InterfaceUtil.toOption(event.problem.rendered()).getOrElse(message0)
else message0
val problemPos = event.problem.position
val problemSeverity = event.problem.severity
val sourceFile = InterfaceUtil.toOption(problemPos.sourceFile())
Expand Down
32 changes: 26 additions & 6 deletions frontend/src/main/scala/bloop/reporter/BspProjectReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ final class BspProjectReporter(
cwd: AbsolutePath,
config: ReporterConfig,
reportAllPreviousProblems: Boolean,
showRenderedMessage: Boolean,
override val _problems: Reporter.Buffer[ProblemPerPhase]
) extends Reporter(logger, cwd, config, _problems) {

Expand All @@ -30,14 +31,16 @@ final class BspProjectReporter(
logger: BspServerLogger,
cwd: AbsolutePath,
config: ReporterConfig,
reportAllPreviousProblems: Boolean
reportAllPreviousProblems: Boolean,
showRenderedMessage: Boolean
) =
this(
project,
logger,
cwd,
config,
reportAllPreviousProblems,
showRenderedMessage,
createBuffer[ProblemPerPhase](project)
)

Expand All @@ -59,8 +62,13 @@ final class BspProjectReporter(
case Some(file) =>
// If it's the first diagnostic for this file, set clear to true
val clear = clearedFilesForClient.putIfAbsent(file, true).isEmpty
logger.diagnostic(CompilationEvent.Diagnostic(project.bspUri, problem, clear))
case None => logger.diagnostic(CompilationEvent.Diagnostic(project.bspUri, problem, false))
logger.diagnostic(
CompilationEvent.Diagnostic(project.bspUri, problem, clear, showRenderedMessage)
)
case None =>
logger.diagnostic(
CompilationEvent.Diagnostic(project.bspUri, problem, false, showRenderedMessage)
)
}
}

Expand Down Expand Up @@ -248,7 +256,12 @@ final class BspProjectReporter(
case ProblemPerPhase(problem, _) =>
val clear = clearedFilesForClient.putIfAbsent(sourceFile, true).isEmpty
logger.diagnostic(
CompilationEvent.Diagnostic(project.bspUri, problem, clear)
CompilationEvent.Diagnostic(
project.bspUri,
problem,
clear,
showRenderedMessage
)
)
}
}
Expand All @@ -265,7 +278,9 @@ final class BspProjectReporter(
problems.foreach {
case ProblemPerPhase(problem, _) =>
val clear = clearedFilesForClient.putIfAbsent(sourceFile, true).isEmpty
logger.diagnostic(CompilationEvent.Diagnostic(project.bspUri, problem, clear))
logger.diagnostic(
CompilationEvent.Diagnostic(project.bspUri, problem, clear, showRenderedMessage)
)
}
}

Expand Down Expand Up @@ -335,7 +350,12 @@ final class BspProjectReporter(
case ProblemPerPhase(problem, _) =>
val clear = clearedFilesForClient.putIfAbsent(sourceFile, true).isEmpty
logger.diagnostic(
CompilationEvent.Diagnostic(project.bspUri, problem, clear)
CompilationEvent.Diagnostic(
project.bspUri,
problem,
clear,
showRenderedMessage
)
)
}
}
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/test/scala/bloop/bsp/BspClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ trait BspClientTest {
val canonical = pathString.replace(File.separatorChar, '/')
val report = diagnostics.map(
_.copy(source = Some("_"), code = Some("_")).toString
.replace("\n", " ")
.replace(END_OF_LINE_MATCHER, " ")
.replaceAll(END_OF_LINE_MATCHER, " ")
)
builder
.++=(s"#${compileIteration()}: $canonical\n")
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bloop.bsp

import java.io.File
import java.nio.file.Files
import java.nio.file.attribute.FileTime
import java.time.Instant
Expand Down Expand Up @@ -1423,6 +1424,41 @@ class BspCompileSpec(
}
}

test("compile and return rendered message") {
TestUtil.withinWorkspace { workspace =>
val sources = List(
"""/main/scala/Foo.scala
|def foo(s: String): Int = s
""".stripMargin
)

val logger = new RecordingLogger(ansiCodesSupported = false)
val `A` = TestProject(workspace, "a", sources, scalaVersion = Some("3.3.7"))
val projects = List(`A`)

loadBspState(workspace, projects, logger) { state =>
val compiledState = state.compile(`A`, arguments = Some(List("--show-rendered-message")))
assertExitStatus(compiledState, ExitStatus.CompilationError)
val sep = File.separator
assertNoDiff(
// Remove ANSI escape codes
compiledState.lastDiagnostics(`A`).replaceAll("\u001B\\[[;\\d]*m", ""),
s"""
|#1: task start 1
| -> Msg: Compiling a (1 Scala source)
| -> Data kind: compile-task
|#1: a/src/main/scala/Foo.scala
| -> List(Diagnostic(Range(Position(0,26),Position(0,27)),Some(Error),Some(_),Some(_),-- [E007] Type Mismatch Error: $workspace${sep}a${sep}src${sep}main${sep}scala${sep}Foo.scala:1:26 1 |def foo(s: String): Int = s | ^ | Found: (s : String) | Required: Int | | longer explanation available when compiling with `-explain`,None,None,Some({"actions":[]})))
| -> reset = true
|#1: task finish 1
| -> errors 1, warnings 0, noop false
| -> Msg: Compiled 'a'
| -> Data kind: compile-report """.stripMargin
)
}
}
}

test("task notifications are sent when compiling project with dependency") {
TestUtil.withinWorkspace { workspace =>
val sourcesA = List(
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/bloop/io/Environment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ object Environment {
* - "\r\n"
* - "\r"
*/
def END_OF_LINE_MATCHER = "\r\n|\n"
def END_OF_LINE_MATCHER = "\r\n|\n|\r"

/*
* A list of valid shell paths. The SHELL environment variable must
Expand Down
3 changes: 2 additions & 1 deletion shared/src/main/scala/bloop/logging/CompilationEvent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ object CompilationEvent {
case class Diagnostic(
projectUri: bsp.Uri,
problem: xsbti.Problem,
clear: Boolean
clear: Boolean,
showRenderedMessage: Boolean
) extends CompilationEvent

/**
Expand Down
3 changes: 3 additions & 0 deletions shared/src/main/scala/bloop/reporter/Problem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final case class Problem private (
position: xsbti.Position,
/** The category of this problem. */
category: String,
/** If present, the string shown to the user when displaying this Problem */
override val rendered: Optional[String],
/** Unique code attatched to the diagnostic being reported */
override val diagnosticCode: Optional[xsbti.DiagnosticCode],
override val diagnosticRelatedInforamation: java.util.List[xsbti.DiagnosticRelatedInformation],
Expand All @@ -30,6 +32,7 @@ object Problem {
problem.message(),
problem.position(),
problem.category(),
problem.rendered(),
problem.diagnosticCode(),
problem.diagnosticRelatedInformation(),
problem.actions()
Expand Down
Loading