Skip to content

Commit 0fd8488

Browse files
committed
feat(notify): use nvim_echo instead of vim.notify
1 parent f224604 commit 0fd8488

16 files changed

Lines changed: 132 additions & 89 deletions

File tree

lua/fzf-lua/actions.lua

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ M.vimcmd_entry = function(_vimcmd, selected, opts, pcall_vimcmd)
233233
end
234234
if pcall_vimcmd ~= false then
235235
local ok, err = pcall(function() vim.cmd(vimcmd) end)
236-
if not ok then utils.warn(string.format("':%s' failed: %s", vimcmd, err)) end
236+
if not ok then utils.error("':%s' failed: %s", vimcmd, err) end
237237
else
238238
vim.cmd(vimcmd)
239239
end
@@ -514,7 +514,7 @@ end
514514
M.toggle_bg = function(_, _)
515515
vim.o.background = vim.o.background == "dark" and "light" or "dark"
516516
utils.setup_highlights()
517-
utils.info(string.format([[background set to "%s"]], vim.o.background))
517+
utils.info([[background set to '%s']], vim.o.background)
518518
end
519519

520520
M.hi = function(selected)
@@ -789,7 +789,7 @@ M.git_switch = function(selected, opts)
789789
table.insert(cmd, branch)
790790
local output, rc = utils.io_systemlist(cmd)
791791
if rc ~= 0 then
792-
utils.err(unpack(output))
792+
utils.error(unpack(output))
793793
else
794794
utils.info(unpack(output))
795795
vim.cmd("checktime")
@@ -809,9 +809,9 @@ M.git_branch_add = function(selected, opts)
809809
table.insert(cmd_add_branch, branch)
810810
local output, rc = utils.io_systemlist(cmd_add_branch)
811811
if rc ~= 0 then
812-
utils.err(unpack(output))
812+
utils.error(unpack(output))
813813
else
814-
utils.info(string.format("Created branch '%s'.", branch))
814+
utils.info("Created branch '%s'.", branch)
815815
end
816816
end
817817
end
@@ -823,14 +823,14 @@ M.git_branch_del = function(selected, opts)
823823
local branch = selected[1]:match("[^%s%*]+")
824824
local cur_branch = utils.io_systemlist(cmd_cur_branch)[1]
825825
if branch == cur_branch then
826-
utils.warn(string.format("Cannot delete active branch '%s'", branch))
826+
utils.warn("Cannot delete active branch '%s'", branch)
827827
return
828828
end
829829
if vim.fn.confirm("Delete branch " .. branch .. "?", "&Yes\n&No") == 1 then
830830
table.insert(cmd_del_branch, branch)
831831
local output, rc = utils.io_systemlist(cmd_del_branch)
832832
if rc ~= 0 then
833-
utils.err(unpack(output))
833+
utils.error(unpack(output))
834834
else
835835
utils.info(unpack(output))
836836
end
@@ -857,8 +857,15 @@ M.git_yank_commit = function(selected, opts)
857857
vim.fn.setreg(reg, commit_hash)
858858
end
859859
vim.fn.setreg([[0]], commit_hash)
860-
utils.info(string.format("commit hash %s copied to register %s, use 'p' to paste.",
861-
commit_hash, regs[1]))
860+
utils.info({
861+
"commit hash ",
862+
{ commit_hash, "DiagnosticVirtualLinesWarn" },
863+
" copied to register ",
864+
{ regs[1], "DiagnosticVirtualLinesHint" },
865+
", use '",
866+
{ "p", "DiagnosticVirtualLinesHint" },
867+
"' to paste.",
868+
})
862869
end
863870

