Some of our teammates just upgraded to the latest version of this extension and noticed that the formatter's behavior has changed.
Before upgrading extension:
Format document -- no diffAfter upgrading extension:
Format document -- large diffOur formatter configuration is and has been set from an .xml config file. Our .vscode/settings.json looks like this:
"java.format.settings.url": "path/to/code-style.xml",
I opened the project in Eclipse and imported the same code-style.xml file, and verified that the Eclipse formatter running with that config produces no diff.
I've concluded the formatter on the most recent version of this extension has regressed.
MacOS 11.2.1openjdk version "15.0.1" 2020-10-201.54.1v0.76.0.vscode/settings.jsonFormat documentFormatter generating unwanted diffs on newest extension version.
No formatting diffs on files that were formatted with prior extension version.
Edit: I discovered it works with a (relative) file URL (absolute doesn't work because ${workspaceFolder} is not interpolated).
"java.format.settings.url": "file:path/to/code-style.xml",
Fwiw, the documentation for this setting says it can be a path. Maybe you want to fix? https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings
What is the workaround that we can use in the meantime?
For example, assuming you have the formatter file in the ${workspaceFolder} like ${workspaceFolder}/eclipse-formatter.xml, what should the url be?
Currently I have it set as eclipse-formatter.xml and it doesn't seem to pick it up.
I guess I should've read @rothfels answer more carefully 馃槄, since it is mentioned that the URI could be relative to the ${workspaceFolder}.
A workaround for the scenario I've described above is to set the java.format.settings.url property like:
# assuming your formatter xml file in on ${workspaceFolder}
# and is called 'eclipse-formatter.xml'
"java.format.settings.url": "file:./eclipse-formatter.xml"
For me relative with ~ didn't work, nor did absolute, but adding file: did work, thank you @rothfels .
Question: To mitigate this regression, we switched to the "file:" protocol as a workaround. After this regression is fixed, will the "file:" workaround break again or also continue to work, just to inform our developers. Thanks!
@kristian It will work.
Most helpful comment
Edit: I discovered it works with a (relative) file URL (absolute doesn't work because
${workspaceFolder}is not interpolated).Fwiw, the documentation for this setting says it can be a path. Maybe you want to fix? https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings