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 (!project.isInitialized) return
|
||||||
|
|
||||||
if (notificationPostponed && !isSyncing) {
|
if (notificationPostponed && !isSyncing) {
|
||||||
ApplicationManager.getApplication().executeOnPooledThread {
|
DumbService.getInstance(project).runWhenSmart {
|
||||||
DumbService.getInstance(project).waitForSmartMode()
|
|
||||||
if (!isSyncing) {
|
if (!isSyncing) {
|
||||||
notificationPostponed = false
|
notificationPostponed = false
|
||||||
|
|
||||||
|
val excludeModules = collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(project))
|
||||||
|
|
||||||
showConfigureKotlinNotificationIfNeeded(
|
showConfigureKotlinNotificationIfNeeded(
|
||||||
project,
|
project,
|
||||||
collectModulesWithOutdatedRuntime(findOutdatedKotlinLibraries(project))
|
excludeModules
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,17 +260,27 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
|||||||
if (previousElement instanceof LeafPsiElement
|
if (previousElement instanceof LeafPsiElement
|
||||||
&& ((LeafPsiElement) previousElement).getElementType() == KtTokens.LONG_TEMPLATE_ENTRY_START
|
&& ((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, "}");
|
editor.getDocument().insertString(offset, "}");
|
||||||
return Result.STOP;
|
return Result.STOP;
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiElement currentElement = file.findElementAt(offset);
|
PsiElement lastInLongTemplateEntry = previousElement.getParent().getLastChild();
|
||||||
boolean isNextTokenIsIdentifier = currentElement instanceof LeafPsiElement &&
|
boolean isSimpleLongTemplateEntry =
|
||||||
((LeafPsiElement) currentElement).getElementType() != KtTokens.IDENTIFIER;
|
lastInLongTemplateEntry instanceof LeafPsiElement &&
|
||||||
if (isNextTokenIsIdentifier) {
|
((LeafPsiElement) lastInLongTemplateEntry).getElementType() == KtTokens.LONG_TEMPLATE_ENTRY_END &&
|
||||||
editor.getDocument().insertString(offset, "}");
|
lastInLongTemplateEntry.getParent().getTextLength() == currentElement.getTextLength() + "${}".length();
|
||||||
return Result.STOP;
|
|
||||||
|
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 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 testTypeStringTemplateStartInEmptyString() = doTypeTest(
|
||||||
'{',
|
'{',
|
||||||
"""fun foo() { "$<caret>" }""",
|
"""fun foo() { "$<caret>" }""",
|
||||||
|
|||||||
Reference in New Issue
Block a user