From bef36bb2fd7493828529ed49a071d240602b164d Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 16 Apr 2023 10:47:36 +0200 Subject: [PATCH] fix(format): ignore vim.b.autoformat when formatting using key bindings. Fixes #575 --- lua/lazyvim/plugins/lsp/format.lua | 5 +++-- lua/lazyvim/plugins/lsp/keymaps.lua | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lua/lazyvim/plugins/lsp/format.lua b/lua/lazyvim/plugins/lsp/format.lua index 3605fc54..06841e21 100644 --- a/lua/lazyvim/plugins/lsp/format.lua +++ b/lua/lazyvim/plugins/lsp/format.lua @@ -18,9 +18,10 @@ function M.toggle() end end -function M.format() +---@param opts? {force?:boolean} +function M.format(opts) local buf = vim.api.nvim_get_current_buf() - if vim.b.autoformat == false then + if vim.b.autoformat == false and not (opts and opts.force) then return end local ft = vim.bo[buf].filetype diff --git a/lua/lazyvim/plugins/lsp/keymaps.lua b/lua/lazyvim/plugins/lsp/keymaps.lua index 37301b50..e6f8d755 100644 --- a/lua/lazyvim/plugins/lsp/keymaps.lua +++ b/lua/lazyvim/plugins/lsp/keymaps.lua @@ -5,7 +5,9 @@ M._keys = nil ---@return (LazyKeys|{has?:string})[] function M.get() - local format = require("lazyvim.plugins.lsp.format").format + local format = function() + require("lazyvim.plugins.lsp.format").format({ force = true }) + end if not M._keys then ---@class PluginLspKeys -- stylua: ignore