Open
Description
With a format settings file containing
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
and java.completion.importOrder specifying groups, all imports are still not spaced.
"java.completion.importOrder": [
"java",
"javax",
"org",
"com",
"",
"#"
]
Environment
- Operating System: Linux
- JDK version:
- Visual Studio Code version: 1.76
- Java extension version: 1.15.0
Steps To Reproduce
With
import java.time.Duration;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
- Format document do not add or remove blank lines
Current Result
import java.time.Duration;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expected Result
import java.time.Duration;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Activity
snjeza commentedon Mar 4, 2023
@scrocquesel I can't reproduce the issue.
Where you set
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>?scrocquesel commentedon Mar 5, 2023
@snjeza In a file relative to the project. I recheck and Organize does honor the setting but not Format document. (I edit the description)
snjeza commentedon Mar 5, 2023
@scrocquesel Could you show your user, workspace
settings.jsonand<your_project>/.settings/org.eclipse.jdt.core.prefs?scrocquesel commentedon Mar 5, 2023
Nothing java related in user settings.json and no
<your_project>/.settings/org.eclipse.jdt.core.prefsfile.Project settings can be found at scrocquesel/java-operator-sdk@9ed7d7d
snjeza commentedon Mar 5, 2023
@scrocquesel Could you try right click, select
Source Action>Organize Importsscrocquesel commentedon Mar 5, 2023
Yes, this works but not format command. I understand that we need to do two command to format files according to the eclipse format settings profile.
snjeza commentedon Mar 6, 2023
It can also be reproduced in Eclipse.
rgrunber commentedon Mar 6, 2023
Apparently this is functioning as designed :
https://bugs.eclipse.org/bugs/show_bug.cgi?id=165210#c5
https://bugs.eclipse.org/bugs/show_bug.cgi?id=572253#c1
It's definitely odd to have format options that the formatter does not enforce. I guess one workaround for now would be to set
editor.formatOnSave&java.saveActions.organizeImports.Nightenom commentedon Mar 6, 2024
I'm having very similar problem, however with
<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="-1"/>ie. no lines between any imports. The issue is thatjava.saveActions.organizeImportsruns aftereditor.formatOnSaveso the formatter rules are not applied correctlyedit: fixed using following json instead of
java.saveActions.organizeImports, honestly formatter should always run as last action in onSave-like triggeredit2: running the combo in first edit repeatedly (using ctrl+s) results in editor shifting in due to lines being added by import action and removed by formatter action, some intermediate file might fix such issue - could be also marked as upstream vscode issue