Repository navigation
Log how each format and import optimization of the IntelliJ plugin ends - #265
Merged
Merged
Conversation
With debug logging on for #com.palantir.javaformat, a format logged only the request it received, and the import optimizer nothing at all. A save with "Reformat code" and "Optimize imports" read like a format alone, and the log could not say whether the imports were fixed, handed over to the format or left alone, nor whether the IDE had asked the optimizer at all. A format now also logs how long it took, whether it fixed the imports the optimizer handed over, and whether the text changed. The optimizer logs a line for every way it ends: handed over to a format in progress, skipped while a format's text waits to be applied, in an untrusted project or for a file with no document, and otherwise how long fixImports took and whether it changed the text, then whether its text was applied or dropped because the document changed meanwhile.
Error Prone Support's ConstantNaming wants a static final field in UPPER_SNAKE_CASE, and flagged the five loggers named log or logger: four in the IntelliJ plugin, one in the Gradle plugin's SpotlessInterop. They are final fields of the instance now, with the names they had. The code that logs went along. In FormatterProvider, the methods that log are methods of the instance, and the cache loads with this::createFormatter. getBundledImplementationUrls, which the tests call without a provider, stays static and logs nothing: the provider logs the directory itself, once, where it used to log a line without it and then the same line with it. The formatting task is an inner class of the formatting service, and the import optimizer's helpers that log are its methods.
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.
Based on
21.X.X; independent of the other open pull requests.With debug logging on for
#com.palantir.javaformat, the IntelliJ plugin logged only the request a format received, and its import optimizer logged nothing at all. A save with "Reformat code" and "Optimize imports" in Actions on Save then read like a format alone: the log could not say whether the imports were fixed, handed over to the format or left alone, nor whether the IDE had asked the optimizer at all.What it logs now
All at debug, so nothing changes with the default log level.
A format, after the line of the request it received: how long it took, whether it fixed the imports the optimizer handed over, and whether the text changed.
Formatted file=… in 28 ms, imports fixed too: false, text changed: trueThe import optimizer, a line for every way it ends, each starting with
Optimizing imports of file=…:handed over to the formatting request in progress, which fixes them after formattingskipped, a formatting request has finished and its text is not applied yetskipped, the project is not trusted, andskipped, the file has no documentfixImports ran in 4 ms, length=26614, text changed: true, thenapplied the fixed imports, ordropped the fixed imports, the document changed meanwhileLoggers in instance fields
Error Prone Support's
ConstantNamingwants astatic finalfield inUPPER_SNAKE_CASE, and flagged the five loggers namedlogorlogger: four in the IntelliJ plugin, andSpotlessInteropin the Gradle plugin. They arefinalfields of the instance now, with the names they had, and the code that logs went along:FormatterProvider. The methods that log are methods of the instance, and the cache loads withthis::createFormatter.getBundledImplementationUrls, which the tests call without a provider, stays static and logs nothing. The provider logs the bundled directory itself, once; it used to log a line without the directory and then the same line with it.What the log showed in IntelliJ IDEA 2026.3
With the plugin built from this branch:
PendingFormatstays for the IDEs and the paths that start the optimizer while a format is still running.fixImports3 to 20 ms, once warm. In a separate JVM, the same format took 550 to 800 ms andfixImportsabout 360 ms.GoFormatOnSaveDefaultsProvider). Saving a Java file then formats it and never asks the optimizer. The new lines made that visible: a save logged a format and no optimizer line.Possible downsides
Tests
None added: the changes add debug lines and move loggers into instance fields.
./gradlew :open-java-format-idea-plugin:check :gradle-open-java-format:checkpasses, and compiling both modules reports noConstantNamingfinding.