Vscode-java: regression: java.format.settings.url no longer loads project .xml file

Created on 6 Mar 2021  路  6Comments  路  Source: redhat-developer/vscode-java

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:

  • open a file, run Format document -- no diff

After upgrading extension:

  • open a file, run Format document -- large diff

Our 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.

Environment
  • Operating System: MacOS 11.2.1
  • JDK version: openjdk version "15.0.1" 2020-10-20
  • Visual Studio Code version: 1.54.1
  • Java extension version: v0.76.0
Steps To Reproduce
  1. Create custom code style .xml file
  2. Configure via .vscode/settings.json
  3. Run Format document
Current Result

Formatter generating unwanted diffs on newest extension version.

Expected Result

No formatting diffs on files that were formatted with prior extension version.

formatter

Most helpful comment

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

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings