Fix incremental analysis for whitespaces
incremental analysis could ignore whitespace iff old item was whitespace #KT-37629 Fixed
This commit is contained in:
+7
-6
@@ -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] :
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// OUT_OF_CODE_BLOCK: FALSE
|
||||
// TYPE: ' '
|
||||
fun main() {
|
||||
"x"<caret>foo 4.0
|
||||
}
|
||||
|
||||
infix fun String.foo(s: Double) = Unit
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user