redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

Formatter Settings File Ignoring disabling_tag/enabling_tag #1295

Open spottedmahn opened 4 years ago

spottedmahn commented 4 years ago

When I specify a formatter settings file, the disable/enable formatting tags are ignored.

Environment
Steps To Reproduce
  1. Change workspace settings to:
    {
    "java.format.settings.url": "https://raw.githubusercontent.com/snjeza/vscode-test/master/fluent.xml"
    }
  2. Wrap some code w/ // @formatter:off & // @formatter:on
  3. Do something in that code that is outside of the default for the format settings
  4. Auto format the code (ALT + SHIFT + F)

Sample project

Current Result

Code between // @formatter:off & // @formatter:on is formatted

Expected Result

Code between // @formatter:off & // @formatter:on shouldn't be formatted

Additional Informations

Before auto-format: image

After auto-format: image

Format setting file: image

snjeza commented 4 years ago

@spottedmahn could you try the following:

// @formatter:off 
...your code... 
// @formatter:on

instead of

// @formatter:on
...your code... 
// @formatter:off
spottedmahn commented 4 years ago

As a debugging step? Or a final solution?

spottedmahn commented 4 years ago

image

Source

spottedmahn commented 4 years ago

Also, pointing it at a profile that doesn't override the values, i.e. they are missing, produces the same "bug"

enabling_tag and disabling_tag not listed:

image

image

ak0ska commented 4 years ago

Is there any solution for this issue? I have the same problem, being unable to exclude code blocks from formatting.

CsCherrYY commented 4 years ago

Could you find the setting org.eclipse.jdt.core.formatter.use_on_off_tags in the profile? This setting should be set to true to enable the disabling_tag and the enabling_tag.

ak0ska commented 4 years ago

I had a look and it was set to false. After changing the configuration and restarting the editor the tags work as expected. Thank you for your help! 😄