Skip to content

Fix #4390: Sort REPL autocomplete suggestions #4417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.toString))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smarter We have an ordering for Name that differs from the default String ordering. I am wondering if we should use it here? The Name ordering will not group type names and term names together

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they should be grouped together, but we should also not display type completions if we're not in a type context

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but that's probably out of the scope of this PR

}

/** Possible completions of members of `prefix` which are accessible when called inside `boundary` */
Expand Down
10 changes: 10 additions & 0 deletions compiler/test/dotty/tools/repl/TabcompleteTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}