Skip to content

Commit 3323d5d

Browse files
committed
fix: don't split :<word> into two tokens.
In the situation where we have `:im<tab>` normally `:` and `im` would be split into two tokens and it would result in `::imports`. Instead, we detect early if we are about to complete a command and instead of parsing it normally like Scala we just grab the entire thing as the word.
1 parent 4577255 commit 3323d5d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ final class JLineTerminal extends java.io.Closeable {
152152
// using dummy values, resulting parsed input is probably unused
153153
defaultParsedLine
154154

155+
// In the situation where we have a partial command that we want to
156+
// complete we need to ensure that the :<partial-word> isn't split into
157+
// 2 tokens, but rather the entire thing is treated as the "word", in
158+
// order to insure the : is replaced in the completion.
159+
case ParseContext.COMPLETE if
160+
ParseResult.commands.exists(command => command._1.startsWith(input)) =>
161+
parsedLine(input, cursor)
162+
155163
case ParseContext.COMPLETE =>
156164
// Parse to find completions (typically after a Tab).
157165
def isCompletable(token: Token) = isIdentifier(token) || isKeyword(token)

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,7 @@ class ReplDriver(settings: Array[String],
221221

222222
if expr.startsWith(":") then
223223
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))
224+
case command if command._1.startsWith(expr) => makeCandidate(command._1)
231225
}
232226
else
233227
given state: State = newRun(state0)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class TabcompleteTests extends ReplTest {
211211
@Test def commandPreface = initially {
212212
// This looks odd, but if we return :doc here it will result in ::doc in the REPL
213213
assertEquals(
214-
List("doc"),
214+
List(":doc"),
215215
tabComplete(":d")
216216
)
217217
}

0 commit comments

Comments
 (0)