Fixed KT-6033 Smart completion: wrong replacement range by Tab for item with all arguments at once
#KT-6033 Fixed
This commit is contained in:
@@ -43,6 +43,8 @@ import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import com.intellij.psi.PsiErrorElement
|
||||
import com.intellij.psi.search.PsiElementProcessor
|
||||
import com.intellij.psi.PsiComment
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgument
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList
|
||||
|
||||
public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
@@ -106,6 +108,12 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
}
|
||||
|
||||
context.getOffsetMap().addOffset(SmartCompletion.OLD_ARGUMENTS_REPLACEMENT_OFFSET, expressionEnd)
|
||||
|
||||
val argumentList = (expression.getParent() as? JetValueArgument)?.getParent() as? JetValueArgumentList
|
||||
if (argumentList != null) {
|
||||
context.getOffsetMap().addOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET,
|
||||
argumentList.getRightParenthesis()?.getTextRange()?.getStartOffset() ?: argumentList.getTextRange().getEndOffset())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.jet.plugin.completion.PositionalArgumentExpectedInfo
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.plugin.completion.assignPriority
|
||||
import com.intellij.codeInsight.lookup.Lookup
|
||||
|
||||
class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
|
||||
val typesWithAutoCasts: (DeclarationDescriptor) -> Iterable<JetType>) {
|
||||
@@ -76,6 +77,15 @@ class MultipleArgumentsItemProvider(val bindingContext: BindingContext,
|
||||
|
||||
return LookupElementBuilder
|
||||
.create(variables.map { IdeDescriptorRenderers.SOURCE_CODE.renderName(it.getName()) }.joinToString(", "))
|
||||
.withInsertHandler { (context, lookupElement) ->
|
||||
if (context.getCompletionChar() == Lookup.REPLACE_SELECT_CHAR) {
|
||||
val offset = context.getOffsetMap().getOffset(SmartCompletion.MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET)
|
||||
if (offset != -1) {
|
||||
context.getDocument().deleteString(context.getTailOffset(), offset)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
.withIcon(compoundIcon)
|
||||
.addTail(Tail.RPARENTH) //TODO: support square brackets
|
||||
.assignPriority(ItemPriority.MULTIPLE_ARGUMENTS_ITEM)
|
||||
|
||||
@@ -324,5 +324,6 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
|
||||
|
||||
class object {
|
||||
public val OLD_ARGUMENTS_REPLACEMENT_OFFSET: OffsetKey = OffsetKey.create("nonFunctionReplacementOffset")
|
||||
public val MULTIPLE_ARGUMENTS_REPLACEMENT_OFFSET: OffsetKey = OffsetKey.create("multipleArgumentsReplacementOffset")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(a: Int, b: String, c: String) {}
|
||||
|
||||
fun bar(b: String, a: Int, c: String) {
|
||||
foo(<caret>1, "", "")
|
||||
}
|
||||
|
||||
// ELEMENT: "a, b, c"
|
||||
// CHAR: \t
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo(a: Int, b: String, c: String) {}
|
||||
|
||||
fun bar(b: String, a: Int, c: String) {
|
||||
foo(a, b, c)<caret>
|
||||
}
|
||||
|
||||
// ELEMENT: "a, b, c"
|
||||
// CHAR: \t
|
||||
Reference in New Issue
Block a user