neovim / nvim-lspconfig

Quickstart configs for Nvim LSP
Apache License 2.0
10.74k stars 2.08k forks source link

JDTLS - Configure Formatting Wrapping Max Line Width #1633

Closed cloudlena closed 2 years ago

cloudlena commented 2 years ago

Language server

jdtls

Requested feature

It would be great if I could somehow configure the maximum line length for the wrapping of JDTLS' formatting as described here: https://stackoverflow.com/questions/3697287/eclipse-set-maximum-line-length-for-auto-formatting

Other clients which have this feature

texlab (under settings.texlab.formatterLineLength)

mjlbach commented 2 years ago

This is actually annoying even for vscode users: https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings

You can make an eclipse formatter file: https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml

<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/> is the important line.

Then pass

require('jdtls').setup{
-- ... all your other stuff
settings = {
    java = {
      format = {
          settings = { url = "/path/to/local/settings.xml" }
      }
    }
}