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

Formatter: "Remove blank lines in Javadoc" is being ignored. #2122

Closed
rhystedstone opened this issue Sep 18, 2021 · 13 comments
Closed

Formatter: "Remove blank lines in Javadoc" is being ignored. #2122

rhystedstone opened this issue Sep 18, 2021 · 13 comments

Comments

@rhystedstone
Copy link

The option "Remove blank lines in Javadoc" (org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment) is being ignored. The output remains the same regardless of this setting.

Environment
  • Operating System: Windows NT 10.0
  • JDK version: 16.0.27 Hotspot
  • Visual Studio Code version: 1.60.1 (user setup)
  • Java extension version: v0.82.0
Steps To Reproduce
  1. Use a custom formatter for Java
  2. Change the option org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment to true, either in the formatter preview, or directly via the xml.
  3. Blank lines in javadocs aren't cleared.

Project:
A snippet of my project's javadoc which displays 5 blank lines
Formatter Preview:
A screenshot of the formatter preview which displays a tick next to "Remove blank lines in javadoc", yet the preview next to it displays 3 blank lines in the javadoc

log.log
The jdt_ws log is attached - The java.trace logs returned nothing.

Current Result

Currently the lines aren't removed from the javadoc.

/**
 * Some description of the method
 * 
 * 
 * 
 * 
 * @param arg1 A parameter
 * @param arg2 Another parameter
 */
Expected Result

The lines should be removed from the javadoc:

/**
 * Some description of the method
 * @param arg1 A parameter
 * @param arg2 Another parameter
 */
@CsCherrYY
Copy link
Contributor

I can't reproduce this issue locally, could you attach your formatter profile?

@rhystedstone
Copy link
Author

I couldn't upload it to github, so here's a link:
https://drive.google.com/u/0/uc?export=download&confirm=MDEV&id=1u9MJg_zrKLsaBlqzO5yJEOmQz_uKQXvM

@rhystedstone
Copy link
Author

Also ignores this formatter: eclipse-formatter.xml

@snjeza
Copy link
Contributor

snjeza commented May 12, 2022

@rhystedstone could you show your settings.json (the java.format.settings.url and java.settings.url preferences)?

@snjeza
Copy link
Contributor

snjeza commented May 12, 2022

Related issue: #2429

@rhystedstone
Copy link
Author

rhystedstone commented May 12, 2022

@snjeza My java.format.settings.url points to: file:///C:/Users/Rhys/Development/language/java/eclipse-formatter.xml, which is a copy of the one I mentioned earlier.
My java.settings.url was originally blank, but I found a workaround for the formatter, which involves getting eclipse to generate the prefs file. So, it's currently set to that file, located at file:///C:/Users/Rhys/Development/language/java/settings.pref, which actually works and follows the settings I want.

settings.prefs
eclipse-formatter.xml

@snjeza
Copy link
Contributor

snjeza commented May 13, 2022

@rhystedstone Could you try https://github.com/snjeza/vscode-test/raw/master/java-1.6.1.vsix?
It includes #2451 and eclipse-jdtls/eclipse.jdt.ls#2089
You should see an error message if your java.format.settings.url or java.settings.url is invalid.

@rhystedstone
Copy link
Author

I can confirm that this version does notify me of an invalid URL. However, my current settings do not display the notification until I ammend them to a known invalid path.

@rhystedstone
Copy link
Author

rhystedstone commented May 13, 2022

I just tried to use a new formatter.xml file, however it did not work.

Files:

New formatter.xml file: Tomas's Preset
New settings.pref file Tomas's Preset as a settings.pref

My steps:

  1. Remove the java.settings.url setting and reload VSCode
  2. Double-check the java.settings.formatter.url setting points to the correct formatter (It did)
  3. Attempted to format a document which I purposefully changed to something which should be corrected with the formatter (See below)
  4. The document formatted, but the formatting was different, despite the settings matching those of my settings.prefs file.
  5. Re-added the java.settings.url setting and reloaded VSCode.
  6. The document formatted correctly.
    Note: Reloading vscode isn't necessary to make the changes, but I did it just in-case it would change something.

My formatter test:

Add multiple lines of text to a javadoc, with a new line between each.

/**
 * Test something.
 * 
 * 
 * Test anything.
 * 
 * 
 * Test nothing.
 */
 public void test(){
 }

If the formatter is following my preferences, all the new lines would be removed and a space placed between each line of text.
Example:

/**
 * Test something. Test anything. Test nothing.
 */
 public void test(){
 }

If the formatter is not following my preferences properly, it will keep the lines of text separate, which is what happens currently.

/**
 * Test something.
 * 
 * 
 * Test anything.
 * 
 * 
 * Test nothing.
 */
 public void test(){
 }

@rhystedstone
Copy link
Author

I just got it working by removing the java.format.settings.profile key.
I don't know if there was an invalid character, but without that setting, it works with the xml.

It may be a good idea to also add a warning for an invalid value as it fails too silently.

@rhystedstone
Copy link
Author

This issue can be closed as the original issue is 8 months old, so the formatter has had several different settings.
It's possible that the old formatter file I used was invalid somehow, or an option I implemented was invalid.

@snjeza
Copy link
Contributor

snjeza commented May 13, 2022

I just got it working by removing the java.format.settings.profile key.
I don't know if there was an invalid character, but without that setting, it works with the xml.

You should see

Invalid settings: java.format.settings.profile=<Incorrect_Profile>. The '<Incorrect_Profile' profile doesn't exist.

in your log

@rhystedstone
Copy link
Author

Closing as stale.

@rhystedstone rhystedstone closed this as not planned Won't fix, can't repro, duplicate, stale Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants