Skip to content

Commit 4577255

Browse files
committed
fix: take into account preface for repl commands
1 parent 5e2c869 commit 4577255

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/repl/ReplDriver.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,15 @@ class ReplDriver(settings: Array[String],
220220
}
221221

222222
if expr.startsWith(":") then
223-
ParseResult.commands.map(command => makeCandidate(command._1))
223+
ParseResult.commands.collect {
224+
// If expr is only : then we return the commands with : since jline
225+
// correctly handles them
226+
case command if expr == ":" => makeCandidate(command._1)
227+
// However if there is more than just the : we filter by it and then
228+
// drop the : since jline will correctly complete it but you'll end up
229+
// with ::import for example instead of :import
230+
case command if command._1.startsWith(expr) => makeCandidate(command._1.drop(1))
231+
}
224232
else
225233
given state: State = newRun(state0)
226234
compiler

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,4 +207,12 @@ class TabcompleteTests extends ReplTest {
207207
tabComplete(":")
208208
)
209209
}
210+
211+
@Test def commandPreface = initially {
212+
// This looks odd, but if we return :doc here it will result in ::doc in the REPL
213+
assertEquals(
214+
List("doc"),
215+
tabComplete(":d")
216+
)
217+
}
210218
}

0 commit comments

Comments
 (0)