Skip to content

Commit

Permalink
Handle colons in file names when producing SemanticDB
Browse files Browse the repository at this point in the history
Fixes #15860
  • Loading branch information
kierendavies committed Aug 17, 2022
1 parent e560c2d commit 53e1adc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/semanticdb/Tools.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ object Tools:
def mkURIstring(path: Path): String =
// Calling `.toUri` on a relative path will convert it to absolute. Iteration through its parts instead preserves
// the resulting URI as relative.
val uriParts = for part <- path.asScala yield new java.net.URI(null, null, part.toString, null)
uriParts.mkString("/")
// To prevent colon `:` from being treated as a scheme separator, prepend a slash `/` to each part to trick the URI
// parser into treating it as an absolute path, and then strip the spurious leading slash from the final result.
val uriParts = for part <- path.asScala yield new java.net.URI(null, null, "/" + part.toString, null)
uriParts.mkString.stripPrefix("/")

/** Load SemanticDB TextDocument for a single Scala source file
*
Expand Down
3 changes: 3 additions & 0 deletions tests/semanticdb/expect/example-dir/FileInDir.expect.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package example

class FileInDir/*<-example::FileInDir#*/
3 changes: 3 additions & 0 deletions tests/semanticdb/expect/example-dir/FileInDir.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package example

class FileInDir
19 changes: 19 additions & 0 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,25 @@ Occurrences:
[6:19..6:20): U -> local0
[6:24..6:27): ??? -> scala/Predef.`???`().

expect/example-dir/FileInDir.scala
----------------------------------

Summary:
Schema => SemanticDB v4
Uri => example-dir/FileInDir.scala
Text => empty
Language => Scala
Symbols => 2 entries
Occurrences => 2 entries

Symbols:
example/FileInDir# => class FileInDir extends Object { self: FileInDir => +1 decls }
example/FileInDir#`<init>`(). => primary ctor <init> (): FileInDir

Occurrences:
[0:8..0:15): example <- example/
[2:6..2:15): FileInDir <- example/FileInDir#

expect/exports-example-Codec.scala
----------------------------------

Expand Down

0 comments on commit 53e1adc

Please sign in to comment.