Skip to content

Commit

Permalink
feat(formatexpr): don't require LSP range formatting if operating on …
Browse files Browse the repository at this point in the history
…whole file (#272)

solves: #271
  • Loading branch information
ndavd committed Jan 8, 2024
1 parent 0e61fc8 commit 47ceff6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lua/conform/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,17 @@ M.formatexpr = function(opts)
end
local end_line = vim.fn.getline(end_lnum)
local end_col = end_line:len()
opts.range = {
start = { start_lnum, 0 },
["end"] = { end_lnum, end_col },
}

if vim.v.count == vim.fn.line("$") then
-- Whole buffer is selected; use buffer formatting
opts.range = nil
else
opts.range = {
start = { start_lnum, 0 },
["end"] = { end_lnum, end_col },
}
end

if M.format(opts) then
return 0
elseif opts.lsp_fallback and not vim.tbl_isempty(lsp_format.get_format_clients(opts)) then
Expand Down

0 comments on commit 47ceff6

Please sign in to comment.