Skip to content

Commit cdbb1be

Browse files
authored
Merge pull request #4417 from ankitson/sort-repl-autocomplete
Fix #4390: Sort REPL autocomplete suggestions
2 parents e87a5d1 + c639cd4 commit cdbb1be

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ object Interactive {
218218
case (sel @ Select(qual, _)) :: _ => getMemberCompletions(qual)
219219
case _ => getScopeCompletions(ctx)
220220
}
221-
interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %")
222-
(completionPos, completions.toList)
221+
222+
val sortedCompletions = completions.toList.sortBy(_.name: Name)
223+
interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = $sortedCompletions%, %")
224+
(completionPos, sortedCompletions)
223225
}
224226

225227
/** Possible completions of members of `prefix` which are accessible when called inside `boundary` */

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ class TabcompleteTests extends ReplTest {
6565
List("\"", ")", "'", "¨", "£", ":", ",", ";", "@", "}", "[", "]")
6666
.foreach(src => assertTrue(tabComplete(src).suggestions.isEmpty))
6767
}
68+
69+
@Test def sortedCompletions: Unit =
70+
fromInitialState { implicit state =>
71+
val src = "class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }"
72+
compiler.compile(src).stateOrFail
73+
}
74+
.andThen { implicit state =>
75+
val expected = List("comp1", "comp2", "comp3")
76+
assertEquals(expected, tabComplete("(new Foo).comp").suggestions)
77+
}
6878
}

0 commit comments

Comments
 (0)