mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
EA-256745 Fix IllegalArgumentException in PyMultipleArgumentsCompletionContributor
(cherry picked from commit 4ee05e67c7b76c19627cb5e7018db71c96c41ebe) IJ-MR-6318 GitOrigin-RevId: a1f4717881c910c84c6458a28a0caab6217bba55
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a8128ea212
commit
135babbf04
@@ -28,7 +28,7 @@ class PyMultipleArgumentsCompletionContributor: CompletionContributor() {
|
||||
private object MyCompletionProvider : CompletionProvider<CompletionParameters>() {
|
||||
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet) {
|
||||
val position = parameters.position
|
||||
val argumentIndex = getArgumentIndex(position) ?: return
|
||||
val argumentExplicitIndex = getArgumentIndex(position) ?: return
|
||||
|
||||
val call = PsiTreeUtil.getParentOfType(position, PyCallExpression::class.java) ?: return
|
||||
val typeEvalContext = parameters.getTypeEvalContext()
|
||||
@@ -41,9 +41,14 @@ class PyMultipleArgumentsCompletionContributor: CompletionContributor() {
|
||||
|
||||
callableTypes.forEach { callableType ->
|
||||
val callableParameters = callableType.getParameters(typeEvalContext)
|
||||
if (callableParameters == null || callableParameters.any { it.isKeywordContainer || it.isPositionalContainer }) return@forEach
|
||||
val argumentIndex = callableType.implicitOffset + argumentExplicitIndex
|
||||
if (callableParameters == null ||
|
||||
argumentIndex >= callableParameters.size ||
|
||||
callableParameters.any { it.isKeywordContainer || it.isPositionalContainer }) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val unfilledParameters = ContainerUtil.subList(callableParameters, argumentIndex + callableType.implicitOffset)
|
||||
val unfilledParameters = ContainerUtil.subList(callableParameters, argumentIndex)
|
||||
val variables = collectVariablesToComplete(unfilledParameters, names)
|
||||
if (variables.size > 1) {
|
||||
result.addElement(createParametersLookupElement(variables, call))
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
def foo(x):
|
||||
pass
|
||||
|
||||
x = 42
|
||||
y = 42
|
||||
z = 42
|
||||
foo(x, y, <caret>)
|
||||
@@ -0,0 +1,9 @@
|
||||
class C:
|
||||
def foo(self, x, y):
|
||||
pass
|
||||
|
||||
def bar(self):
|
||||
x = 22
|
||||
y = 33
|
||||
z = 44
|
||||
self.foo(x, y, z, <caret>)
|
||||
@@ -97,6 +97,14 @@ class PyMultipleArgumentsCompletionTest: PyTestCase() {
|
||||
assertEquals(1, doTestByTestName().count { it == "x" })
|
||||
}
|
||||
|
||||
fun testNoExceptionIfMoreArgumentsThanParameters() {
|
||||
doTestByTestName()
|
||||
}
|
||||
|
||||
fun testNoExceptionIfMoreArgumentsWithImplicitThanParameters() {
|
||||
doTestByTestName()
|
||||
}
|
||||
|
||||
private fun doTestByTestName(): List<String?> {
|
||||
val testName = "multipleArgumentsCompletion/${getTestName(true)}"
|
||||
myFixture.configureByFile("$testName.py")
|
||||
|
||||
Reference in New Issue
Block a user