diff --git a/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala b/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala index 8fe949fbbad..cf45826ee98 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/BuildTargetInfo.scala @@ -5,6 +5,7 @@ import java.nio.file.Path import scala.collection.mutable.ListBuffer import scala.meta.internal.metals.MetalsEnrichments._ +import scala.meta.internal.mtags.URIEncoderDecoder import ch.epfl.scala.bsp4j.BuildTarget import ch.epfl.scala.bsp4j.BuildTargetIdentifier diff --git a/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala b/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala index 096b1dd6082..697eb19aa00 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala +++ b/metals/src/main/scala/scala/meta/internal/metals/FileDecoderProvider.scala @@ -25,6 +25,7 @@ import scala.meta.internal.metals.clients.language.MetalsQuickPickItem import scala.meta.internal.metals.clients.language.MetalsQuickPickParams import scala.meta.internal.metap.Main import scala.meta.internal.mtags.SemanticdbClasspath +import scala.meta.internal.mtags.URIEncoderDecoder import scala.meta.internal.parsing.ClassFinder import scala.meta.internal.parsing.ClassWithPos import scala.meta.io.AbsolutePath diff --git a/metals/src/main/scala/scala/meta/internal/metals/URIEncoderDecoder.scala b/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala similarity index 96% rename from metals/src/main/scala/scala/meta/internal/metals/URIEncoderDecoder.scala rename to mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala index 0955bcbeb57..989294efe2f 100644 --- a/metals/src/main/scala/scala/meta/internal/metals/URIEncoderDecoder.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/metals/URIEncoderDecoder.scala @@ -1,4 +1,4 @@ -package scala.meta.internal.metals +package scala.meta.internal.mtags object URIEncoderDecoder { diff --git a/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala b/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala index ebb36895945..5601e3b5f16 100644 --- a/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala +++ b/mtags/src/main/scala-2/scala/meta/internal/mtags/MtagsEnrichments.scala @@ -133,8 +133,13 @@ trait MtagsEnrichments extends CommonMtagsEnrichments { URLDecoder.decode(value, "UTF-8").toAbsolutePath(followSymlink) else if (value.toUpperCase.startsWith("JAR:FILE%3A")) URLDecoder.decode(value, "UTF-8").toAbsolutePath(followSymlink) - else - URI.create(value.stripPrefix("metals:")).toAbsolutePath(followSymlink) + else if (value.toUpperCase.startsWith("JAR")) + URI.create(value).toAbsolutePath(followSymlink) + else { + val stripped = value.stripPrefix("metals:") + val percentEncoded = URIEncoderDecoder.encode(stripped) + URI.create(percentEncoded).toAbsolutePath(followSymlink) + } } def lastIndexBetween( char: Char, diff --git a/tests/unit/src/test/scala/tests/MetalsEnrichmentsSuite.scala b/tests/unit/src/test/scala/tests/MetalsEnrichmentsSuite.scala index 837cfb3b0e0..aba9204d54a 100644 --- a/tests/unit/src/test/scala/tests/MetalsEnrichmentsSuite.scala +++ b/tests/unit/src/test/scala/tests/MetalsEnrichmentsSuite.scala @@ -22,10 +22,18 @@ class MetalsEnrichmentsSuite extends BaseSuite { assertEquals(relativeCreated, expected) } - test("uri-to-absolute-path") { + test("dont-decode-uri") { val uri = "file:///Users/happyMetalsUser/hello%20space%20world/src/main/scala/Main.scala" val path = uri.toAbsolutePath assert(path.toString().contains("hello space world")) } + + test("encode-uri-space") { + val uri = + "file:///Users/happyMetalsUser/hello space+world/src/main/scala/Main.scala" + val path = uri.toAbsolutePath + assert(path.toString().contains("hello space+world")) + } + } diff --git a/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala b/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala index fc2e677c1e5..ae6055946ef 100644 --- a/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala +++ b/tests/unit/src/test/scala/tests/UriEncoderDecoderSuite.scala @@ -1,6 +1,6 @@ package tests -import scala.meta.internal.metals.URIEncoderDecoder +import scala.meta.internal.mtags.URIEncoderDecoder class UriEncoderDecoderSuite extends BaseSuite {