Skip to content

Commit 57ca75c

Browse files
committed
fix: take into account preface for repl commands
1 parent f4a6e9e commit 57ca75c

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
@@ -211,7 +211,15 @@ class ReplDriver(settings: Array[String],
211211
}
212212

213213
if expr.startsWith(":") then
214-
ParseResult.commands.map(command => makeCandidate(command._1))
214+
ParseResult.commands.collect {
215+
// If expr is only : then we return the commands with : since jline
216+
// correctly handles them
217+
case command if expr == ":" => makeCandidate(command._1)
218+
// However if there is more than just the : we filter by it and then
219+
// drop the : since jline will correctly complete it but you'll end up
220+
// with ::import for example instead of :import
221+
case command if command._1.startsWith(expr) => makeCandidate(command._1.drop(1))
222+
}
215223
else
216224
given state: State = newRun(state0)
217225
compiler

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,12 @@ class TabcompleteTests extends ReplTest {
147147
tabComplete(":")
148148
)
149149
}
150+
151+
@Test def commandPreface = initially {
152+
// This looks odd, but if we return :doc here it will result in ::doc in the REPL
153+
assertEquals(
154+
List("doc"),
155+
tabComplete(":d")
156+
)
157+
}
150158
}

0 commit comments

Comments
 (0)