Don't fire publishDiagnostic if there's no problems both in current and previous compilation

This commit is contained in:
Rikito Taniguchi 2022-03-18 02:23:08 +09:00 committed by Eugene Yokota
parent 2962b088a0
commit 862d373f02
2 changed files with 23 additions and 15 deletions

View File

@ -2374,10 +2374,11 @@ object Defaults extends BuildCommon {
val ci = (compile / compileInputs).value val ci = (compile / compileInputs).value
val ping = earlyOutputPing.value val ping = earlyOutputPing.value
val reporter = (compile / bspReporter).value val reporter = (compile / bspReporter).value
val prevAnalysis = previousCompile.value.analysis.toOption.getOrElse(Analysis.empty)
BspCompileTask.compute(bspTargetIdentifier.value, thisProjectRef.value, configuration.value) { BspCompileTask.compute(bspTargetIdentifier.value, thisProjectRef.value, configuration.value) {
task => task =>
// TODO - Should readAnalysis + saveAnalysis be scoped by the compile task too? // TODO - Should readAnalysis + saveAnalysis be scoped by the compile task too?
compileIncrementalTaskImpl(task, s, ci, ping, reporter) compileIncrementalTaskImpl(task, s, ci, ping, reporter, prevAnalysis)
} }
} }
private val incCompiler = ZincUtil.defaultIncrementalCompiler private val incCompiler = ZincUtil.defaultIncrementalCompiler
@ -2406,7 +2407,8 @@ object Defaults extends BuildCommon {
s: TaskStreams, s: TaskStreams,
ci: Inputs, ci: Inputs,
promise: PromiseWrap[Boolean], promise: PromiseWrap[Boolean],
reporter: BuildServerReporter reporter: BuildServerReporter,
prev: CompileAnalysis
): CompileResult = { ): CompileResult = {
lazy val x = s.text(ExportStream) lazy val x = s.text(ExportStream)
def onArgs(cs: Compilers) = { def onArgs(cs: Compilers) = {
@ -2428,7 +2430,7 @@ object Defaults extends BuildCommon {
.withSetup(onProgress(setup)) .withSetup(onProgress(setup))
try { try {
val result = incCompiler.compile(i, s.log) val result = incCompiler.compile(i, s.log)
reporter.sendSuccessReport(result.getAnalysis) reporter.sendSuccessReport(result.getAnalysis, prev)
result result
} catch { } catch {
case e: Throwable => case e: Throwable =>

View File

@ -38,7 +38,7 @@ sealed trait BuildServerReporter extends Reporter {
protected def publishDiagnostic(problem: Problem): Unit protected def publishDiagnostic(problem: Problem): Unit
def sendSuccessReport(analysis: CompileAnalysis): Unit def sendSuccessReport(analysis: CompileAnalysis, prev: CompileAnalysis): Unit
def sendFailureReport(sources: Array[VirtualFile]): Unit def sendFailureReport(sources: Array[VirtualFile]): Unit
@ -86,20 +86,26 @@ final class BuildServerReporterImpl(
if (ref.id().contains("<")) None if (ref.id().contains("<")) None
else Some(converter.toPath(ref)) else Some(converter.toPath(ref))
override def sendSuccessReport(analysis: CompileAnalysis): Unit = { override def sendSuccessReport(analysis: CompileAnalysis, prev: CompileAnalysis): Unit = {
val prevInfos = prev.readSourceInfos().getAllSourceInfos().asScala
for { for {
(source, infos) <- analysis.readSourceInfos.getAllSourceInfos.asScala (source, infos) <- analysis.readSourceInfos.getAllSourceInfos.asScala
filePath <- toSafePath(source) filePath <- toSafePath(source)
} { } {
val diagnostics = infos.getReportedProblems.toSeq.flatMap(toDiagnostic) val prevProblems = prevInfos.get(source).map(_.getReportedProblems()).getOrElse(Array.empty)
val params = PublishDiagnosticsParams( val dontPublish = prevProblems.length == 0 && infos.getReportedProblems().length == 0
textDocument = TextDocumentIdentifier(filePath.toUri),
buildTarget, if (!dontPublish) {
originId = None, val diagnostics = infos.getReportedProblems.toSeq.flatMap(toDiagnostic)
diagnostics.toVector, val params = PublishDiagnosticsParams(
reset = true textDocument = TextDocumentIdentifier(filePath.toUri),
) buildTarget,
exchange.notifyEvent("build/publishDiagnostics", params) originId = None,
diagnostics.toVector,
reset = true
)
exchange.notifyEvent("build/publishDiagnostics", params)
}
} }
} }
@ -179,7 +185,7 @@ final class BuildServerForwarder(
protected override val underlying: Reporter protected override val underlying: Reporter
) extends BuildServerReporter { ) extends BuildServerReporter {
override def sendSuccessReport(analysis: CompileAnalysis): Unit = () override def sendSuccessReport(analysis: CompileAnalysis, prev: CompileAnalysis): Unit = ()
override def sendFailureReport(sources: Array[VirtualFile]): Unit = () override def sendFailureReport(sources: Array[VirtualFile]): Unit = ()