@@ -8,6 +8,15 @@ import dotty.tools.dotc.semanticdb.Scala3.{_, given _}
8
8
9
9
object Tools :
10
10
11
+ /** Converts a Path to a String that is URI encoded, without forcing absolute paths.
12
+ *
13
+ * Calling `.toUri` on a relative path will convert it to absolute. Iteration through its parts instead preserves
14
+ * the resulting URI as relative.
15
+ */
16
+ def mkURIstring (path : Path ): String =
17
+ val uriParts = for part <- path.asScala yield new java.net.URI (null , null , part.toString, null )
18
+ uriParts.mkString(" /" )
19
+
11
20
/** Load SemanticDB TextDocument for a single Scala source file
12
21
*
13
22
* @param scalaAbsolutePath Absolute path to a Scala source file.
@@ -19,16 +28,16 @@ object Tools:
19
28
scalaRelativePath : Path ,
20
29
semanticdbAbsolutePath : Path
21
30
): TextDocument =
22
- val reluri = scalaRelativePath.toString
31
+ val reluri = mkURIstring( scalaRelativePath)
23
32
val sdocs = parseTextDocuments(semanticdbAbsolutePath)
24
33
sdocs.documents.find(_.uri == reluri) match
25
- case None => throw new NoSuchElementException (reluri )
34
+ case None => throw new NoSuchElementException (s " $scalaRelativePath " )
26
35
case Some (document) =>
27
36
val text = new String (Files .readAllBytes(scalaAbsolutePath), StandardCharsets .UTF_8 )
28
37
// Assert the SemanticDB payload is in-sync with the contents of the Scala file on disk.
29
38
val md5FingerprintOnDisk = internal.MD5 .compute(text)
30
39
if document.md5 != md5FingerprintOnDisk
31
- throw new IllegalArgumentException (" stale semanticdb: " + reluri )
40
+ throw new IllegalArgumentException (s " stale semanticdb: $scalaRelativePath " )
32
41
else
33
42
// Update text document to include full text contents of the file.
34
43
document.copy(text = text)
0 commit comments