@@ -249,6 +249,8 @@ private fun completableElement(file: CompiledFile, cursor: Int): KtElement? {
249
249
? : el.parent?.parent as ? KtQualifiedExpression
250
250
// ?
251
251
? : el as ? KtNameReferenceExpression
252
+ // x ? y (infix)
253
+ ? : el.parent as ? KtBinaryExpression
252
254
}
253
255
254
256
private fun elementCompletions (file : CompiledFile , cursor : Int , surroundingElement : KtElement ): Sequence <DeclarationDescriptor > {
@@ -319,13 +321,27 @@ private fun elementCompletions(file: CompiledFile, cursor: Int, surroundingEleme
319
321
val scope = file.scopeAtPoint(surroundingElement.startOffset) ? : return noResult(" No scope at ${file.describePosition(cursor)} " , emptySequence())
320
322
identifiers(scope)
321
323
}
324
+ // x ? y (infix)
325
+ is KtBinaryExpression -> {
326
+ if (surroundingElement.operationToken == KtTokens .IDENTIFIER ) {
327
+ completeMembers(file, cursor, surroundingElement.left!! )
328
+ } else emptySequence()
329
+ }
322
330
else -> {
323
331
LOG .info(" {} {} didn't look like a type, a member, or an identifier" , surroundingElement::class .simpleName, surroundingElement.text)
324
332
emptySequence()
325
333
}
326
334
}
327
335
}
328
336
337
+ private fun receiverDescriptors (exp : KtExpression , vararg descriptors : Sequence <DeclarationDescriptor >): Sequence <DeclarationDescriptor > {
338
+ val seq = sequenceOf(* descriptors).flatten()
339
+ if (exp.parent !is KtBinaryExpression ) return seq
340
+
341
+ // filter if infix call
342
+ return seq.filter { declarationIsInfix(it) }
343
+ }
344
+
329
345
private fun completeMembers (file : CompiledFile , cursor : Int , receiverExpr : KtExpression , unwrapNullable : Boolean = false): Sequence <DeclarationDescriptor > {
330
346
// thingWithType.?
331
347
var descriptors = emptySequence<DeclarationDescriptor >()
@@ -341,7 +357,7 @@ private fun completeMembers(file: CompiledFile, cursor: Int, receiverExpr: KtExp
341
357
LOG .debug(" Completing members of instance '{}'" , receiverType)
342
358
val members = receiverType.memberScope.getContributedDescriptors().asSequence()
343
359
val extensions = extensionFunctions(lexicalScope).filter { isExtensionFor(receiverType, it) }
344
- descriptors = members + extensions
360
+ descriptors = receiverDescriptors(receiverExpr, members, extensions)
345
361
346
362
if (! isCompanionOfEnum(receiverType) && ! isCompanionOfSealed(receiverType)) {
347
363
return descriptors
@@ -370,6 +386,11 @@ private fun ClassDescriptor.getDescriptors(): Sequence<DeclarationDescriptor> {
370
386
371
387
}
372
388
389
+ private fun declarationIsInfix (declaration : DeclarationDescriptor ): Boolean {
390
+ val functionDescriptor = declaration as ? FunctionDescriptor ? : return false
391
+ return functionDescriptor.isInfix
392
+ }
393
+
373
394
private fun isCompanionOfEnum (kotlinType : KotlinType ): Boolean {
374
395
val classDescriptor = TypeUtils .getClassDescriptor(kotlinType)
375
396
val isCompanion = DescriptorUtils .isCompanionObject(classDescriptor)
0 commit comments