Fix incremental analysis for whitespaces

incremental analysis could ignore whitespace iff old item was whitespace

#KT-37629 Fixed
This commit is contained in:
Vladimir Dolzhenko
2020-03-23 14:46:55 +00:00
parent 8935c600c1
commit 0073d260f8
3 changed files with 19 additions and 6 deletions
@@ -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 -> changeSet.changedElements.all { changedElement ->
val changesByElement = changeSet.getChangesByElement(changedElement) val changesByElement = changeSet.getChangesByElement(changedElement)
changesByElement.affectedChildren.all { affectedChild -> 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) val changeByChild = changesByElement.getChangeByChild(affectedChild)
return@all if (changeByChild is ChangeInfoImpl) { return@all if (changeByChild is ChangeInfoImpl) {
val oldChild = changeByChild.oldChild val oldChild = changeByChild.oldChild
oldChild is PsiComment || oldChild is KDoc precondition(oldChild)
} else false } else false
} }
} }
private fun isCommentChange(changeSet: TreeChangeEvent): Boolean =
isSpecificChange(changeSet) { it is PsiComment || it is KDoc }
private fun isFormattingChange(changeSet: TreeChangeEvent): Boolean = private fun isFormattingChange(changeSet: TreeChangeEvent): Boolean =
changeSet.changedElements.all { isSpecificChange(changeSet) { it is PsiWhiteSpace }
changeSet.getChangesByElement(it).affectedChildren.all { c -> c is PsiWhiteSpace }
}
/** /**
* Has to be aligned with [getInsideCodeBlockModificationScope] : * Has to be aligned with [getInsideCodeBlockModificationScope] :
@@ -0,0 +1,7 @@
// OUT_OF_CODE_BLOCK: FALSE
// TYPE: ' '
fun main() {
"x"<caret>foo 4.0
}
infix fun String.foo(s: Double) = Unit
@@ -318,6 +318,11 @@ public class OutOfBlockModificationTestGenerated extends AbstractOutOfBlockModif
runTest("idea/testData/codeInsight/outOfBlock/InUninitializedPropertyAccessor.kt"); 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") @TestMetadata("InitBlock.kt")
public void testInitBlock() throws Exception { public void testInitBlock() throws Exception {
runTest("idea/testData/codeInsight/outOfBlock/InitBlock.kt"); runTest("idea/testData/codeInsight/outOfBlock/InitBlock.kt");