Skip to content

Commit 35a23d6

Browse files
committed
Use AnalysisCallback2 to avoid dropping CodeActions
1 parent 039f658 commit 35a23d6

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ val jnaDep = "net.java.dev.jna" % "jna"
4545
val jlineDeps = Seq(jlineDep, jnaDep)
4646
val testInterfaceDep = "org.scala-sbt" % "test-interface" % "1.0"
4747
val diffUtilsDep = "io.github.java-diff-utils" % "java-diff-utils" % "4.12"
48-
val compilerInterfaceDep = "org.scala-sbt" % "compiler-interface" % "1.9.2"
48+
val compilerInterfaceDep = "org.scala-sbt" % "compiler-interface" % "1.9.3"
4949

5050
val projectFolder = settingKey[String]("subfolder in src when using configureAsSubproject, else the project name")
5151

src/sbt-bridge/scala/tools/xsbt/CompilerBridge.scala

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
package scala.tools
1616
package xsbt
1717

18-
import xsbti.{ AnalysisCallback, Logger, Problem, Reporter, VirtualFile }
18+
import xsbti.{AnalysisCallback, AnalysisCallback2, Logger, Problem, Reporter, VirtualFile}
1919
import xsbti.compile._
20+
2021
import scala.tools.nsc.Settings
2122
import scala.collection.mutable
2223
import scala.reflect.io.AbstractFile
2324
import scala.tools.nsc.CompilerCommand
2425
import Log.debug
2526
import java.io.File
27+
import java.util.{Collections, Optional}
2628

2729
/**
2830
* This is the entry point for the compiler bridge (implementation of CompilerInterface)
@@ -154,6 +156,14 @@ private final class CachedCompiler0(
154156
compileProgress: CompileProgress
155157
): Unit = {
156158

159+
lazy val callback2 =
160+
try callback.asInstanceOf[AnalysisCallback2]
161+
catch { case _: NoClassDefFoundError => null}
162+
163+
def callbackProblem(p: Problem) =
164+
if (callback2 != null) callback2.problem2(p.category, p.position, p.message, p.severity, true, p.rendered, p.diagnosticCode, p.diagnosticRelatedInformation, p.actions)
165+
else callback.problem(p.category, p.position, p.message, p.severity, true)
166+
157167
if (command.shouldStopWithInfo) {
158168
underlyingReporter.info(null, command.getInfoMessage(compiler), true)
159169
throw new InterfaceCompileFailed(args, Array(), StopInfoError)
@@ -165,10 +175,7 @@ private final class CachedCompiler0(
165175
val run = new compiler.ZincRun(compileProgress)
166176

167177
run.compileFiles(sources)
168-
processUnreportedWarnings(run)
169-
underlyingReporter.problems.foreach(p =>
170-
callback.problem(p.category, p.position, p.message, p.severity, true)
171-
)
178+
underlyingReporter.problems.foreach(callbackProblem)
172179
}
173180

174181
underlyingReporter.printSummary()
@@ -192,18 +199,4 @@ private final class CachedCompiler0(
192199
debug(log, "Compilation cancelled (CompilerInterface)")
193200
throw new InterfaceCompileCancelled(args, "Compilation has been cancelled")
194201
}
195-
196-
def processUnreportedWarnings(run: compiler.Run): Unit = {
197-
// allConditionalWarnings and the ConditionalWarning class are only in 2.10+
198-
final class CondWarnCompat(
199-
val what: String,
200-
val warnings: mutable.ListBuffer[(compiler.Position, String)]
201-
)
202-
implicit def compat(run: AnyRef): Compat = new Compat
203-
final class Compat { def allConditionalWarnings = List[CondWarnCompat]() }
204-
205-
val warnings = run.allConditionalWarnings
206-
if (warnings.nonEmpty)
207-
compiler.logUnreportedWarnings(warnings.map(cw => ("" /*cw.what*/, cw.warnings.toList)))
208-
}
209202
}

test/junit/scala/tools/xsbt/TestCallback.scala

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package scala.tools.xsbt
22

3-
import xsbti.{AnalysisCallback, UseScope, VirtualFile, VirtualFileRef}
3+
import xsbti.api.{ClassLike, DependencyContext}
4+
import xsbti.{Action, AnalysisCallback2, DiagnosticCode, DiagnosticRelatedInformation, Position, Severity, UseScope, VirtualFile, VirtualFileRef}
45

56
import java.io.File
67
import java.nio.file.Path
78
import java.util
89
import java.util.Optional
9-
import xsbti.api.{ClassLike, DependencyContext}
10-
1110
import scala.collection.mutable.ArrayBuffer
1211

13-
class TestCallback extends AnalysisCallback {
12+
class TestCallback extends AnalysisCallback2 {
1413
case class TestUsedName(name: String, scopes: util.EnumSet[UseScope])
1514

1615
val classDependencies = new ArrayBuffer[(String, String, DependencyContext)]
@@ -122,6 +121,16 @@ class TestCallback extends AnalysisCallback {
122121
reported: Boolean
123122
): Unit = ()
124123

124+
override def problem2(what: String,
125+
pos: Position,
126+
msg: String,
127+
severity: Severity,
128+
reported: Boolean,
129+
rendered: Optional[String],
130+
diagnosticCode: Optional[DiagnosticCode],
131+
diagnosticRelatedInformation: util.List[DiagnosticRelatedInformation],
132+
actions: util.List[Action]): Unit = ()
133+
125134
override def dependencyPhaseCompleted(): Unit = {}
126135

127136
override def apiPhaseCompleted(): Unit = {}
@@ -153,7 +162,7 @@ object TestCallback {
153162
}
154163

155164
private def pairsToMultiMap[A, B](pairs: Seq[(A, B)]): Map[A, Set[B]] = {
156-
import scala.collection.{ mutable => m }
165+
import scala.collection.{mutable => m}
157166
val emptyMultiMap = new m.HashMap[A, m.Set[B]]
158167
val multiMap = pairs.foldLeft(emptyMultiMap) {
159168
case (acc, (key, value)) => acc.get(key) match {

0 commit comments

Comments
 (0)