From 0073d260f8cecc95cc1ee1d59c0a02a85ac345c9 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Mon, 23 Mar 2020 14:46:55 +0000 Subject: [PATCH] Fix incremental analysis for whitespaces incremental analysis could ignore whitespace iff old item was whitespace #KT-37629 Fixed --- .../trackers/KotlinCodeBlockModificationListener.kt | 13 +++++++------ .../codeInsight/outOfBlock/InfixFunWhitespace.kt | 7 +++++++ .../OutOfBlockModificationTestGenerated.java | 5 +++++ 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 idea/testData/codeInsight/outOfBlock/InfixFunWhitespace.kt diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt index 314dd9f8839..1437f14c883 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/trackers/KotlinCodeBlockModificationListener.kt @@ -181,23 +181,24 @@ class KotlinCodeBlockModificationListener( } } - private fun isCommentChange(changeSet: TreeChangeEvent): Boolean = + private fun isSpecificChange(changeSet: TreeChangeEvent, precondition: (ASTNode?) -> Boolean): Boolean = changeSet.changedElements.all { changedElement -> val changesByElement = changeSet.getChangesByElement(changedElement) changesByElement.affectedChildren.all { affectedChild -> - if (!(affectedChild is PsiComment || affectedChild is KDoc)) return@all false + if (!precondition(affectedChild)) return@all false val changeByChild = changesByElement.getChangeByChild(affectedChild) return@all if (changeByChild is ChangeInfoImpl) { val oldChild = changeByChild.oldChild - oldChild is PsiComment || oldChild is KDoc + precondition(oldChild) } else false } } + private fun isCommentChange(changeSet: TreeChangeEvent): Boolean = + isSpecificChange(changeSet) { it is PsiComment || it is KDoc } + private fun isFormattingChange(changeSet: TreeChangeEvent): Boolean = - changeSet.changedElements.all { - changeSet.getChangesByElement(it).affectedChildren.all { c -> c is PsiWhiteSpace } - } + isSpecificChange(changeSet) { it is PsiWhiteSpace } /** * Has to be aligned with [getInsideCodeBlockModificationScope] : diff --git a/idea/testData/codeInsight/outOfBlock/InfixFunWhitespace.kt b/idea/testData/codeInsight/outOfBlock/InfixFunWhitespace.kt new file mode 100644 index 00000000000..b40e0a384b4 --- /dev/null +++ b/idea/testData/codeInsight/outOfBlock/InfixFunWhitespace.kt @@ -0,0 +1,7 @@ +// OUT_OF_CODE_BLOCK: FALSE +// TYPE: ' ' +fun main() { + "x"foo 4.0 +} + +infix fun String.foo(s: Double) = Unit \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java index c7b35523ad2..5e20aca1e73 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/OutOfBlockModificationTestGenerated.java @@ -318,6 +318,11 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif runTest("idea/testData/codeInsight/outOfBlock/InUninitializedPropertyAccessor.kt"); } + @TestMetadata("InfixFunWhitespace.kt") + public void testInfixFunWhitespace() throws Exception { + runTest("idea/testData/codeInsight/outOfBlock/InfixFunWhitespace.kt"); + } + @TestMetadata("InitBlock.kt") public void testInitBlock() throws Exception { runTest("idea/testData/codeInsight/outOfBlock/InitBlock.kt");