0

This is the original formatting of my code:

LoadingCache<String, Map<K, V>> cache = CacheBuilder
    .newBuilder()
    .maximumSize(10000)
    .concurrencyLevel(Runtime.getRuntime().availableProcessors())
    .refreshAfterWrite(3, TimeUnit.HOURS)

When my cursor makes this selection and I ask VSCode to format, I get:

    LoadingCache<String, Map<K, V>> cache = CacheBuilder.newBuilder().maximumSize(10000)
            .concurrencyLevel(Runtime.getRuntime().availableProcessors()).refreshAfterWrite(3, TimeUnit.HOURS)

How do I tell VSCode to leave lines such as newBuilder, maximumSize, concurrencyLevel alone in their own line?

By the way, I am using Google's style guide: https://github.com/google/styleguide/blob/gh-pages/eclipse-java-google-style.xml

Tinker
  • 4,165
  • 6
  • 33
  • 72
  • 1
    Put a `//` on the end of a line. – Andy Turner Aug 05 '20 at 20:31
  • See https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings (and [my answer here](https://stackoverflow.com/a/53510327/6505250)) – howlger Aug 06 '20 at 10:43
  • @howlger I am already doing that. – Tinker Aug 06 '20 at 17:02
  • What do you do already? Did you already use Eclipse to adapt the formatter profile to your needs? Please show where you got stuck. – howlger Aug 06 '20 at 18:19
  • I have set java.format.settings.url and java.format.settings.profile. I just don't know which setting I have to turn change inside that style sheet – Tinker Aug 06 '20 at 18:26
  • @Tinker These properties are not intended to be edited manually. You have to use the Eclipse Java IDE for this, since VSCode does not (yet) provide an UI for this. – howlger Aug 07 '20 at 15:43

2 Answers2

0

It depends on the Plugin you are using with VSCode to format your code. Usually you can change the settings.json to life the code as it is or to change the formatting to your preferred style.

Kornejew
  • 94
  • 1
  • 2
  • What `settings.json` file? – nitind Aug 05 '20 at 22:48
  • In VS Code all settings, for VS Code and its extensions, are saved in the settings.json file. You can open it by pressing Ctrl + Shift + P and then type Preferences: Open Settings (JSON) – Kornejew Aug 06 '20 at 06:22
  • It's about Java, not about JavaScript or TypeScript. See https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings – howlger Aug 06 '20 at 10:49
0

The formatter you are using has no settings to get what you want.

Normally, you can change all the 'end_of_line' to 'next_line' to let the code start with a new line. But I tried both 'styleguide' and built-in formatter 'eclipse-formatter' under formatter folder of 'redhat.java' extension. It still can't get what you want. And I googled, try to find the new settings to change the formatter behavior, but I could not found.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13