Skip to content
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)
}
}