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 indicesHelper: KotlinIndicesHelper,
|
||||||
private val callTypeAndReceiver: CallTypeAndReceiver<*, *>
|
private val callTypeAndReceiver: CallTypeAndReceiver<*, *>
|
||||||
) {
|
) {
|
||||||
private val nearestReceiver = receiverTypes?.lastOrNull()
|
private val nearestReceiver = receiverTypes?.firstOrNull()
|
||||||
private val nearestReceiverMarkers = nearestReceiver?.takeIf { it.implicit }
|
private val nearestReceiverMarkers = nearestReceiver?.takeIf { it.implicit }
|
||||||
?.let { DslMarkerUtils.extractDslMarkerFqNames(it.type) }.orEmpty()
|
?.let { DslMarkerUtils.extractDslMarkerFqNames(it.type) }.orEmpty()
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ class DslMembersCompletion(
|
|||||||
if (nearestReceiver == null || nearestReceiverMarkers.isEmpty()) return
|
if (nearestReceiver == null || nearestReceiverMarkers.isEmpty()) return
|
||||||
|
|
||||||
val receiverMarkersShortNames = nearestReceiverMarkers.map { it.shortName() }.distinct()
|
val receiverMarkersShortNames = nearestReceiverMarkers.map { it.shortName() }.distinct()
|
||||||
indicesHelper.getCallableTopLevelExtensions(
|
val extensionDescriptors = indicesHelper.getCallableTopLevelExtensions(
|
||||||
nameFilter = { prefixMatcher.prefixMatches(it) },
|
nameFilter = { prefixMatcher.prefixMatches(it) },
|
||||||
declarationFilter = {
|
declarationFilter = {
|
||||||
(it as KtModifierListOwner).modifierList?.collectAnnotationEntriesFromStubOrPsi()?.any { it.shortName in receiverMarkersShortNames }
|
(it as KtModifierListOwner).modifierList?.collectAnnotationEntriesFromStubOrPsi()?.any { it.shortName in receiverMarkersShortNames }
|
||||||
@@ -63,8 +63,9 @@ class DslMembersCompletion(
|
|||||||
},
|
},
|
||||||
callTypeAndReceiver = callTypeAndReceiver,
|
callTypeAndReceiver = callTypeAndReceiver,
|
||||||
receiverTypes = listOf(nearestReceiver.type)
|
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()
|
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);
|
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")
|
@TestMetadata("ExactMatchForKeyword.kt")
|
||||||
public void testExactMatchForKeyword() throws Exception {
|
public void testExactMatchForKeyword() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/ExactMatchForKeyword.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/weighers/basic/ExactMatchForKeyword.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user