Better position of argument name hint for multiline varargs
#KT-20614 Fixed
This commit is contained in:
@@ -27,12 +27,12 @@ fun provideArgumentNameHints(element: KtCallElement): List<InlayInfo> {
|
||||
val call = element.getCall(ctx) ?: return emptyList()
|
||||
val resolvedCall = call.getResolvedCall(ctx)
|
||||
if (resolvedCall != null) {
|
||||
return getArgumentNameHintsForCallCandidate(resolvedCall)
|
||||
return getArgumentNameHintsForCallCandidate(resolvedCall, call.valueArgumentList)
|
||||
}
|
||||
val candidates = call.resolveCandidates(ctx, element.getResolutionFacade())
|
||||
if (candidates.isEmpty()) return emptyList()
|
||||
candidates.singleOrNull()?.let { return getArgumentNameHintsForCallCandidate(it) }
|
||||
return candidates.map { getArgumentNameHintsForCallCandidate(it) }.reduce { infos1, infos2 ->
|
||||
candidates.singleOrNull()?.let { return getArgumentNameHintsForCallCandidate(it, call.valueArgumentList) }
|
||||
return candidates.map { getArgumentNameHintsForCallCandidate(it, call.valueArgumentList) }.reduce { infos1, infos2 ->
|
||||
for (index in infos1.indices) {
|
||||
if (index >= infos2.size || infos1[index] != infos2[index]) {
|
||||
return@reduce infos1.subList(0, index)
|
||||
@@ -42,7 +42,10 @@ fun provideArgumentNameHints(element: KtCallElement): List<InlayInfo> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getArgumentNameHintsForCallCandidate(resolvedCall: ResolvedCall<out CallableDescriptor>): List<InlayInfo> {
|
||||
private fun getArgumentNameHintsForCallCandidate(
|
||||
resolvedCall: ResolvedCall<out CallableDescriptor>,
|
||||
valueArgumentList: KtValueArgumentList?
|
||||
): List<InlayInfo> {
|
||||
val resultingDescriptor = resolvedCall.resultingDescriptor
|
||||
if (resultingDescriptor.hasSynthesizedParameterNames() && resultingDescriptor !is FunctionInvokeDescriptor) {
|
||||
return emptyList()
|
||||
@@ -58,8 +61,11 @@ private fun getArgumentNameHintsForCallCandidate(resolvedCall: ResolvedCall<out
|
||||
arg.getArgumentExpression()?.let { argExp ->
|
||||
if (!arg.isNamed() && !valueParam.name.isSpecial && argExp.isUnclearExpression()) {
|
||||
val prefix = if (valueParam.varargElementType != null) "..." else ""
|
||||
return@mapNotNull InlayInfo(prefix + valueParam.name.identifier,
|
||||
arg.getSpreadElement()?.startOffset ?: argExp.startOffset)
|
||||
val offset = if (arg == valueArgumentList?.arguments?.firstOrNull() && valueParam.varargElementType != null)
|
||||
valueArgumentList.leftParenthesis?.textRange?.endOffset ?: argExp.startOffset
|
||||
else
|
||||
arg.getSpreadElement()?.startOffset ?: argExp.startOffset
|
||||
return@mapNotNull InlayInfo(prefix + valueParam.name.identifier, offset)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.parameterInfo
|
||||
@@ -184,4 +173,15 @@ annotation class ManyArgs(val name: String, val surname: String)
|
||||
intArrayOf(1, 0).apply { foo(<hint text="...x:" />*this) }
|
||||
}""")
|
||||
}
|
||||
|
||||
fun `test line break`() {
|
||||
check("""fun foo(vararg x: Int) {
|
||||
foo(<hint text="...x:" />
|
||||
1,
|
||||
2,
|
||||
3
|
||||
) }
|
||||
}"""
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user