Skip to content

Fix #6208, #6605: Properly support toplevel defs in the IDE #6611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
}
}

def compile(sourceCode: String): Unit = {
val virtualFile = new VirtualFile(sourceCode)
def compileFromString(sourceCode: String): Unit = {
val virtualFile = new VirtualFile("compileFromString-${java.util.UUID.randomUUID().toString}")
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8")) // buffering is still advised by javadoc
writer.write(sourceCode)
writer.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ class InteractiveDriver(val settings: List[String]) extends Driver {
}

private def toSource(uri: URI, sourceCode: String): SourceFile = {
val virtualFile = new VirtualFile(uri.toString, Paths.get(uri).toString)
val path = Paths.get(uri)
val virtualFile = new VirtualFile(path.getFileName.toString, path.toString)
val writer = new BufferedWriter(new OutputStreamWriter(virtualFile.output, "UTF-8"))
writer.write(sourceCode)
writer.close()
Expand Down
9 changes: 1 addition & 8 deletions compiler/test/dotty/tools/DottyTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,7 @@ trait DottyTest extends ContextEscapeDetection {
def checkCompile(checkAfterPhase: String, source: String)(assertion: (tpd.Tree, Context) => Unit): Context = {
val c = compilerWithChecker(checkAfterPhase)(assertion)
val run = c.newRun
run.compile(source)
run.runContext
}

def checkCompile(checkAfterPhase: String, sources: List[String])(assertion: (tpd.Tree, Context) => Unit): Context = {
val c = compilerWithChecker(checkAfterPhase)(assertion)
val run = c.newRun
run.compile(sources)
run.compileFromString(source)
run.runContext
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ trait DottyBytecodeTest {

val compiler = new Compiler
val run = compiler.newRun
compiler.newRun.compile(source)
compiler.newRun.compileFromString(source)

checkOutput(ctx.settings.outputDir.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,13 @@ class HoverTest {
.hover(m3 to m4, hoverContent("Test.🤪"))

}

@Test def topLevel: Unit = {
code"""package hello
|val x: Int = 1
|val y = ${m1}this${m2}.x""".withSource
// The test framework will place the code above in a virtual file called Source0.scala,
// sp the top-level definitions should be enclosed in an object called `Source0$package`.
.hover(m1 to m2, hoverContent("hello.Source0$package.type(hello.Source0$package)"))
}
}