ANN: fix infinite loop when invoking a quick fix on an element with a syntax error #7841
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This issue produced an interesting situation. In the following code (which has a syntax error in the reference lifetime):
the
foo
call is parsed as having two arguments. Therefore theRemoveRedundantFunctionArgumentsFix
shows up, which tries to remove the argumenta
, along with its surrounding whitespace and comments. The code that handles this isRsElement.deleteWithSurroundingCommaAndWhitespace
inRsElement.kt
:The problem is that when the whitespace before
a
in&'static a
gets removed, the plugin somehow automatically adds it back again (maybe because it's preceded by an error element?). This caused the above function to end in an infinite loop. To resolve this pathetic case, I introduced a simple infinite loop guard, which will run the removal at most five times (this should be enough to remove successive whitespace/comments in most situations).The bug was pretty nasty, as it immediately deadlocked the whole IDE.
Fixes: #7830
changelog: Avoid IDE freeze in certain situations when invoking quick fixes or intentions on elements with syntax errors.