Skip to content

Commit

Permalink
fix: take into account preface for repl commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ckipp01 committed Mar 7, 2022
1 parent f4a6e9e commit 57ca75c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ class ReplDriver(settings: Array[String],
}

if expr.startsWith(":") then
ParseResult.commands.map(command => makeCandidate(command._1))
ParseResult.commands.collect {
// If expr is only : then we return the commands with : since jline
// correctly handles them
case command if expr == ":" => makeCandidate(command._1)
// However if there is more than just the : we filter by it and then
// drop the : since jline will correctly complete it but you'll end up
// with ::import for example instead of :import
case command if command._1.startsWith(expr) => makeCandidate(command._1.drop(1))
}
else
given state: State = newRun(state0)
compiler
Expand Down
8 changes: 8 additions & 0 deletions compiler/test/dotty/tools/repl/TabcompleteTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,12 @@ class TabcompleteTests extends ReplTest {
tabComplete(":")
)
}

@Test def commandPreface = initially {
// This looks odd, but if we return :doc here it will result in ::doc in the REPL
assertEquals(
List("doc"),
tabComplete(":d")
)
}
}

0 comments on commit 57ca75c

Please sign in to comment.