diff --git a/lua/conform/init.lua b/lua/conform/init.lua index 585b7c8e19f..864d6eb840f 100644 --- a/lua/conform/init.lua +++ b/lua/conform/init.lua @@ -300,6 +300,10 @@ M.format = function(opts, callback) lsp_fallback = false, quiet = false, }) + local mode = vim.api.nvim_get_mode().mode + if not opts.range and mode == "v" or mode == "V" then + opts.range = range_from_selection(opts.bufnr, mode) + end callback = callback or function(_err) end local log = require("conform.log") local lsp_format = require("conform.lsp_format") @@ -323,11 +327,6 @@ M.format = function(opts, callback) end if any_formatters then - local mode = vim.api.nvim_get_mode().mode - if not opts.range and mode == "v" or mode == "V" then - opts.range = range_from_selection(opts.bufnr, mode) - end - ---@param err? conform.Error local function handle_err(err) if err then