Merge pull request #6367 from eed3si9n/wip/pos-sourcefile

Make sure to also pass absolute sourceFile to sourceMappers, take 2
This commit is contained in:
eugene yokota 2021-03-07 15:09:50 -05:00 committed by GitHub
commit 571005efa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 11 deletions

View File

@ -94,7 +94,6 @@ import xsbti.{ FileConverter, Position }
import scala.annotation.nowarn
import scala.collection.immutable.ListMap
import scala.concurrent.duration._
import scala.util.Try
import scala.util.control.NonFatal
import scala.xml.NodeSeq
@ -470,16 +469,16 @@ object Defaults extends BuildCommon {
)
private[sbt] def toAbsoluteSource(fc: FileConverter)(pos: Position): Position = {
def isValid(path: String): Boolean = {
Try(Paths.get(path)).map(_ => true).getOrElse(false)
}
val newPath: Option[String] = pos
val newPath: Option[NioPath] = pos
.sourcePath()
.asScala
.filter(isValid)
.map { path =>
fc.toPath(VirtualFileRef.of(path)).toAbsolutePath.toString
.flatMap { path =>
try {
Some(fc.toPath(VirtualFileRef.of(path)))
} catch {
// catch all to trap wierd path injected by compiler, users, or plugins
case NonFatal(_) => None
}
}
newPath
@ -495,9 +494,14 @@ object Defaults extends BuildCommon {
override def pointerSpace(): Optional[String] = pos.pointerSpace()
override def sourcePath(): Optional[String] = Optional.of(path)
override def sourcePath(): Optional[String] = Optional.of(path.toAbsolutePath.toString)
override def sourceFile(): Optional[File] = pos.sourceFile()
override def sourceFile(): Optional[File] =
(try {
Some(path.toFile.getAbsoluteFile)
} catch {
case NonFatal(_) => None
}).toOptional
override def startOffset(): Optional[Integer] = pos.startOffset()