diff --git a/lua/lazyvim/plugins/lsp/format.lua b/lua/lazyvim/plugins/lsp/format.lua index 556a1214..7b60f9a3 100644 --- a/lua/lazyvim/plugins/lsp/format.lua +++ b/lua/lazyvim/plugins/lsp/format.lua @@ -47,6 +47,44 @@ function M.format(opts) }, require("lazyvim.util").opts("nvim-lspconfig").format or {})) end +---@param formatters LazyVimFormatters +function M.notify(formatters) + local lines = { "# Active:" } + + for _, client in ipairs(formatters.active) do + local line = "- **" .. client.name .. "**" + if client.name == "null-ls" then + line = line + .. " (" + .. table.concat( + vim.tbl_map(function(f) + return "`" .. f.name .. "`" + end, formatters.null_ls), + ", " + ) + .. ")" + end + table.insert(lines, line) + end + + if #formatters.available > 0 then + table.insert(lines, "") + table.insert(lines, "# Disabled:") + for _, client in ipairs(formatters.available) do + table.insert(lines, "- **" .. client.name .. "**") + end + end + + vim.notify(table.concat(lines, "\n"), vim.log.levels.INFO, { + title = "Formatting", + on_open = function(win) + vim.api.nvim_win_set_option(win, "conceallevel", 3) + vim.api.nvim_win_set_option(win, "spell", false) + local buf = vim.api.nvim_win_get_buf(win) + vim.treesitter.start(buf, "markdown") + end, + }) +end -- Gets all lsp clients that support formatting. -- When a null-ls formatter is available for the current filetype, diff --git a/lua/lazyvim/plugins/lsp/init.lua b/lua/lazyvim/plugins/lsp/init.lua index 188c8be0..54c69473 100644 --- a/lua/lazyvim/plugins/lsp/init.lua +++ b/lua/lazyvim/plugins/lsp/init.lua @@ -35,6 +35,9 @@ return { capabilities = {}, -- Automatically format on save autoformat = true, + -- Enable this to show formatters used in a notification + -- Useful for debugging formatter issues + format_notify = false, -- options for vim.lsp.buf.format -- `bufnr` and `filter` is handled by the LazyVim formatter, -- but can be also overridden when specified