@@ -68,7 +68,7 @@ fun completions(file: CompiledFile, cursor: Int, index: SymbolIndex, config: Com
68
68
val elementItemLabels = elementItemList.mapNotNull { it.label }.toSet()
69
69
val items = (
70
70
elementItemList.asSequence()
71
- + (if (! isExhaustive) indexCompletionItems(file.parse , receiver, index, partial).filter { it.label !in elementItemLabels } else emptySequence())
71
+ + (if (! isExhaustive) indexCompletionItems(file, cursor , receiver, index, partial).filter { it.label !in elementItemLabels } else emptySequence())
72
72
+ (if (elementItemList.isEmpty()) keywordCompletionItems(partial) else emptySequence())
73
73
)
74
74
val itemList = items
@@ -81,7 +81,8 @@ fun completions(file: CompiledFile, cursor: Int, index: SymbolIndex, config: Com
81
81
}
82
82
83
83
/* * Finds completions in the global symbol index, for potentially unimported symbols. */
84
- private fun indexCompletionItems (parsedFile : KtFile , receiver : KtExpression ? , index : SymbolIndex , partial : String ): Sequence <CompletionItem > {
84
+ private fun indexCompletionItems (file : CompiledFile , cursor : Int , receiver : KtExpression ? , index : SymbolIndex , partial : String ): Sequence <CompletionItem > {
85
+ val parsedFile = file.parse
85
86
val imports = parsedFile.importDirectives
86
87
// TODO: Deal with alias imports
87
88
val wildcardPackages = imports
@@ -92,6 +93,8 @@ private fun indexCompletionItems(parsedFile: KtFile, receiver: KtExpression?, in
92
93
val importedNames = imports
93
94
.mapNotNull { it.importedFqName?.shortName() }
94
95
.toSet()
96
+ val receiverType = receiver?.let { expr -> file.scopeAtPoint(cursor)?.let { file.typeOfExpression(expr, it) } }
97
+ val receiverTypeFqName = receiverType?.constructor ?.declarationDescriptor?.fqNameSafe
95
98
96
99
return index
97
100
.query(partial, limit = MAX_COMPLETION_ITEMS )
@@ -104,6 +107,7 @@ private fun indexCompletionItems(parsedFile: KtFile, receiver: KtExpression?, in
104
107
|| it.visibility == Symbol .Visibility .PROTECTED
105
108
|| it.visibility == Symbol .Visibility .INTERNAL
106
109
}
110
+ .filter { receiverTypeFqName == it.extensionReceiverType } // if both are null, it's not an extension
107
111
.map { CompletionItem ().apply {
108
112
label = it.fqName.shortName().toString()
109
113
kind = when (it.kind) {
0 commit comments