@@ -205,7 +205,7 @@ class ReplDriver(settings: Array[String],
205205 label
206206
207207 /** Extract possible completions at the index of `cursor` in `expr` */
208- protected final def completions (cursor : Int , expr : String , state0 : State ): List [Candidate ] = {
208+ protected final def completions (cursor : Int , expr : String , state0 : State ): List [Candidate ] =
209209 def makeCandidate (label : String ) = {
210210
211211 new Candidate (
@@ -218,20 +218,24 @@ class ReplDriver(settings: Array[String],
218218 /* complete = */ false // if true adds space when completing
219219 )
220220 }
221- implicit val state = newRun(state0)
222- compiler
223- .typeCheck(expr, errorsAllowed = true )
224- .map { tree =>
225- val file = SourceFile .virtual(" <completions>" , expr, maybeIncomplete = true )
226- val unit = CompilationUnit (file)(using state.context)
227- unit.tpdTree = tree
228- given Context = state.context.fresh.setCompilationUnit(unit)
229- val srcPos = SourcePosition (file, Span (cursor))
230- val (_, completions) = Completion .completions(srcPos)
231- completions.map(_.label).distinct.map(makeCandidate)
232- }
233- .getOrElse(Nil )
234- }
221+
222+ if expr.startsWith(" :" ) then
223+ ParseResult .commands.map(command => makeCandidate(command._1))
224+ else
225+ given state : State = newRun(state0)
226+ compiler
227+ .typeCheck(expr, errorsAllowed = true )
228+ .map { tree =>
229+ val file = SourceFile .virtual(" <completions>" , expr, maybeIncomplete = true )
230+ val unit = CompilationUnit (file)(using state.context)
231+ unit.tpdTree = tree
232+ given Context = state.context.fresh.setCompilationUnit(unit)
233+ val srcPos = SourcePosition (file, Span (cursor))
234+ val (_, completions) = Completion .completions(srcPos)
235+ completions.map(_.label).distinct.map(makeCandidate)
236+ }
237+ .getOrElse(Nil )
238+ end completions
235239
236240 private def interpret (res : ParseResult )(implicit state : State ): State = {
237241 res match {
0 commit comments