Skip to content

Commit 0c16bb2

Browse files
committed
Only sort completions by distance if partial is not empty
Otherwise, the shortest completions would always show up first, which is not necessarily always desired. For example, if the user types a member (.?) expression, it would be better to show relevant members on top instead of those with the shortest name.
1 parent c53b05a commit 0c16bb2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

server/src/main/kotlin/org/javacs/kt/completion/Completions.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ private fun elementCompletionItems(file: CompiledFile, cursor: Int, config: Comp
7676
val surroundingElement = completableElement(file, cursor) ?: return emptySequence()
7777
val completions = elementCompletions(file, cursor, surroundingElement)
7878

79-
val matchesName = completions
80-
.filter { containsCharactersInOrder(name(it), partial, false) }
81-
.sortedBy { stringDistance(name(it), partial) }
82-
val visible = matchesName.filter(isVisible(file, cursor))
79+
val matchesName = completions.filter { containsCharactersInOrder(name(it), partial, false) }
80+
val sorted = matchesName.takeIf { partial.isNotEmpty() }?.sortedBy { stringDistance(name(it), partial) } ?: matchesName
81+
val visible = sorted.filter(isVisible(file, cursor))
8382

8483
return visible.map { completionItem(it, surroundingElement, file, config) }
8584
}

0 commit comments

Comments
 (0)