Skip to content

Commit

Permalink
Bring back old completions as a deprecated method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kordyjan committed Mar 28, 2024
1 parent c251f36 commit 73bb4cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions compiler/src/dotty/tools/repl/ReplDriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ReplDriver(settings: Array[String],
/* complete = */ false // if true adds space when completing
)
}
val comps = completions(line.cursor, line.line, state)
val comps = completionsWithSignatures(line.cursor, line.line, state)
candidates.addAll(comps.map(_.label).distinct.map(makeCandidate).asJava)
val lineWord = line.word()
comps.filter(c => c.label == lineWord && c.symbols.nonEmpty) match
Expand Down Expand Up @@ -255,8 +255,22 @@ class ReplDriver(settings: Array[String],
else
label

@deprecated("Use completionsWithSignatures instead", "3.4.2")
protected final def completions(cursor: Int, expr: String, state0: State): List[Candidate] =
completionsWithSignatures(cursor, expr, state0).map: c =>
new Candidate(
/* value = */ c.label,
/* displ = */ stripBackTicks(c.label), // displayed value
/* group = */ null, // can be used to group completions together
/* descr = */ null, // TODO use for documentation?
/* suffix = */ null,
/* key = */ null,
/* complete = */ false // if true adds space when completing
)
end completions

/** Extract possible completions at the index of `cursor` in `expr` */
protected final def completions(cursor: Int, expr: String, state0: State): List[Completion] =
protected final def completionsWithSignatures(cursor: Int, expr: String, state0: State): List[Completion] =
if expr.startsWith(":") then
ParseResult.commands.collect {
case command if command._1.startsWith(expr) => Completion(command._1, "", List())
Expand All @@ -275,7 +289,7 @@ class ReplDriver(settings: Array[String],
try Completion.completions(srcPos)._2 catch case NonFatal(_) => Nil
}
.getOrElse(Nil)
end completions
end completionsWithSignatures

protected def interpret(res: ParseResult, quiet: Boolean = false)(using state: State): State = {
res match {
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/repl/ReplTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na

/** Returns the `(<instance completions>, <companion completions>)`*/
def tabComplete(src: String)(implicit state: State): List[String] =
completions(src.length, src, state).map(_.label).sorted.distinct
completionsWithSignatures(src.length, src, state).map(_.label).sorted.distinct

extension [A](state: State)
infix def andThen(op: State ?=> A): A = op(using state)
Expand Down

0 comments on commit 73bb4cd

Please sign in to comment.