Fix scripting REPL completion after literals
This commit is contained in:
committed by
Ilya Chernikov
parent
d2fec96f38
commit
400ea13f07
+17
@@ -62,6 +62,23 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNoVariantsAfterLiterals() = test {
|
||||
fun testNoVariants(testCode: String, testCursor: Int? = null) = run {
|
||||
doComplete
|
||||
code = testCode
|
||||
cursor = testCursor ?: testCode.length
|
||||
expect {
|
||||
completionsMode(ComparisonType.EQUALS)
|
||||
}
|
||||
}
|
||||
|
||||
testNoVariants("val x1 = 42")
|
||||
testNoVariants("val x2 = 42.42")
|
||||
testNoVariants("val x3 = 'v'")
|
||||
testNoVariants("val x4 = \"str42\"")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun testPackagesImport() = test {
|
||||
|
||||
+13
-1
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
|
||||
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -90,6 +91,17 @@ private class KJvmReplCompleter(
|
||||
if (simpleExpression != null) {
|
||||
val inDescriptor: DeclarationDescriptor = simpleExpression.getResolutionScope(bindingContext, resolutionFacade).ownerDescriptor
|
||||
val prefix = element.text.substring(0, cursor - element.startOffset)
|
||||
|
||||
val elementParent = element.parent
|
||||
if (prefix.isEmpty() && elementParent is KtBinaryExpression) {
|
||||
when (elementParent.node.firstChildNode.elementType) {
|
||||
KtStubElementTypes.INTEGER_CONSTANT,
|
||||
KtStubElementTypes.FLOAT_CONSTANT,
|
||||
KtStubElementTypes.CHARACTER_CONSTANT,
|
||||
KtStubElementTypes.STRING_TEMPLATE -> return@gen
|
||||
}
|
||||
}
|
||||
|
||||
isSortNeeded = false
|
||||
descriptors = ReferenceVariantsHelper(
|
||||
bindingContext,
|
||||
@@ -246,7 +258,7 @@ private class KJvmReplCompleter(
|
||||
}
|
||||
}
|
||||
|
||||
private inner class VisibilityFilter(
|
||||
private class VisibilityFilter(
|
||||
private val inDescriptor: DeclarationDescriptor
|
||||
) : (DeclarationDescriptor) -> Boolean {
|
||||
override fun invoke(descriptor: DeclarationDescriptor): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user