Don't auto close simple long template entry if it's already finished (KT-11143)
#KT-11143 Fixed
This commit is contained in:
+5
-3
@@ -53,13 +53,15 @@ class KotlinConfigurationCheckerComponent(val project: Project) : ProjectCompone
|
||||
if (!project.isInitialized) return
|
||||
|
||||
if (notificationPostponed && !isSyncing) {
|
||||
ApplicationManager.getApplication().executeOnPooledThread {
|
||||
DumbService.getInstance(project).waitForSmartMode()
|
||||
DumbService.getInstance(project).runWhenSmart {
|
||||
if (!isSyncing) {
|
||||
notificationPostponed = false
|
||||
|
||||
val excludeModules = collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(project))
|
||||
|
||||
showConfigureKotlinNotificationIfNeeded(
|
||||
project,
|
||||
collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(project))
|
||||
excludeModules
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,17 +260,27 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
||||
if (previousElement instanceof LeafPsiElement
|
||||
&& ((LeafPsiElement) previousElement).getElementType() == KtTokens.LONG_TEMPLATE_ENTRY_START
|
||||
) {
|
||||
if (previousDollarInStringOffset != null && previousDollarInStringOffset.intValue() == offset - 1) {
|
||||
PsiElement currentElement = file.findElementAt(offset);
|
||||
boolean isNextTokenIsIdentifier = currentElement instanceof LeafPsiElement &&
|
||||
((LeafPsiElement) currentElement).getElementType() == KtTokens.IDENTIFIER;
|
||||
|
||||
if (!isNextTokenIsIdentifier) {
|
||||
editor.getDocument().insertString(offset, "}");
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
PsiElement currentElement = file.findElementAt(offset);
|
||||
boolean isNextTokenIsIdentifier = currentElement instanceof LeafPsiElement &&
|
||||
((LeafPsiElement) currentElement).getElementType() != KtTokens.IDENTIFIER;
|
||||
if (isNextTokenIsIdentifier) {
|
||||
editor.getDocument().insertString(offset, "}");
|
||||
return Result.STOP;
|
||||
PsiElement lastInLongTemplateEntry = previousElement.getParent().getLastChild();
|
||||
boolean isSimpleLongTemplateEntry =
|
||||
lastInLongTemplateEntry instanceof LeafPsiElement &&
|
||||
((LeafPsiElement) lastInLongTemplateEntry).getElementType() == KtTokens.LONG_TEMPLATE_ENTRY_END &&
|
||||
lastInLongTemplateEntry.getParent().getTextLength() == currentElement.getTextLength() + "${}".length();
|
||||
|
||||
if (!isSimpleLongTemplateEntry) {
|
||||
boolean isAfterTypedDollar = previousDollarInStringOffset != null && previousDollarInStringOffset.intValue() == offset - 1;
|
||||
if (isAfterTypedDollar) {
|
||||
editor.getDocument().insertString(offset, "}");
|
||||
return Result.STOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,24 @@ class TypedHandlerTest : LightCodeInsightTestCase() {
|
||||
"""fun foo() { "$dollar{<caret>}something" }"""
|
||||
)
|
||||
|
||||
fun testTypeStringTemplateWithUnmatchedBrace() = doTypeTest(
|
||||
"$dollar{",
|
||||
"""val a = "<caret>bar}foo"""",
|
||||
"""val a = "$dollar{<caret>bar}foo""""
|
||||
)
|
||||
|
||||
fun testTypeStringTemplateWithUnmatchedBraceComplex() = doTypeTest(
|
||||
"$dollar{",
|
||||
"""val a = "<caret>bar + more}foo"""",
|
||||
"""val a = "$dollar{<caret>}bar + more}foo""""
|
||||
)
|
||||
|
||||
fun testTypeStringTemplateStartInStringWithBraceLiterals() = doTypeTest(
|
||||
"$dollar{",
|
||||
"""val test = "{ code <caret>other }"""",
|
||||
"""val test = "{ code $dollar{<caret>}other }""""
|
||||
)
|
||||
|
||||
fun testTypeStringTemplateStartInEmptyString() = doTypeTest(
|
||||
'{',
|
||||
"""fun foo() { "$<caret>" }""",
|
||||
|
||||
Reference in New Issue
Block a user