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

Eclipse Formatter settings for comment length ignored #3394

Open
RLThomaz opened this issue Nov 20, 2023 · 2 comments
Open

Eclipse Formatter settings for comment length ignored #3394

RLThomaz opened this issue Nov 20, 2023 · 2 comments

Comments

@RLThomaz
Copy link

I have a custom, Eclipse Formatter XML preference file that includes the following Eclipse JDT formatter setting for comment length:

<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="120"/>

I have noticed that, when formatting the code using this settings, comments were always formatted to 80 columns, regardless of the value used. When opening > Java: Open Java Formatter Settings with Preview using the Command Palette, and navigating to the comment section, I noticed that the value in Maximum comment line length is set to 80 -- check out the image below. When modifying this value, my XML file is updated to include the following setting:

<setting id="comment_line_length" value="120"/>

image

It seems that the formatter is picking up its default setting for line length, which is a property name different than the Eclipse JDT Core formatter setting.

Environment
  • Operating System: Amazon Linux 2 (running through SSH)
  • JDK version: 8
  • Visual Studio Code version: the latest (Nov 2023 release)
  • Java extension version: v1.24.0
Steps To Reproduce
  1. Create an Eclipsed Formatter XML file containing the setting org.eclipse.jdt.core.formatter.comment.line_length with a value different than 80.
  2. Write a comment that goes over 80 or the value set for the property above.
  3. Format the code and see the comment being limited to 80 despite the value used in the property above.
Current Result

Comments are formatted to the default value set by comment_line_length instead of the value set by org.eclipse.jdt.core.formatter.comment.line_length.

Expected Result

Comments should be formatted using org.eclipse.jdt.core.formatter.comment.line_length when available.

Additional Informations

Likely related to #2798

@rgrunber
Copy link
Member

rgrunber commented Nov 20, 2023

Where does the java.format.settings.url setting point to ? Is it the location of your custom file, or some other xml formatter file within your project folder ? I noticed there are 2 options :

  • Java: Open Java Formatter Settings with Preview
  • Java: Open Java Formatter Settings

One creates an eclipse-formatter.xml at the root of the proejct and the other creates a .vscode/java-formatter.xml. Maybe you're editing one of those while the other is being used ?

@RLThomaz
Copy link
Author

Where does the java.format.settings.url setting point to ?

It's pointing to my custom file, e.g.:

"java.format.settings.url": "/home/rlthomaz/workplace/ServiceABuildConfiguration/formatter/custom.formatter.preferences.xml",

Yes, there are two options there. It creates a file if java.format.settings.url is not pointing to a valid one already. I actually opened the file with both options, and editing the settings using the GUI (with Preview) option reflects automatically on the raw file opened with the first option.

Maybe you're editing one of those while the other is being used?

I don't think that's the case as I can see changes reflected on my custom file, e.g., editing Blank Lines > Between class declarations to 3 from 1 changes my custom file setting to:

<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="3"/>

I have noticed other discrepancies now, though. Editing Indentation > Tab size. from 4 to 8, for example, does not reflect on my custom file. Instead, it updates my *.code-workspace file by including the following JSON object:

		"[java]": {
			"editor.tabSize": 8
		},

I guess this means that the use of *.xml preferences file is inconsistent and only certain Eclipse settings are truly used.

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

No branches or pull requests

2 participants