Skip to content

Commit 400427d

Browse files
authored
Merge pull request #15064 from som-snytt/tweak/hovertest
SourceFile converts File.separator
2 parents 35b1084 + 0d35999 commit 400427d

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Denotations.Denotation
1111
import typer.Typer
1212
import typer.ImportInfo.withRootImports
1313
import Decorators._
14-
import io.{AbstractFile, VirtualFile}
14+
import io.AbstractFile
1515
import Phases.unfusedPhases
1616

1717
import util._

compiler/src/dotty/tools/dotc/interactive/InteractiveDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.util.zip._
1414
import scala.collection._
1515
import scala.io.Codec
1616

17-
import dotty.tools.io.{ AbstractFile, VirtualFile }
17+
import dotty.tools.io.AbstractFile
1818

1919
import ast.{Trees, tpd}
2020
import core._, core.Decorators._

compiler/src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import scala.collection.mutable
1515
import scala.collection.mutable.ArrayBuffer
1616
import scala.util.chaining.given
1717

18+
import java.io.File.separator
1819
import java.nio.charset.StandardCharsets
1920
import java.nio.file.{FileSystemException, NoSuchFileException}
2021
import java.util.Optional
@@ -217,8 +218,11 @@ object SourceFile {
217218

218219
implicit def fromContext(using Context): SourceFile = ctx.source
219220

221+
/** A source file with an underlying virtual file. The name is taken as a file system path
222+
* with the local separator converted to "/". The last element of the path will be the simple name of the file.
223+
*/
220224
def virtual(name: String, content: String, maybeIncomplete: Boolean = false) =
221-
SourceFile(new VirtualFile(name, content.getBytes(StandardCharsets.UTF_8)), content.toCharArray)
225+
SourceFile(new VirtualFile(name.replace(separator, "/"), content.getBytes(StandardCharsets.UTF_8)), content.toCharArray)
222226
.tap(_._maybeInComplete = maybeIncomplete)
223227

224228
/** Returns the relative path of `source` within the `reference` path

compiler/src/dotty/tools/io/VirtualDirectory.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ extends AbstractFile {
5656

5757
override def fileNamed(name: String): AbstractFile =
5858
Option(lookupName(name, directory = false)) getOrElse {
59-
val newFile = new VirtualFile(name, path + '/' + name)
59+
val newFile = new VirtualFile(name, s"$path/$name")
6060
files(name) = newFile
6161
newFile
6262
}

scaladoc/src/dotty/tools/scaladoc/DocContext.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import java.nio.file.Paths
88
import collection.JavaConverters._
99
import dotty.tools.scaladoc.site.StaticSiteContext
1010
import dotty.tools.dotc.core.Contexts._
11-
import dotty.tools.io.VirtualFile
1211
import dotty.tools.dotc.util.SourceFile
1312
import dotty.tools.dotc.util.SourcePosition
1413
import dotty.tools.dotc.util.Spans

0 commit comments

Comments
 (0)