864871
M.git_checkout = function(selected, opts)
@@ -871,7 +878,7 @@ M.git_checkout = function(selected, opts)
871878
table.insert(cmd_checkout, commit_hash)
872879
local output, rc = utils.io_systemlist(cmd_checkout)
873880
if rc ~= 0 then
874-
utils.err(unpack(output))
881+
utils.error(unpack(output))
875882
else
876883
utils.info(unpack(output))
877884
vim.cmd("checktime")
@@ -887,7 +894,7 @@ local git_exec = function(selected, opts, cmd, silent)
887894
table.insert(_cmd, file)
888895
local output, rc = utils.io_systemlist(_cmd)
889896
if rc ~= 0 and not silent then
890-
utils.err(unpack(output) or string.format("exit code %d", rc))
897+
utils.error(unpack(output) or string.format("exit code %d", rc))
891898
end
892899
success = rc == 0
893900
end
@@ -1064,10 +1071,9 @@ M.tmux_buf_set_reg = function(selected, opts)
10641071
opts.register = opts.register or [["]]
10651072
local ok, err = pcall(vim.fn.setreg, opts.register, data)
10661073
if ok then
1067-
utils.info(string.format("%d characters copied into register %s",
1068-
#data, opts.register))
1074+
utils.info("%d characters copied into register %s", #data, opts.register)
10691075
else
1070-
utils.err(string.format("setreg(%s) failed: %s", opts.register, err))
1076+
utils.error("setreg(%s) failed: %s", opts.register, err)
10711077
end
10721078
end
10731079
end

lua/fzf-lua/cmd.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function M.run_command(cmd, ...)
1111
cmd = cmd or "builtin"
1212

1313
if not builtin[cmd] then
14-
utils.info(string.format("invalid command '%s'", cmd))
14+
utils.error("invalid command '%s'", cmd)
1515
return
1616
end
1717

lua/fzf-lua/config.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -674,18 +674,18 @@ function M.normalize_opts(opts, globals, __resume_key)
674674
opts.__FZF_VERSION = FZF_VERSION
675675
vim.g.fzf_lua_fzf_version = FZF_VERSION
676676
if not opts.__FZF_VERSION then
677-
utils.err(string.format("'fzf --version' failed with error %s: %s", rc, err))
677+
utils.error("'fzf --version' failed with error %s: %s", rc, err)
678678
return nil
679679
elseif not utils.has(opts, "fzf", { 0, 36 }) then
680-
utils.err(string.format("fzf version %s is lower than minimum (0.36), aborting.",
681-
utils.ver2str(opts.__FZF_VERSION)))
680+
utils.error("fzf version %s is lower than minimum (0.36), aborting.",
681+
utils.ver2str(opts.__FZF_VERSION))
682682
return nil
683683
end
684684
else
685685
local SK_VERSION, rc, err = utils.sk_version(opts)
686686
opts.__SK_VERSION = SK_VERSION
687687
if not opts.__SK_VERSION then
688-
utils.err(string.format("'sk --version' failed with error %s: %s", rc, err))
688+
utils.error("'sk --version' failed with error %s: %s", rc, err)
689689
return nil
690690
end
691691
end
@@ -782,12 +782,12 @@ function M.normalize_opts(opts, globals, __resume_key)
782782
end
783783
end)()
784784
local function warn(flag, val, min_ver)
785-
return utils.warn(string.format("Removed flag '%s%s', %s.",
785+
return utils.warn("Removed flag '%s%s', %s.",
786786
flag, type(val) == "string" and "=" .. val or "",
787787
not min_ver and string.format("not supported with %s", bin)
788788
or string.format("only supported with %s v%s (has=%s)",
789789
bin, utils.ver2str(min_ver), utils.ver2str(version))
790-
))
790+
)
791791
end
792792
for min_verstr, ver_data in pairs(changelog) do
793793
for flag, non_compat_value in pairs(ver_data.fzf_opts) do
@@ -872,8 +872,8 @@ function M.normalize_opts(opts, globals, __resume_key)
872872
-- don't display the warning unless the user specifically set
873873
-- file_icons to `true` or `mini|devicons`
874874
if not tonumber(opts.file_icons) then
875-
utils.warn(string.format("error loading '%s', disabling 'file_icons'.",
876-
opts.file_icons == "mini" and "mini.icons" or "nvim-web-devicons"))
875+
utils.warn("error loading '%s', disabling 'file_icons'.",
876+
opts.file_icons == "mini" and "mini.icons" or "nvim-web-devicons")
877877
end
878878
opts.file_icons = nil
879879
end

lua/fzf-lua/core.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ M.fzf_wrap = function(cmd, opts, convert_actions)
259259
if err and err:match("Vim%(edit%):E325") then
260260
return
261261
end
262-
utils.err("fn_selected threw an error: " .. debug.traceback(err, 1))
262+
utils.error("fn_selected threw an error: " .. debug.traceback(err, 1))
263263
end)
264264
-- Do not strt fzf, return the stringified contents and opts onlu
265265
-- used by the "combine" picker to merge inputs
@@ -678,8 +678,8 @@ M.build_fzf_cli = function(opts, fzf_win)
678678
v = [["]] .. v:sub(2, #v - 1) .. [["]]
679679
end
680680
if libuv.is_escaped(v) then
681-
utils.warn(string.format("`fzf_opts` are automatically shellescaped."
682-
.. " Please remove surrounding quotes from %s=%s", k, v))
681+
utils.warn("`fzf_opts` are automatically shellescaped."
682+
.. " Please remove surrounding quotes from %s=%s", k, v)
683683
end
684684
opt_v = libuv.is_escaped(v) and v or libuv.shellescape(v)
685685
end

lua/fzf-lua/devicons.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function NvimWebDevicons:load_icons(opts)
105105
end)
106106
if not ok or not all_devicons or utils.tbl_isempty(all_devicons) then
107107
-- something is wrong with devicons
108-
utils.err("devicons.get_icons() is nil or empty!")
108+
utils.error("devicons.get_icons() is nil or empty!")
109109
return
110110
end
111111
local icons = {

lua/fzf-lua/previewer/builtin.lua

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function TSContext.inc_dec_maxlines(num, winid, bufnr)
7878
local config = require("treesitter-context.config")
7979
local max_lines = config.max_lines or 0
8080
config.max_lines = math.max(0, max_lines + tonumber(num))
81-
utils.info(string.format("treesitter-context `max_lines` set to %d.", config.max_lines))
81+
utils.info("treesitter-context `max_lines` set to %d.", config.max_lines)
8282
if TSContext.is_attached(winid) then
8383
for _, t in ipairs({ 0, 20 }) do
8484
vim.defer_fn(function() TSContext.update(winid, bufnr) end, t)
@@ -93,7 +93,7 @@ end
9393
function TSContext.update(winid, bufnr, opts)
9494
opts = opts or {}
9595
if not TSContext.setup(opts) then return end
96-
assert(bufnr == vim.api.nvim_win_get_buf(winid))
96+
assert(not vim.api.nvim_win_is_valid(winid) or bufnr == vim.api.nvim_win_get_buf(winid))
9797
local render = require("treesitter-context.render")
9898
local context_ranges, context_lines = require("treesitter-context.context").get(winid)
9999
if not context_ranges or #context_ranges == 0 then
@@ -965,8 +965,7 @@ local ts_attach = function(bufnr, ft)
965965
if lang and loaded then
966966
local ok, err = pcall(vim.treesitter.start, bufnr, lang)
967967
if not ok then
968-
utils.warn(string.format(
969-
"unable to attach treesitter highlighter for filetype '%s': %s", ft, err))
968+
utils.warn("unable to attach treesitter highlighter for filetype '%s': %s", ft, err)
970969
end
971970
return ok
972971
end
@@ -1104,12 +1103,12 @@ function Previewer.buffer_or_file:do_syntax(entry)
11041103
syntax_limit_reached = 2
11051104
end
11061105
if syntax_limit_reached > 0 and self.opts.silent == false then
1107-
utils.info(string.format(
1106+
utils.info(
11081107
"syntax disabled for '%s' (%s), consider increasing '%s(%d)'", entry.path,
11091108
syntax_limit_reached == 1 and ("%d lines"):format(lcount) or ("%db"):format(bytes),
11101109
syntax_limit_reached == 1 and "syntax_limit_l" or "syntax_limit_b",
11111110
syntax_limit_reached == 1 and self.syntax_limit_l or self.syntax_limit_b
1112-
))
1111+
)
11131112
end
11141113

11151114
if syntax_limit_reached ~= 0 then
@@ -1246,9 +1245,9 @@ function Previewer.buffer_or_file:set_cursor_hl(entry)
12461245
regex_end = tonumber(regex_end) and regex_end - regex_start
12471246
regex_start = tonumber(regex_start) and regex_start + math.max(1, col) or 0
12481247
elseif self.opts.silent ~= true then
1249-
utils.warn(string.format(
1248+
utils.warn(
12501249
[[Unable to init vim.regex with "%s", %s. . Add 'silent=true' to hide this message.]],
1251-
regex, reg))
1250+
regex, reg)
12521251
end
12531252
if regex_start > 0 then
12541253
self.match_id = fn.matchaddpos(self.win.hls.search, { { lnum, regex_start, regex_end } }, 11)

lua/fzf-lua/providers/buffers.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,7 @@ M.treesitter = function(opts)
479479
local ft = vim.bo[bufnr0].ft
480480
local lang = ts.language.get_lang(ft) or ft
481481
if not utils.has_ts_parser(lang) then
482-
utils.info(string.format("No treesitter parser found for '%s' (bufnr=%d).",
483-
bufname0, bufnr0))
482+
utils.info("No treesitter parser found for '%s' (bufnr=%d).", bufname0, bufnr0)
484483
return
485484
end
486485

lua/fzf-lua/providers/colorschemes.lua

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,12 @@ function AsyncDownloadManager:new(opts)
152152
self.max_threads = tonumber(opts.max_threads) > 0 and tonumber(opts.max_threads) or 5
153153
local stat, _ = uv.fs_stat(self.path)
154154
if stat and stat.type ~= "directory" then
155-
utils.warn(string.format(
156-
[["%s" already exists and is not a directory (type:%s)]], self.path, stat.type))
155+
utils.error([["%s" already exists and is not a directory (type:%s)]], self.path, stat.type)
157156
return
158157
end
159158
if not stat then
160159
if vim.fn.mkdir(self.path, "p") ~= 1 then
161-
utils.warn(string.format([[Unable to create cache directory "%s"]], self.path))
160+
utils.error([[Unable to create cache directory "%s"]], self.path)
162161
return
163162
end
164163
end
@@ -192,11 +191,11 @@ function AsyncDownloadManager:load_db(db)
192191
self.db = db
193192
for k, p in pairs(self.db or {}) do
194193
if type(p.url) ~= "string" then
195-
utils.warn(string.format("package %s: missing 'url'", k))
194+
utils.warn("package %s: missing 'url'", k)
196195
return false
197196
end
198197
if type(p.colorschemes) ~= "table" or utils.tbl_isempty(p.colorschemes) then
199-
utils.warn(string.format("package %s: missing or empty 'colorschemes'", k))
198+
utils.warn("package %s: missing or empty 'colorschemes'", k)
200199
return false
201200
end
202201
local github_url = "https://github.com/"
@@ -215,8 +214,7 @@ function AsyncDownloadManager:load_db(db)
215214
for i, v in ipairs(p.colorschemes) do
216215
p.colorschemes[i].disp_name = v.disp_name or p.disp_name
217216
if not v.name and not v.lua and not v.vim then
218-
utils.warn(string.format(
219-
"package %s: colorschemes[%d], must contain at least 'name|lua|vim'", k, i))
217+
utils.warn("package %s: colorschemes[%d], must contain at least 'name|lua|vim'", k, i)
220218
return false
221219
end
222220
end
@@ -298,7 +296,7 @@ function AsyncDownloadManager:jobstart(plugin, job_args)
298296
job_args[2] = vim.tbl_extend("keep", job_args[2] or {},
299297
{
300298
on_exit = function(_, rc, _)
301-
utils.info(string.format("%s [job_id:%d] finished with exit code %s", plugin, job_id, rc))
299+
utils.info("%s [job_id:%d] finished with exit code %s", plugin, job_id, rc)
302300
if type(info.on_exit) == "function" then
303301
-- this calls `coroutine.resume` and resumes fzf's reload input stream
304302
info.on_exit(_, rc, _)
@@ -313,11 +311,10 @@ function AsyncDownloadManager:jobstart(plugin, job_args)
313311
if job_id == 0 then
314312
utils.warn("jobstart: invalid args")
315313
elseif job_id == -1 then
316-
utils.warn(string.format([[jobstart: "%s" is not executable]], job_args[1]))
314+
utils.warn([[jobstart: "%s" is not executable]], job_args[1])
317315
else
318316
-- job started successfully
319-
utils.info(string.format("%s [path:%s] [job_id:%d]...",
320-
msg, path.HOME_to_tilde(assert(info.path)), job_id))
317+
utils.info("%s [path:%s] [job_id:%d]...", msg, path.HOME_to_tilde(assert(info.path)), job_id)
321318
self.job_ids[tostring(job_id)] = { plugin = plugin, args = job_args }
322319
self.db[plugin].job_id = job_id
323320
end
@@ -352,7 +349,7 @@ M.apply_awesome_theme = function(dbkey, idx, opts)
352349
-- TODO: should we check `package.loaded[...]` before packadd?
353350
local ok, out = pcall(function() vim.cmd("packadd " .. p.dir) end)
354351
if not ok then
355-
utils.warn(string.format("Unable to packadd %s: %s", p.dir, tostring(out)))
352+
utils.error("Unable to packadd %s: %s", p.dir, tostring(out))
356353
return
357354
end
358355
if cs.vim then
@@ -363,7 +360,7 @@ M.apply_awesome_theme = function(dbkey, idx, opts)
363360
ok, out = pcall(function() vim.cmd("colorscheme " .. cs.name) end)
364361
end
365362
if not ok then
366-
utils.warn(string.format("Unable to apply colorscheme %s: %s", cs.disp_name, tostring(out)))
363+
utils.error("Unable to apply colorscheme %s: %s", cs.disp_name, tostring(out))
367364
end
368365
end
369366

@@ -382,13 +379,13 @@ M.awesome_colorschemes = function(opts)
382379

383380
local json_string = utils.read_file(dbfile)
384381
if not json_string or #json_string == 0 then
385-
utils.warn(string.format("Unable to load json db (%s)", opts.dbfile))
382+
utils.error("Unable to load json db (%s)", opts.dbfile)
386383
return
387384
end
388385

389386
local ok, json_db = pcall(vim.json.decode, json_string)
390387
if not ok then
391-
utils.warn(string.format("Json decode failed: %s", json_db))
388+
utils.error(string.format("Json decode failed: %s", json_db))
392389
return
393390
end
394391

lua/fzf-lua/providers/diagnostic.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ M.diagnostics = function(opts)
153153
end
154154
end
155155
if not has_diags then
156-
utils.info(string.format("No %s found", "diagnostics"))
156+
utils.info("No %s found", "diagnostics")
157157
return
158158
end
159159

lua/fzf-lua/providers/git.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ M.diff = function(opts)
9292
local cmd = path.git_cwd({ "git", "rev-parse", "--verify", opts.ref }, opts)
9393
local _, err = utils.io_systemlist(cmd)
9494
if err ~= 0 then
95-
utils.warn(string.format("Invalid git ref %s", opts.ref))
95+
utils.warn("Invalid git ref %s", opts.ref)
9696
return
9797
end
9898
for _, k in ipairs({ "cmd", "preview" }) do
@@ -246,7 +246,7 @@ M.hunks = function(opts)
246246
local cmd = path.git_cwd({ "git", "rev-parse", "--verify", opts.ref }, opts)
247247
local _, err = utils.io_systemlist(cmd)
248248
if err ~= 0 then
249-
utils.warn(string.format("Invalid git ref %s", opts.ref))
249+
utils.warn("Invalid git ref %s", opts.ref)
250250
return
251251
end
252252
opts.cmd = opts.cmd:gsub("[<{]ref[}>]", opts.ref)

0 commit comments

Comments
 (0)