Skip to content

Commit

Permalink
fix: include number of files in editor message (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 13, 2024
1 parent a8b885b commit 7d2f6d3
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions lua/quicker/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ local function filename_match(item, filename)
end
end

---@param n integer
---@param base string
---@param pluralized? string
---@return string
local function plural(n, base, pluralized)
if n == 1 then
return base
elseif pluralized then
return pluralized
else
return base .. "s"
end
end

---@param item QuickFixItem
---@return QuickFixUserData
local function get_user_data(item)
Expand Down Expand Up @@ -327,7 +341,9 @@ local function save_changes(bufnr, loclist_win)
end
local autosave = config.edit.autosave
local num_applied = 0
local modified_bufs = {}
for chg_buf, text_edits in pairs(changes) do
modified_bufs[chg_buf] = true
num_applied = num_applied + #text_edits
vim.lsp.util.apply_text_edits(text_edits, chg_buf, "utf-8")
local was_modified = buf_was_modified[chg_buf]
Expand All @@ -340,16 +356,30 @@ local function save_changes(bufnr, loclist_win)
end
end
if num_applied > 0 then
local num_files = vim.tbl_count(modified_bufs)
local num_errors = vim.tbl_count(errors)
if num_errors > 0 then
local total = num_errors + num_applied
vim.notify(
string.format("Applied %d/%d change%s", num_applied, total, total == 1 and "" or "s"),
string.format(
"Applied %d/%d %s in %d %s",
num_applied,
total,
plural(total, "change"),
num_files,
plural(num_files, "file")
),
vim.log.levels.WARN
)
else
vim.notify(
string.format("Applied %d change%s", num_applied, num_applied == 1 and "" or "s"),
string.format(
"Applied %d %s in %d %s",
num_applied,
plural(num_applied, "change"),
num_files,
plural(num_files, "file")
),
vim.log.levels.INFO
)
end
Expand Down

0 comments on commit 7d2f6d3

Please sign in to comment.