Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recover from invalid paths returned from Bloop diagnostics #3372

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}