Visual Studio Code: Formatting Java method chaining

From the Redhat Developer VSCode-Java plugin wiki:

You can also define the formatting preferences in your project's .settings/org.eclipse.jdt.core.prefs. It will override global formatting settings. Since this is rather tedious, the best way to edit those preferences is to open your project in Eclipse and set the formatting preferences for your project there.

The option you will be looking for is:

Line Wrapping > Wrapping settings > Function Calls > Qualified invocations

Set it to Wrap all elements, every element on a new line, like in the picture below:

enter image description here


I achieved the same result without resorting to downloading Eclipse just to export the desired setting. I read the fantanstic guide from vscode-java-formatter.md

I already have this in vscode JSON setting:

"java.format.settings.url": "dir/to/eclipse-java-google-style.xml"

Inside the local eclipse-java-google-style.xml, change the following's value from true to false.

<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="false"/>

Save and restart vscode. Now chained methods won't be squeezed into one line.