Skip to content

Log how each format and import optimization of the IntelliJ plugin ends - #265

Merged
abashev merged 2 commits into
21.X.Xfrom
abashev/Update-idea-plugin
Nov 23, 2026
Merged

abashev merged 2 commits into
21.X.Xfrom
abashev/Update-idea-plugin

Conversation

@abashev

@abashev abashev commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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: true

  • The 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 formatting
    • skipped, a formatting request has finished and its text is not applied yet
    • skipped, the project is not trusted, and skipped, the file has no document
    • fixImports ran in 4 ms, length=26614, text changed: true, then applied the fixed imports, or dropped the fixed imports, the document changed meanwhile

Loggers in instance fields

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, and SpotlessInterop in the Gradle plugin. They are final fields 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 with this::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.
  • The formatting task is an inner class of the formatting service, and the import optimizer's helpers that log are its methods.

What the log showed in IntelliJ IDEA 2026.3

With the plugin built from this branch:

  • Saves with "Reformat code" and "Optimize imports" in Actions on Save, and Reformat Code with "Optimize imports" on a directory of 140 files. The optimizer ran on each file once the format's text was applied. Of about 150 such pairs, none was handed over and none was skipped. The handover in PendingFormat stays for the IDEs and the paths that start the optimizer while a format is still running.
  • Timings. In the IDE process, a format took 25 to 60 ms on a file of 26 KB, and fixImports 3 to 20 ms, once warm. In a separate JVM, the same format took 550 to 800 ms and fixImports about 360 ms.
  • Actions on Save without Java. With the Go plugin installed and no "Optimize imports" setting stored for the project, "Optimize imports" on save is on for Go files only (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

  • "Optimize imports on the fly" asks the optimizer on every highlighting pass, so with debug logging on, a file being typed in logs a line per pass.
  • Nothing changes in how a file is formatted or its imports fixed.

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:check passes, and compiling both modules reports no ConstantNaming finding.

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.
@abashev
abashev merged commit e07d9c3 into 21.X.X Nov 23, 2026
16 checks passed
@abashev
abashev deleted the abashev/Update-idea-plugin branch November 23, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant