KT-34740 Make getImplicitReceiversWithInstanceToExpression keep script implicit receivers
- This makes completion aware of scripts implicit receivers (it matters in .gradle.kts files, for example) - ^KT-34740 Fixed
This commit is contained in:
committed by
Roman Golyshev
parent
be2fe256ba
commit
28e2d2faf2
@@ -83,6 +83,7 @@ fun LexicalScope.getImplicitReceiversWithInstanceToExpression(
|
|||||||
val owner = receiver.containingDeclaration
|
val owner = receiver.containingDeclaration
|
||||||
if (owner is ScriptDescriptor) {
|
if (owner is ScriptDescriptor) {
|
||||||
result[receiver] = null
|
result[receiver] = null
|
||||||
|
outerDeclarationsWithInstance.addAll(owner.implicitReceivers)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val (expressionText, isImmediateThis) = if (owner in outerDeclarationsWithInstance) {
|
val (expressionText, isImmediateThis) = if (owner in outerDeclarationsWithInstance) {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
foo<caret>
|
||||||
|
|
||||||
|
// EXIST: fooBase, fooImplicitBase
|
||||||
|
// NOTHING_ELSE
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
package custom.scriptDefinition
|
||||||
|
|
||||||
|
import kotlin.script.experimental.annotations.KotlinScript
|
||||||
|
import kotlin.script.experimental.jvm.dependenciesFromClassContext
|
||||||
|
import kotlin.script.experimental.jvm.jvm
|
||||||
|
import kotlin.script.experimental.api.*
|
||||||
|
|
||||||
|
@KotlinScript(
|
||||||
|
displayName = "Definition for tests",
|
||||||
|
fileExtension = "kts",
|
||||||
|
compilationConfiguration = TemplateDefinition::class
|
||||||
|
)
|
||||||
|
open class Template(val args: Array<String>)
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
object TemplateDefinition : ScriptCompilationConfiguration(
|
||||||
|
{
|
||||||
|
baseClass(Base::class)
|
||||||
|
jvm {
|
||||||
|
dependenciesFromClassContext(TemplateDefinition::class)
|
||||||
|
}
|
||||||
|
ide {
|
||||||
|
acceptedLocations(ScriptAcceptedLocation.Everywhere)
|
||||||
|
}
|
||||||
|
refineConfiguration {
|
||||||
|
beforeCompiling { (_, config, _) ->
|
||||||
|
config.with {
|
||||||
|
implicitReceivers(ImplicitBase::class)
|
||||||
|
}.asSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
open class Base {
|
||||||
|
fun fooBase() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ImplicitBase {
|
||||||
|
fun fooImplicitBase() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fooBase()
|
||||||
|
fooImplicitBase()
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
package custom.scriptDefinition
|
||||||
|
|
||||||
|
import kotlin.script.experimental.annotations.KotlinScript
|
||||||
|
import kotlin.script.experimental.jvm.dependenciesFromClassContext
|
||||||
|
import kotlin.script.experimental.jvm.jvm
|
||||||
|
import kotlin.script.experimental.api.*
|
||||||
|
|
||||||
|
@KotlinScript(
|
||||||
|
displayName = "Definition for tests",
|
||||||
|
fileExtension = "kts",
|
||||||
|
compilationConfiguration = TemplateDefinition::class
|
||||||
|
)
|
||||||
|
open class Template(val args: Array<String>)
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
object TemplateDefinition : ScriptCompilationConfiguration(
|
||||||
|
{
|
||||||
|
baseClass(Base::class)
|
||||||
|
jvm {
|
||||||
|
dependenciesFromClassContext(TemplateDefinition::class)
|
||||||
|
}
|
||||||
|
ide {
|
||||||
|
acceptedLocations(ScriptAcceptedLocation.Everywhere)
|
||||||
|
}
|
||||||
|
refineConfiguration {
|
||||||
|
beforeCompiling { (_, config, _) ->
|
||||||
|
config.with {
|
||||||
|
implicitReceivers(ImplicitBase::class)
|
||||||
|
}.asSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
open class Base {
|
||||||
|
fun fooBase() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ImplicitBase {
|
||||||
|
fun fooImplicitBase() {}
|
||||||
|
}
|
||||||
Generated
+5
@@ -37,4 +37,9 @@ public class ScriptConfigurationCompletionTestGenerated extends AbstractScriptCo
|
|||||||
public void testConflictingModuleJavaLib() throws Exception {
|
public void testConflictingModuleJavaLib() throws Exception {
|
||||||
runTest("idea/testData/script/definition/completion/conflictingModuleJavaLib/");
|
runTest("idea/testData/script/definition/completion/conflictingModuleJavaLib/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("implicitReceiver")
|
||||||
|
public void testImplicitReceiver() throws Exception {
|
||||||
|
runTest("idea/testData/script/definition/completion/implicitReceiver/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+5
@@ -95,6 +95,11 @@ public class ScriptConfigurationHighlightingTestGenerated extends AbstractScript
|
|||||||
runTest("idea/testData/script/definition/highlighting/errorResolver/");
|
runTest("idea/testData/script/definition/highlighting/errorResolver/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("implicitReceiver")
|
||||||
|
public void testImplicitReceiver() throws Exception {
|
||||||
|
runTest("idea/testData/script/definition/highlighting/implicitReceiver/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("javaNestedClass")
|
@TestMetadata("javaNestedClass")
|
||||||
public void testJavaNestedClass() throws Exception {
|
public void testJavaNestedClass() throws Exception {
|
||||||
runTest("idea/testData/script/definition/highlighting/javaNestedClass/");
|
runTest("idea/testData/script/definition/highlighting/javaNestedClass/");
|
||||||
|
|||||||
Reference in New Issue
Block a user