1

I am trying to load formatter.nvim but I get this error:

Lua Diagnostics undefined field 'setup'

enter image description here

What is the path for the logs?

This is my full configuration:

return {
    'mhartington/formatter.nvim',
    config = function()
        -- Utilities for creating configurations
        local util = require "formatter.util"

        -- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
        require("formatter").setup({
            -- Enable or disable logging
            logging = true,
            -- Set the log level
            log_level = vim.log.levels.DEBUG,
            -- All formatter configurations are opt-in
            filetype = {
                lua = {
                    require("formatter.filetypes.lua").stylua,
                    function()
                        return {
                            exe = "stylua",
                            args = {
                                "--column-width",
                                "120",
                                "--indent-type",
                                "Spaces",
                                "--indent-width",
                                "2",
                                "--search-parent-directories",
                                "--stdin-filepath",
                                util.escape_path(util.get_current_buffer_file_path()),
                                "--",
                                "-",
                            },
                            stdin = true,
                        }
                    end
                },
                ["*"] = {
                    require("formatter.filetypes.any").remove_trailing_whitespace,
                    function()
                        vim.lsp.buf.format({ async = true })
                    end,
                }
            }
        })
    end
}

But not working, after I call :Format, the code is not formatted.

1
  • Have you tried using :FormatWrite? Commented Sep 8, 2023 at 7:43

1 Answer 1

0

You normally have to specify cmd = { "Format", "FormatWhatever" } on the same level as config.

This is the lazy loading trigger. Currently it is set to lazy, but there is no event or something to trigger the loading of the plugin. You can also go with lazy=false to disable lazy loading. Check some examples maybe in lazyvim how Folke is doing it.

Besides that your setup function looks fine tho.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.