You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FormatterService.fixImports formats the whole file out of process #221
FormatterService.fixImports formats the whole file when the formatter runs out of process. BootstrappingFormatterService.fixImports and NativeImageFormatterService.fixImports both call runFormatterCommand(input), which runs Main - with no flags: the imports get fixed, and every line of the file is laid out again. FormatterServiceImpl.fixImports, in process, only fixes the imports.
The command line can do the right thing with --fix-imports-only; the services do not pass it. With the 21.0.2 native binary:
packagep;
importjava.util.List;
importjava.util.Map;
classC { List<String> l; Map<String,String> m; }
and open-java-format -, which fixImports runs, gives the whole file formatted.
Why it matters
Nothing calls fixImports through these services today, so nobody sees it. It is what the IntelliJ plugin's import optimizer called while it existed: palantir#1078 added PalantirJavaFormatImportOptimizer on 2024-04-26, and palantir#1089 removed it on 2024-05-21 because "optimizing imports via palantir-java-format is slow". Every Optimize Imports started a JVM and reformatted the file. An import optimizer in the plugin needs this fixed first.
Proposal
Both services pass --fix-imports-only in fixImports.
FormatterServicesTest checks fixImports on the in-process, bootstrapping and native services: imports sorted and unused ones removed, the rest of the file as it was.
Activity