Skip to content

Commit 377f622

Browse files
committed
Fix #4978: Make completion context sensitive
Completions used to pick the runContext as completion context. However in the REPL, the run context does not hold the import informations
1 parent 453ee6b commit 377f622

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ object Interactive {
329329

330330
def contextOfPath(path: List[Tree])(implicit ctx: Context): Context = path match {
331331
case Nil | _ :: Nil =>
332-
ctx.run.runContext.fresh.setCompilationUnit(ctx.compilationUnit)
332+
ctx.fresh.setCompilationUnit(ctx.compilationUnit)
333333
case nested :: encl :: rest =>
334334
import typer.Typer._
335335
val outer = contextOfPath(encl :: rest)

compiler/test/dotty/tools/repl/TabcompleteTests.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,24 @@ class TabcompleteTests extends ReplTest {
6060
val expected = List("comp1", "comp2", "comp3")
6161
assertEquals(expected, tabComplete("(new Foo).comp").sorted)
6262
}
63+
64+
@Test def completeFromPreviousState2 =
65+
fromInitialState { implicit state =>
66+
val src = "def hello = 1"
67+
run(src)
68+
}
69+
.andThen { implicit state =>
70+
val expected = List("hello")
71+
assertEquals(expected, tabComplete("hel"))
72+
}
73+
74+
@Test def tabCompleteFromPreviousImport =
75+
fromInitialState { implicit state =>
76+
val src = "import java.io.FileDescriptor"
77+
run(src)
78+
}
79+
.andThen { implicit state =>
80+
val expected = List("FileDescriptor")
81+
assertEquals(expected, tabComplete("val foo: FileDesc"))
82+
}
6383
}

0 commit comments

Comments
 (0)