Dsl completion: fix completion when multiple receivers are in scope
This commit is contained in:
+5
-4
@@ -23,7 +23,7 @@ class DslMembersCompletion(
|
||||
private val indicesHelper: KotlinIndicesHelper,
|
||||
private val callTypeAndReceiver: CallTypeAndReceiver<*, *>
|
||||
) {
|
||||
private val nearestReceiver = receiverTypes?.lastOrNull()
|
||||
private val nearestReceiver = receiverTypes?.firstOrNull()
|
||||
private val nearestReceiverMarkers = nearestReceiver?.takeIf { it.implicit }
|
||||
?.let { DslMarkerUtils.extractDslMarkerFqNames(it.type) }.orEmpty()
|
||||
|
||||
@@ -55,7 +55,7 @@ class DslMembersCompletion(
|
||||
if (nearestReceiver == null || nearestReceiverMarkers.isEmpty()) return
|
||||
|
||||
val receiverMarkersShortNames = nearestReceiverMarkers.map { it.shortName() }.distinct()
|
||||
indicesHelper.getCallableTopLevelExtensions(
|
||||
val extensionDescriptors = indicesHelper.getCallableTopLevelExtensions(
|
||||
nameFilter = { prefixMatcher.prefixMatches(it) },
|
||||
declarationFilter = {
|
||||
(it as KtModifierListOwner).modifierList?.collectAnnotationEntriesFromStubOrPsi()?.any { it.shortName in receiverMarkersShortNames }
|
||||
@@ -63,8 +63,9 @@ class DslMembersCompletion(
|
||||
},
|
||||
callTypeAndReceiver = callTypeAndReceiver,
|
||||
receiverTypes = listOf(nearestReceiver.type)
|
||||
).forEach { descriptor: DeclarationDescriptor ->
|
||||
collector.addDescriptorElements(descriptor, factory, notImported = true, withReceiverCast = false, prohibitDuplicates = true)
|
||||
)
|
||||
extensionDescriptors.forEach {
|
||||
collector.addDescriptorElements(it, factory, notImported = true, withReceiverCast = false, prohibitDuplicates = true)
|
||||
}
|
||||
|
||||
collector.flushToResultSet()
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package dsl
|
||||
|
||||
import test.Dsl
|
||||
import test.R
|
||||
|
||||
@Dsl
|
||||
fun R.foo2() {}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// RUNTIME
|
||||
package test
|
||||
|
||||
class HasFoo {
|
||||
fun foo10() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val foo5 = 3
|
||||
with(0) {
|
||||
with("") {
|
||||
with(HasFoo()) {
|
||||
r {
|
||||
foo<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DslMarker
|
||||
annotation class Dsl
|
||||
|
||||
|
||||
@Dsl
|
||||
class R
|
||||
|
||||
fun r(body: R.() -> Unit) {
|
||||
|
||||
}
|
||||
|
||||
fun foo1(i: Int) {
|
||||
|
||||
}
|
||||
|
||||
// ORDER: foo2
|
||||
// ORDER: foo10
|
||||
// ORDER: foo1
|
||||
// ORDER: foo5
|
||||
+6
@@ -73,6 +73,12 @@ public class BasicCompletionWeigherTestGenerated extends AbstractBasicCompletion
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DslCallsWithMultipleReceivers.kt")
|
||||
public void testDslCallsWithMultipleReceivers() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/DslCallsWithMultipleReceivers.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExactMatchForKeyword.kt")
|
||||
public void testExactMatchForKeyword() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/ExactMatchForKeyword.kt");
|
||||
|
||||
Reference in New Issue
Block a user