Skip to content

blank lines between import groups is ignored #2980

Open

Description

@scrocquesel

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;
  1. 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;
Additional Informations

Activity

  1. snjeza commented on Mar 4, 2023

    @snjeza
    Collaborator

    @scrocquesel I can't reproduce the issue.
    Where you set <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/> ?

  2. scrocquesel commented on Mar 5, 2023

    @scrocquesel
    Author

    @snjeza In a file relative to the project. I recheck and Organize does honor the setting but not Format document. (I edit the description)

  3. snjeza commented on Mar 5, 2023

    @snjeza
    Collaborator

    @scrocquesel Could you show your user, workspace settings.json and <your_project>/.settings/org.eclipse.jdt.core.prefs ?

  4. scrocquesel commented on Mar 5, 2023

    @scrocquesel
    Author

    @scrocquesel Could you show your user, workspace settings.json and <your_project>/.settings/org.eclipse.jdt.core.prefs ?

    Nothing java related in user settings.json and no <your_project>/.settings/org.eclipse.jdt.core.prefs file.
    Project settings can be found at scrocquesel/java-operator-sdk@9ed7d7d

  5. snjeza commented on Mar 5, 2023

    @snjeza
    Collaborator

    @scrocquesel Could you try right click, select Source Action>Organize Imports

  6. scrocquesel commented on Mar 5, 2023

    @scrocquesel
    Author

    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.

  7. snjeza commented on Mar 6, 2023

    @snjeza
    Collaborator

    It can also be reproduced in Eclipse.

  8. rgrunber commented on Mar 6, 2023

    @rgrunber
    Member

    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 .

  9. Nightenom commented on Mar 6, 2024

    @Nightenom

    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 that java.saveActions.organizeImports runs after editor.formatOnSave so the formatter rules are not applied correctly

    edit: fixed using following json instead of java.saveActions.organizeImports, honestly formatter should always run as last action in onSave-like trigger

    "editor.codeActionsOnSave": {
        "source.organizeImports": "always"
    }

    edit2: 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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions