-
Notifications
You must be signed in to change notification settings - Fork 886
Fix java.lang.RuntimeException: Document is locked by write PSI operations
errors
#960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is great, thank you so much for fixing this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got asked if I had the power to un-block this. I'm not actually sure if I do, but one question before I try:
We read the document text at line 62. If we later find that the document is blocked, we perform and postponed operations, and then we write output that was based on the document text we read earlier. Does that mean that we could undo the effects of any of the operations that we'd just postponed? If so, should we be reading the document text again (maybe retrying the whole of processFile
) and operating on that? If that's difficult, would it be better to simply do nothing? I see some other formatter implementations that choose to do nothing, e.g., this code in ktfmt.
Yeah, that's a good spot. I've changed it to unblock and apply if the document text hasn't changed (not sure how likely that is), otherwise do nothing. Intellij's own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Let's see if I can in fact get this converted into a change in our internal repo, and then we'll see if anyone with permissions is up for getting it submitted.
i changed the import optimizer to not set
|
I see this warning that Now, presumably it doesn't add a lot to the cost of setting the text when we're modifying the imports. And even if there is nothing to set (and so we're paying only the cost of getting the text), you make a good point that IntelliJ's own import optimizer does what looks like lots of stuff (implementation?) on the main thread, so How Bad Can It Be? Still, do you think we could get most of the value by including only the first of your two new checks, the one that happens in whatever background thread does the work, since that one uses the result of the |
it seems to suggest using
|
…f formatter results are unchanged, or if `document.text` has changed This seemed to be responsible for some of the issues with the formatter seemingly not formatting a file.
Oh, right, sorry, I'd somehow been thinking that the second check was a new thing and not the fix you'd previously explained. getCharSequence looks like it makes a nice, easy optimization in any case. |
Also update to
google-java-format
1.17.0