[REPL] Add completion for the call named parameters
This commit is contained in:
+18
@@ -109,6 +109,24 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFunctionArgumentNames() = test {
|
||||||
|
run {
|
||||||
|
doCompile
|
||||||
|
code = """fun _sf(_someInt: Int = 42, _someString: String = "s") = 1"""
|
||||||
|
}
|
||||||
|
run {
|
||||||
|
doComplete
|
||||||
|
code = """_sf(_s"""
|
||||||
|
cursor = code.length
|
||||||
|
expect {
|
||||||
|
addCompletion("_sf(", "_sf(Int = ..., String = ...)", "Int", "method")
|
||||||
|
addCompletion("_someInt = ", "_someInt", "Int", "parameter")
|
||||||
|
addCompletion("_someString = ", "_someString", "String", "parameter")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testExtensionMethods() = test {
|
fun testExtensionMethods() = test {
|
||||||
run {
|
run {
|
||||||
|
|||||||
+35
-17
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||||
|
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||||
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
||||||
@@ -36,7 +37,6 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.asFlexibleType
|
import org.jetbrains.kotlin.types.asFlexibleType
|
||||||
import org.jetbrains.kotlin.types.isFlexible
|
import org.jetbrains.kotlin.types.isFlexible
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
|
||||||
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
import kotlin.script.experimental.api.ScriptCompilationConfiguration
|
||||||
import kotlin.script.experimental.api.SourceCodeCompletionVariant
|
import kotlin.script.experimental.api.SourceCodeCompletionVariant
|
||||||
|
|
||||||
@@ -115,21 +115,35 @@ private class KJvmReplCompleter(
|
|||||||
) return@gen
|
) return@gen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val containingCallId = simpleExpression.getParentOfType<KtCallExpression>(true)?.calleeExpression?.text
|
||||||
|
fun Name.test(checkAgainstContainingCall: Boolean): Boolean {
|
||||||
|
if (isSpecial) return false
|
||||||
|
if (nameFilter(identifier, prefix)) return true
|
||||||
|
return checkAgainstContainingCall && containingCallId?.let { nameFilter(identifier, it) } == true
|
||||||
|
}
|
||||||
|
|
||||||
isSortNeeded = false
|
isSortNeeded = false
|
||||||
descriptors = ReferenceVariantsHelper(
|
descriptors = ArrayList<DeclarationDescriptor>().also { result ->
|
||||||
bindingContext,
|
ReferenceVariantsHelper(
|
||||||
resolutionFacade,
|
bindingContext,
|
||||||
moduleDescriptor,
|
resolutionFacade,
|
||||||
VisibilityFilter(inDescriptor)
|
moduleDescriptor,
|
||||||
).getReferenceVariants(
|
VisibilityFilter(inDescriptor)
|
||||||
simpleExpression,
|
).getReferenceVariants(
|
||||||
DescriptorKindFilter.ALL,
|
simpleExpression,
|
||||||
{ name: Name -> !name.isSpecial && nameFilter(name.identifier, prefix) },
|
DescriptorKindFilter.ALL,
|
||||||
filterOutJavaGettersAndSetters = true,
|
{ it.test(true) },
|
||||||
filterOutShadowed = filterOutShadowedDescriptors, // setting to true makes it slower up to 4 times
|
filterOutJavaGettersAndSetters = true,
|
||||||
excludeNonInitializedVariable = true,
|
filterOutShadowed = filterOutShadowedDescriptors, // setting to true makes it slower up to 4 times
|
||||||
useReceiverType = null
|
excludeNonInitializedVariable = true,
|
||||||
)
|
useReceiverType = null
|
||||||
|
).forEach { descriptor ->
|
||||||
|
if (descriptor.name.test(false)) result.add(descriptor)
|
||||||
|
if (descriptor is CallableDescriptor && containingCallId == descriptor.name.identifier) {
|
||||||
|
descriptor.valueParameters.filterTo(result) { it.name.test(false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (element is KtStringTemplateExpression) {
|
} else if (element is KtStringTemplateExpression) {
|
||||||
if (element.hasInterpolation()) {
|
if (element.hasInterpolation()) {
|
||||||
@@ -348,7 +362,7 @@ private class KJvmReplCompleter(
|
|||||||
is ClassDescriptor -> "class"
|
is ClassDescriptor -> "class"
|
||||||
is PackageFragmentDescriptor -> "package"
|
is PackageFragmentDescriptor -> "package"
|
||||||
is PackageViewDescriptor -> "package"
|
is PackageViewDescriptor -> "package"
|
||||||
is ValueParameterDescriptor -> "genericValue"
|
is ValueParameterDescriptor -> "parameter"
|
||||||
is TypeParameterDescriptorImpl -> "class"
|
is TypeParameterDescriptorImpl -> "class"
|
||||||
else -> ""
|
else -> ""
|
||||||
}
|
}
|
||||||
@@ -396,13 +410,17 @@ private class KJvmReplCompleter(
|
|||||||
val outType =
|
val outType =
|
||||||
descriptor.type
|
descriptor.type
|
||||||
typeText = RENDERER.renderType(outType)
|
typeText = RENDERER.renderType(outType)
|
||||||
|
if (descriptor is ValueParameterDescriptor) {
|
||||||
|
completionText = "$rawDescriptorName = "
|
||||||
|
}
|
||||||
} else if (descriptor is ClassDescriptor) {
|
} else if (descriptor is ClassDescriptor) {
|
||||||
val declaredIn = descriptor.containingDeclaration
|
val declaredIn = descriptor.containingDeclaration
|
||||||
tailText = " (" + DescriptorUtils.getFqName(declaredIn) + ")"
|
tailText = " (" + DescriptorUtils.getFqName(declaredIn) + ")"
|
||||||
} else {
|
} else {
|
||||||
typeText = RENDERER.render(descriptor)
|
typeText = RENDERER.render(descriptor)
|
||||||
}
|
}
|
||||||
tailText = if (typeText.isEmpty()) tailText else typeText
|
|
||||||
|
tailText = typeText.ifEmpty { tailText }
|
||||||
|
|
||||||
if (completionText.isEmpty()) {
|
if (completionText.isEmpty()) {
|
||||||
completionText = presentableText
|
completionText = presentableText
|
||||||
|
|||||||
Reference in New Issue
Block a user