redhat-developer / vscode-java

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

Configure space between imports blocks when Organize Imports #543

Closed adrianmoya closed 1 year ago

adrianmoya commented 6 years ago

When I "Organize Imports" I get a blank line between import blocks ie:

import com.x
import com.x

import org.y
import org.y

Is there a way to prevent this? It doesn't comply with Google Java Style.

P.S.: I'm using the java.format.url setting pointing to a local eclipse-java-google-style.xml file

snjeza commented 6 years ago

You may want to take a look at https://github.com/eclipse/eclipse.jdt.ls/pull/640

adrianmoya commented 6 years ago

@snjeza so this is not possible today, until the expose formatting properties feature gets released? I didn't see anything in the thread regarding this particular issue...

gorkem commented 6 years ago

external formatter feature is released on 0.24.0. you should grab the google formatter mentioned on the PR and try

adrianmoya commented 6 years ago

@gorkem I'm using the google formatting file and those settings, sorry I didn't specify that. That's why i comment that the import spaces don't comply, even when using the formatting style setting.

adrianmoya commented 6 years ago

Back to this, is it only me getting the undesired result? My setup:


{
    "java.jdt.ls.vmargs": "-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication -javaagent:\"/home/adrian/.vscode/extensions/GabrielBB.vscode-lombok-0.9.4/server/lombok.jar\" -Xbootclasspath/a:\"/home/adrian/.vscode/extensions/GabrielBB.vscode-lombok-0.9.4/server/lombok.jar\"",
    "maven.executable.path": "./mvnw",
    "java.completion.importOrder": [
        "com",
        "java",
        "javax",
        "lombok",
        "org"
    ],
    "workbench.editor.enablePreviewFromQuickOpen": false,
    "editor.tabSize": 2,
    "editor.detectIndentation": false,
    "editor.insertSpaces": true,
    "extensions.autoUpdate": false,
    "java.import.gradle.enabled": false,
    "java.format.settings.url": "/home/adrian/java/eclipse-java-google-style.xml",
    "java.format.comments.enabled": false,
    "java.trace.server": "verbose",
    "git.autofetch": true,
    "git.confirmSync": false,
    "java.errors.incompleteClasspath.severity": "ignore"
  }

Expected behavior: no space between imports, as the formating settings set <setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="0"/>

Current behavior: A space between import groups.

kfstorm commented 4 years ago

Any update on this issue?

snjeza commented 4 years ago

@kfstorm You can try the following settings:

"java.format.settings.url": "https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml"
kfstorm commented 4 years ago

@snjeza Thanks. I just found that only java.format.settings.url is not enough, I have to set "java.format.settings.profile": "GoogleStyle" too.

kaskavalci commented 3 years ago

For me this wasn't enough to follow google style. Following steps helped me

$ code --install-extension emeraldwalk.RunOnSave
$ brew install google-java-format

and add the following config to settings.json

  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.java$",
        "cmd": "google-java-format --replace ${file}"
      },
    ],
  },

further reading: https://www.sethvargo.com/using-google-java-format-with-vs-code/