Skip to content

Commit

Permalink
Recover from invalid paths returned from Bloop diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Dec 16, 2024
1 parent 60f7322 commit 82fdad2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ch.epfl.scala.bsp4j

import java.io.File
import java.net.URI
import java.nio.file.Paths
import java.nio.file.{NoSuchFileException, Paths}

import scala.build.errors.Severity
import scala.build.internal.WrapperParams
Expand Down Expand Up @@ -185,12 +185,19 @@ object ConsoleBloopBuildClient {
for {
line <- lineOpt
p <- path.toOption
lines = os.read.lines(p)
line <- if (line < lines.length) Some(lines(line)) else None
lines =
try
os.read.lines(p)
catch
case e: NoSuchFileException =>
logger.message(s"File not found: $p")
logger.error(e.getMessage)
Nil
line <- lines.lift(line)
} yield line
}
for (code <- codeOpt)
code.linesIterator.map(prefix + _).foreach(logger.error(_))
code.linesIterator.map(prefix + _).foreach(logger.error)
val canPrintUnderline = diag.getRange.getStart.getLine == diag.getRange.getEnd.getLine &&
diag.getRange.getStart.getCharacter != null &&
diag.getRange.getEnd.getCharacter != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,40 @@ trait RunScalacCompatTestDefinitions {
expect(r.out.trim() == macroSettings.mkString(", "))
}
}

if (actualScalaVersion.startsWith("3"))
test("-Ysafe-init-global doesnt crash the CLI when a dependency produces a warning") {
val (org, name, version) = ("hello-world", "test-safe-init-global-works", "0.0.1-SNAPSHOT")
val (depDir, mainDir) = ("dep", "main")
val (depPackage, depClass, depMethod) = ("hello", "DepMain", "x")
val expectedMessage = "Hello, world!"
TestInputs(
os.rel / depDir / "Main.scala" ->
s"""//> using publish.organization $org
|//> using publish.name $name
|//> using publish.version $version
|package $depPackage
|
|object $depClass {
| val $depMethod: Int = y
| val y: Int = $depMethod
|}
|""".stripMargin,
os.rel / mainDir / "Main.scala" ->
s"""//> using option -Ysafe-init-global
|//> using dep $org::$name:$version
|
|import $depPackage.$depClass
|
|object Main extends App {
| val a = $depClass.$depMethod
| println("$expectedMessage")
|}
|""".stripMargin
).fromRoot { root =>
os.proc(TestUtil.cli, "--power", "publish", "local", depDir, extraOptions).call(cwd = root)
val res = os.proc(TestUtil.cli, "run", mainDir, extraOptions).call(cwd = root)
expect(res.out.trim() == expectedMessage)
}
}
}

0 comments on commit 82fdad2

Please sign in to comment.