KTIJ-39340 [kotlin] Select inserted TODO placeholder

(cherry picked from commit 9e27c69b74b677c04b23a4ae33980f9312841d98)

IJ-CR-210501

GitOrigin-RevId: 8f735776b36c96a1c0caa1ea972d89c5214a4249
This commit is contained in:
Vladimir Dolzhenko
2026-07-08 21:26:28 +00:00
committed by intellij-monorepo-bot
parent 525614ade1
commit ca3197d1c3
4 changed files with 22 additions and 6 deletions
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.KtUserType
import org.jetbrains.kotlin.psi.KtValueArgument
internal class AddContextParameterToExistingContextFix(
surroundingCall: KtCallExpression,
@@ -41,9 +42,16 @@ internal class AddContextParameterToExistingContextFix(
} else {
val typeReference = psiFactory.createType(parameterTypeFqNameText)
val userType = shortenReferences(typeReference) as? KtUserType
psiFactory.createExpression("TODO(\"Provide $parameterTypeText\")${userType?.let { " as ${it.text}" } ?: ""}")
psiFactory.createArgument(
psiFactory.createExpression("TODO(\"Provide $parameterTypeText\")${userType?.let { " as ${it.text}" } ?: ""}")
)
}
argList.addBefore(newElement, rightParen)
val insertedElement = argList.addBefore(newElement, rightParen) as? KtValueArgument ?: return
if (candidateName == null) {
val insertedExpression = insertedElement.getArgumentExpression() ?: return
updater.moveCaretTo(insertedExpression)
updater.templateBuilder().field(insertedExpression, insertedExpression.text)
}
}
override fun getActionPresentation(context: ActionContext, element: KtCallExpression): Presentation =
@@ -7,6 +7,7 @@ import com.intellij.modcommand.Presentation
import org.jetbrains.kotlin.idea.base.analysis.api.utils.shortenReferences
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
import org.jetbrains.kotlin.psi.KtCallExpression
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
@@ -37,7 +38,14 @@ internal class SurroundCallWithContextFix(
}
val newExpression = psiFactory.createExpression(expressionText)
shortenReferences(newExpression)
element.replace(newExpression)
val replace = element.replace(newExpression) as? KtCallExpression
if (candidateName == null && replace != null) {
val valueArgument = replace.valueArguments.firstOrNull()
val insertedExpression = valueArgument?.getArgumentExpression() ?: return
updater.moveCaretTo(insertedExpression)
updater.templateBuilder().field(insertedExpression, insertedExpression.text)
}
}
override fun getActionPresentation(context: ActionContext, element: KtExpression): Presentation =
@@ -4,8 +4,8 @@
context(s: String, l: Long) fun bar() {}
fun foo(i: Int) {
context("a", TODO("Provide Long") as Long) {
<caret>bar()
context("a", TODO("Provide Long") as Long<caret>) {
bar()
}
}
@@ -4,7 +4,7 @@
context(s: String) fun bar() {}
fun foo(i: Int) {
<caret>context(TODO("Provide String") as String) { bar() }
context(TODO("Provide String") as String<caret>) { bar() }
}
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.k2.codeinsight.fixes.SurroundCallWithContextFix