@@ -60,9 +60,10 @@ fun completions(file: CompiledFile, cursor: Int, index: SymbolIndex, config: Com
60
60
LOG .debug(" Looking for completions that match '{}'" , partial)
61
61
62
62
// TODO: Filter non-imported (i.e. the elementCompletions already found) and auto-import these when selected by the user
63
- val elementItems = elementCompletionItems(file, cursor, config, partial)
63
+ val ( elementItems, isExhaustive) = elementCompletionItems(file, cursor, config, partial)
64
64
val elementItemList = elementItems.take(MAX_COMPLETION_ITEMS ).toList()
65
- val items = (elementItemList.asSequence() + indexCompletionItems(index, partial)).ifEmpty { keywordCompletionItems(partial) }
65
+ val items = (elementItemList.asSequence() + if (isExhaustive) emptySequence() else indexCompletionItems(index, partial))
66
+ .ifEmpty { keywordCompletionItems(partial) }
66
67
val itemList = items
67
68
.take(MAX_COMPLETION_ITEMS )
68
69
.toList()
@@ -101,17 +102,20 @@ private fun keywordCompletionItems(partial: String): Sequence<CompletionItem> =
101
102
kind = CompletionItemKind .Keyword
102
103
} }
103
104
105
+ data class ElementCompletionItems (val items : Sequence <CompletionItem >, val isExhaustive : Boolean )
106
+
104
107
/* * Finds completions based on the element around the user's cursor. */
105
- private fun elementCompletionItems (file : CompiledFile , cursor : Int , config : CompletionConfiguration , partial : String ): Sequence <CompletionItem > {
106
- val surroundingElement = completableElement(file, cursor) ? : return emptySequence()
108
+ private fun elementCompletionItems (file : CompiledFile , cursor : Int , config : CompletionConfiguration , partial : String ): ElementCompletionItems {
109
+ val surroundingElement = completableElement(file, cursor) ? : return ElementCompletionItems (emptySequence(), isExhaustive = false )
110
+ val isExhaustive = surroundingElement !is KtNameReferenceExpression && surroundingElement !is KtTypeElement
107
111
val completions = elementCompletions(file, cursor, surroundingElement)
108
112
109
113
val matchesName = completions.filter { containsCharactersInOrder(name(it), partial, caseSensitive = false ) }
110
114
val sorted = matchesName.takeIf { partial.length >= MIN_SORT_LENGTH }?.sortedBy { stringDistance(name(it), partial) }
111
115
? : matchesName.sortedBy { if (name(it).startsWith(partial)) 0 else 1 }
112
116
val visible = sorted.filter(isVisible(file, cursor))
113
117
114
- return visible.map { completionItem(it, surroundingElement, file, config) }
118
+ return ElementCompletionItems ( visible.map { completionItem(it, surroundingElement, file, config) }, isExhaustive)
115
119
}
116
120
117
121
private val callPattern = Regex (" (.*)\\ ((?:\\ $\\ d+)?\\ )(?:\\ $0)?" )
0 commit comments