1

I'm running nvim using the built in LSP (via the superb AstroVim) to develop dart and flutter.

Loving everything, except how the lsp formatting (which formats on save) is wrapping my lines at 80 characters.

I can see how the dart command line formatter supports

--line-length=<value>

My question: how do I include that parameter to the lsp in the

lua vim.lsp.buf.formatting()

command in order to format at a longer line length.

PS. yes I'm fully aware of the religious war over line length.

PPS. I've tried this in my AstroVim user config, but it doesn't seem to work

["server-settings"] = {
  dartls = {
    settings = {
      ["line-length"] = 120
    }
  }
}
lcheylus
  • 1,217
  • 8
  • 21
pinoyyid
  • 21,499
  • 14
  • 64
  • 115

1 Answers1

0

With AstroNvim, you could add options for your LSP configuration with lsp.server-settings.<lsp> option.

Replace <lsp> by the name of the LSP server used for dart/flutter and add option for line-length (options could be a table or a function). See examples in https://github.com/AstroNvim/AstroNvim/tree/main/lua/configs/lsp/server-settings and https://github.com/AstroNvim/AstroNvim/blob/main/lua/user_example/init.lua

According to dartls documentation, the correct configuration should be :

["server-settings"] = {
  dartls = {
    settings = {
      dart = {      
        lineLength = 120
      }
    }
  }
}
lcheylus
  • 1,217
  • 8
  • 21
  • 1
    thx, but my problem is figuring out what to put in that section. I've updated my question to show an attempt that doesn't work – pinoyyid Sep 02 '22 at 17:46
  • See my edited post with configuration for dartls – lcheylus Sep 04 '22 at 14:47
  • thx again for your answer. Unfortunately that still doesn't work. I'm calling `lua vim.lsp.buf.formatting()` Should it be possible to include the linelength in that function call (and if so, what is the correct lua syntax)? – pinoyyid Sep 05 '22 at 12:32