lsp-format

URL: https://github.com/lukas-reineke/lsp-format.nvim/

Maintainers: Austin Horstman


Configuring a Language

lsp-format uses a table defining which lsp servers to use for each language.

  • exclude is a table of LSP servers that should not format the buffer.
    • Alternatively, you can also just not call on_attach for the clients you don't want to use for formatting.
  • order is a table that determines the order formatting is requested from the LSP server.
  • sync turns on synchronous formatting. The editor will block until the formatting is done.
  • force will write the format result to the buffer, even if the buffer changed after the format request started.

plugins.lsp-format.enable

Whether to enable lsp-format.nvim.

Type: boolean

Default: false

Example: true

Declared by:

plugins.lsp-format.package

The lsp-format.nvim package to use.

Type: package

Default: pkgs.vimPlugins.lsp-format-nvim

Declared by:

plugins.lsp-format.lspServersToEnable

Choose the LSP servers for which lsp-format should be enabled.

Possible values:

  • “all” (default): Enable formatting for all language servers
  • “none”: Do not enable formatting on any language server. You might choose this if for some reason you want to manually call require("lsp-format").on_attach(client) in the onAttach function of your language servers.
  • list of LS names: Manually choose the servers by name

Type: one of “none”, “all” or list of string

Default: "all"

Example:

[
  "efm"
  "gopls"
]

Declared by:

plugins.lsp-format.settings

Options provided to the require('lsp-format').setup function.

Type: attribute set of anything

Default: { }

Example:

{
  go = {
    exclude = [
      "gopls"
    ];
    force = true;
    order = [
      "gopls"
      "efm"
    ];
    sync = true;
  };
  typescript = {
    tab_width = {
      __raw = ''
        function()
          return vim.opt.shiftwidth:get()
        end'';
    };
  };
  yaml = {
    tab_width = 2;
  };
}

Declared by: