Skip to content

Commit

Permalink
Merge pull request #3739 from ckipp01/decode2
Browse files Browse the repository at this point in the history
fix: return an error when trying to decode tasty in Scala 2
  • Loading branch information
ckipp01 authored Mar 18, 2022
2 parents c2d8baa + b47c60d commit 4d583c7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,27 @@ final class FileDecoderProvider(
else DecoderResponse.failed(path.toURI, "Unsupported extension")
}

private def isScala3(path: AbsolutePath): Boolean = {
buildTargets
.scalaVersion(path)
.exists(version => ScalaVersions.isScala3Version(version))
}

private def decodeTasty(
path: AbsolutePath
): Future[DecoderResponse] = {
if (path.isScala)
if (path.isScala && isScala3(path)) {
selectClassFromScalaFileAndDecode(path.toURI, path, false)(
decodeFromTastyFile
)
else if (path.isTasty) {
} else if (path.isScala) {
Future.successful(
DecoderResponse.failed(
path.toURI,
"Decoding tasty is only supported in Scala 3 for now."
)
)
} else if (path.isTasty) {
findPathInfoForClassesPathFile(path) match {
case Some(pathInfo) => decodeFromTastyFile(pathInfo)
case None =>
Expand All @@ -305,8 +318,11 @@ final class FileDecoderProvider(
)
)
}
} else
Future.successful(DecoderResponse.failed(path.toURI, "Invalid extension"))
} else {
Future.successful(
DecoderResponse.failed(path.toURI, "Invalid extension")
)
}
}

private def findPathInfoFromJavaSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ class FileDecoderProviderLspSuite
Right(FileDecoderProviderLspSuite.tastySingle)
)

check(
"tasty-single-not-for-scala2",
s"""|/metals.json
|{
| "app": {
| "scalaVersion": "${V.scala213}"
| }
|}
|/app/src/main/scala/Main.scala
|package foo.bar.example
|object Main
|""".stripMargin,
"app/src/main/scala/Main.scala",
None,
"tasty-decoded",
Left("Decoding tasty is only supported in Scala 3 for now.")
)

check(
"decode-jar",
s"""
Expand Down

0 comments on commit 4d583c7

Please sign in to comment.