Skip to content

Commit

Permalink
Convert PlainFile to ZincPlainFile
Browse files Browse the repository at this point in the history
  • Loading branch information
Friendseeker committed Dec 15, 2023
1 parent 1b2951a commit b4a5377
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 12 additions & 2 deletions internal/compiler-bridge/src/main/scala/xsbt/CallbackGlobal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

package xsbt

import xsbti.{ AnalysisCallback, Severity }
import xsbti.{ AnalysisCallback, AnalysisCallback3, PathBasedFile, Severity }
import xsbti.compile._

import scala.tools.nsc._
import io.AbstractFile
import java.nio.file.{ Files, Path }

import scala.reflect.io.PlainFile
import scala.reflect.ReflectAccess._
import scala.reflect.internal.util.BatchSourceFile

/** Defines the interface of the incremental compiler hiding implementation details. */
sealed abstract class CallbackGlobal(
Expand Down Expand Up @@ -78,6 +78,16 @@ sealed class ZincCompiler(settings: Settings, dreporter: DelegatingReporter, out
extends CallbackGlobal(settings, dreporter, output)
with ZincGlobalCompat {

override def getSourceFile(f: AbstractFile): BatchSourceFile = {
val file = f match {
case plainFile: PlainFile =>
val vf = callback.asInstanceOf[AnalysisCallback3].toVirtualFile(plainFile.file.toPath)
new ZincPlainFile(vf.asInstanceOf[PathBasedFile])
case _ => f
}
super.getSourceFile(file)
}

final class ZincRun(compileProgress: CompileProgress) extends Run {
override def informUnitStarting(phase: Phase, unit: CompilationUnit): Unit = {
compileProgress.startUnit(phase.name, unit.source.path)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Zinc - The incremental compiler for Scala.
* Copyright Scala Center, Lightbend, and Mark Harrah
*
* Licensed under Apache License 2.0
* SPDX-License-Identifier: Apache-2.0
*
* See the NOTICE file distributed with this work for
* additional information regarding copyright ownership.
*/

package xsbti;

import java.nio.file.Path;

public interface AnalysisCallback3 extends AnalysisCallback2 {
VirtualFile toVirtualFile(Path path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ private final class AnalysisCallback(
progress: Option[CompileProgress],
incHandlerOpt: Option[Incremental.IncrementalCallback],
log: Logger
) extends xsbti.AnalysisCallback2 {
) extends xsbti.AnalysisCallback3 {
import Incremental.CompileCycleResult

// This must have a unique value per AnalysisCallback
Expand Down Expand Up @@ -674,6 +674,8 @@ private final class AnalysisCallback(
()
}

override def toVirtualFile(path: Path): VirtualFile = converter.toVirtualFile(path)

override def problem2(
category: String,
pos: Position,
Expand Down

0 comments on commit b4a5377

Please sign in to comment.