Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regression: java.format.settings.url no longer loads project .xml file #1827

Closed
rothfels opened this issue Mar 6, 2021 · 11 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#1690
Assignees

Comments

@rothfels
Copy link

rothfels commented Mar 6, 2021

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.

@rothfels rothfels changed the title Formatter .xml rules not respected in latest extension version. Formatter .xml rules not respected in latest extension version Mar 6, 2021
@rothfels
Copy link
Author

rothfels commented Mar 6, 2021

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

@rothfels rothfels changed the title Formatter .xml rules not respected in latest extension version regression: java.format.settings.url no longer loads local .xml file Mar 6, 2021
@rothfels rothfels changed the title regression: java.format.settings.url no longer loads local .xml file regression: java.format.settings.url no longer loads project .xml file Mar 6, 2021
@lpedrosa
Copy link

lpedrosa commented Mar 7, 2021

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.

@lpedrosa
Copy link

lpedrosa commented Mar 7, 2021

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"

@johnchesser
Copy link

johnchesser commented Mar 12, 2021

For me relative with ~ didn't work, nor did absolute, but adding file: did work, thank you @rothfels .

@kristian
Copy link

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!

@snjeza
Copy link
Contributor

snjeza commented Mar 19, 2021

@kristian It will work.

@llgcode
Copy link

llgcode commented Sep 13, 2021

Hi,
How to reference an absolute file path?
Not seems to work

"java.format.settings.url": "file://E:/tools/config/eclipse-java-mystyle.xml",

@snjeza
Copy link
Contributor

snjeza commented Sep 13, 2021

@llgcode Could you try

"java.format.settings.url": "file:///E:/tools/config/eclipse-java-mystyle.xml",

@llgcode
Copy link

llgcode commented Sep 14, 2021

Hi @snjeza
it seems to load now, not error message in Java output console.
But I'm still not sure my profile (may be too old):

<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="200"/>

When formatting, the code is splitted after 100 chars

Thank you for your help

@kristian
Copy link

kristian commented Oct 3, 2021

Using this without the "file:" protocol again fails for me, is it also anyone else? Could there be another regression on this?

@snjeza
Copy link
Contributor

snjeza commented Oct 4, 2021

Using this without the "file:" protocol again fails for me, is it also anyone else? Could there be another regression on this?

The issue is related to eclipse-jdtls/eclipse.jdt.ls#1893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants