From 73ac067caba4ddaaa8ab8c8c90d2de45cf5b5d28 Mon Sep 17 00:00:00 2001 From: Ankit Soni Date: Sun, 29 Apr 2018 08:47:45 -0700 Subject: [PATCH 1/4] Sort REPL autocomplete suggestions --- compiler/src/dotty/tools/dotc/interactive/Interactive.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index 096554064502..7089f3b9d78e 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -219,7 +219,7 @@ object Interactive { case _ => getScopeCompletions(ctx) } interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %") - (completionPos, completions.toList) + (completionPos, completions.toList.sortBy(_.name.show)) } /** Possible completions of members of `prefix` which are accessible when called inside `boundary` */ From 2e57ceaebca0783b7ef3ba0b571248ae2667ed75 Mon Sep 17 00:00:00 2001 From: Ankit Soni Date: Sun, 29 Apr 2018 21:33:39 -0700 Subject: [PATCH 2/4] tests & use _name.toString --- .../src/dotty/tools/dotc/interactive/Interactive.scala | 2 +- compiler/test/dotty/tools/repl/TabcompleteTests.scala | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index 7089f3b9d78e..eaba8369d464 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -219,7 +219,7 @@ object Interactive { case _ => getScopeCompletions(ctx) } interactiv.println(i"completion with pos = $pos, prefix = $prefix, termOnly = $termOnly, typeOnly = $typeOnly = ${completions.toList}%, %") - (completionPos, completions.toList.sortBy(_.name.show)) + (completionPos, completions.toList.sortBy(_.name.toString)) } /** 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..8644d98fe5a5 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 comp1 = 1; def compa = 3; def compA = 4 }""" + compiler.compile(src).stateOrFail + } + .andThen { implicit state => + val expected = List("comp1", "compA", "compa") + assertEquals(expected, tabComplete("(new Foo).comp").suggestions) + } } From d1dc25bffea89f69d3e81cac3e4c50d2f2b3fd12 Mon Sep 17 00:00:00 2001 From: Ankit Soni Date: Mon, 30 Apr 2018 08:23:49 -0700 Subject: [PATCH 3/4] pr feedback --- compiler/test/dotty/tools/repl/TabcompleteTests.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/test/dotty/tools/repl/TabcompleteTests.scala b/compiler/test/dotty/tools/repl/TabcompleteTests.scala index 8644d98fe5a5..db84b55aa6bf 100644 --- a/compiler/test/dotty/tools/repl/TabcompleteTests.scala +++ b/compiler/test/dotty/tools/repl/TabcompleteTests.scala @@ -68,11 +68,11 @@ class TabcompleteTests extends ReplTest { @Test def sortedCompletions: Unit = fromInitialState { implicit state => - val src = """class Foo { def comp1 = 1; def compa = 3; def compA = 4 }""" + val src = "class Foo { def comp3 = 3; def comp1 = 1; def comp2 = 2 }" compiler.compile(src).stateOrFail } .andThen { implicit state => - val expected = List("comp1", "compA", "compa") + val expected = List("comp1", "comp2", "comp3") assertEquals(expected, tabComplete("(new Foo).comp").suggestions) } } From c639cd43e1c497b1f28bb58e95e4a3560a0ac046 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 1 May 2018 10:32:55 +0200 Subject: [PATCH 4/4] Sort completions by 'Name' --- compiler/src/dotty/tools/dotc/interactive/Interactive.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index eaba8369d464..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.sortBy(_.name.toString)) + + 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` */