diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index 096554064502..5cd531338e6d 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -218,8 +218,10 @@ object Interactive { case (sel @ Select(qual, _)) :: _ => getMemberCompletions(qual) case _ => getScopeCompletions(ctx) } - interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %") - (completionPos, completions.toList) + + val sortedCompletions = completions.toList.sortBy(_.name: Name) + interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = $sortedCompletions%, %") + (completionPos, sortedCompletions) } /** Possible completions of members of `prefix` which are accessible when called inside `boundary` */ diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 47c5e089d534..db84b55aa6bf 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -65,4 +65,14 @@ class TabcompleteTests extends ReplTest { List("\"", ")", "'", "¨", "£", ":", ",", ";", "@", "}", "[", "]") .foreach(src => assertTrue(tabComplete(src).suggestions.isEmpty)) } + + @Test def sortedCompletions: Unit = + fromInitialState { implicit state => + val src = "class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }" + compiler.compile(src).stateOrFail + } + .andThen { implicit state => + val expected = List("comp1", "comp2", "comp3") + assertEquals(expected, tabComplete("(new Foo).comp").suggestions) + } }