Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the formatter line length with neovim lsp dart?

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
    }
  }
}
like image 653
pinoyyid Avatar asked Oct 15 '25 13:10

pinoyyid


1 Answers

You are probably using flutter-tools.nvim. In that case just create ~/.config/nvim/lua/plugins/flutter-tools.lua file and put something like that in it:

return {
  "akinsho/flutter-tools.nvim",
  opts = {
    lsp = { settings = { lineLength = 120 } },
  },
}

flutter-tools should not be configured using nvim-lspconfig. Here is the quote from flutter-tools GitHub page:

flutter tools does not depend on nvim-lspconfig. The two can co-exist but please ensure you do NOT configure dartls using lspconfig. It will be automatically set up by this plugin instead.

By the way, you can find other dart settings here.

UPD:

If you are using nvim-lspconfig for setting dartls, you can change dart settings that way (here's the example):

return {
    "neovim/nvim-lspconfig",
    config = function()
        require("lspconfig").dartls.setup({
            settings = { dart = { lineLength = 120 } },
        })
    end,
}
like image 133
Maksim Terpilowski Avatar answered Oct 18 '25 06:10

Maksim Terpilowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!