Repository navigation
Re-format imports in the IntelliJ plugin when the document changes. - #1518
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
In `GoogleJavaFormatImportOptimizer`, `processFile` computes the optimized imports first, and the returned `Runnable` later applies the result on the EDT inside a write action. Since #960, if the document text changed between `processFile` and the `Runnable` (either because `doPostponedOperationsAndUnblockDocument` flushed pending PSI edits into the document, or because `GoogleJavaFormatFormattingService` finished an asynchronous format pass in the meantime), the `Runnable` returned early without updating the document, silently dropping import optimization. In addition, when `isDocumentBlockedByPsi` was true during `processFile`, reading `document.getText()` instead of `file.getText()` missed uncommitted PSI import additions and caused `doPostponedOperationsAndUnblockDocument` in the `Runnable` to change the document text relative to `origText`. Read `file.getText()` in `processFile` when the document is blocked by uncommitted PSI changes so that pending PSI edits are included in the initial pass, and if the document text has still changed by the time the `Runnable` executes on the EDT, re-run `Formatter.fixImports` on the updated document text instead of dropping import optimization. Closes #971 Fixes #929 Fixes #1070 Fixes #1275 PiperOrigin-RevId: 1011620892
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Re-format imports in the IntelliJ plugin when the document changes.
In
GoogleJavaFormatImportOptimizer,processFilecomputes the optimized imports first, and the returnedRunnablelater applies the result on the EDT inside a write action. Since #960, if the document text changed betweenprocessFileand theRunnable(either becausedoPostponedOperationsAndUnblockDocumentflushed pending PSI edits into the document, or becauseGoogleJavaFormatFormattingServicefinished an asynchronous format pass in the meantime), theRunnablereturned early without updating the document, silently dropping import optimization. In addition, whenisDocumentBlockedByPsiwas true duringprocessFile, readingdocument.getText()instead offile.getText()missed uncommitted PSI import additions and causeddoPostponedOperationsAndUnblockDocumentin theRunnableto change the document text relative toorigText.Read
file.getText()inprocessFilewhen the document is blocked by uncommitted PSI changes so that pending PSI edits are included in the initial pass, and if the document text has still changed by the time theRunnableexecutes on the EDT, re-runFormatter.fixImportson the updated document text instead of dropping import optimization.Closes #971
Fixes #929
Fixes #1070
Fixes #1275