Skip to content

Commit d670018

Browse files
authored
Merge pull request #15863 from zivver/semanticdb-urisyntaxexception
Handle colons in file names when producing SemanticDB
2 parents cf4dd05 + 53e1adc commit d670018

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

compiler/src/dotty/tools/dotc/semanticdb/Tools.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ object Tools:
1212
def mkURIstring(path: Path): String =
1313
// Calling `.toUri` on a relative path will convert it to absolute. Iteration through its parts instead preserves
1414
// the resulting URI as relative.
15-
val uriParts = for part <- path.asScala yield new java.net.URI(null, null, part.toString, null)
16-
uriParts.mkString("/")
15+
// To prevent colon `:` from being treated as a scheme separator, prepend a slash `/` to each part to trick the URI
16+
// parser into treating it as an absolute path, and then strip the spurious leading slash from the final result.
17+
val uriParts = for part <- path.asScala yield new java.net.URI(null, null, "/" + part.toString, null)
18+
uriParts.mkString.stripPrefix("/")
1719

1820
/** Load SemanticDB TextDocument for a single Scala source file
1921
*
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package example
2+
3+
class FileInDir/*<-example::FileInDir#*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package example
2+
3+
class FileInDir

tests/semanticdb/metac.expect

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3811,6 +3811,25 @@ Occurrences:
38113811
[6:19..6:20): U -> local0
38123812
[6:24..6:27): ??? -> scala/Predef.`???`().
38133813

3814+
expect/example-dir/FileInDir.scala
3815+
----------------------------------
3816+
3817+
Summary:
3818+
Schema => SemanticDB v4
3819+
Uri => example-dir/FileInDir.scala
3820+
Text => empty
3821+
Language => Scala
3822+
Symbols => 2 entries
3823+
Occurrences => 2 entries
3824+
3825+
Symbols:
3826+
example/FileInDir# => class FileInDir extends Object { self: FileInDir => +1 decls }
3827+
example/FileInDir#`<init>`(). => primary ctor <init> (): FileInDir
3828+
3829+
Occurrences:
3830+
[0:8..0:15): example <- example/
3831+
[2:6..2:15): FileInDir <- example/FileInDir#
3832+
38143833
expect/exports-example-Codec.scala
38153834
----------------------------------
38163835

0 commit comments

Comments
 (0)