diff options
| author | tami5 <kkharji@protonmail.com> | 2022-03-13 20:11:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-13 18:11:27 +0100 |
| commit | ef7b6ada6d91a1b2932492d78c730e4fc00cd2ea (patch) | |
| tree | dda4cb7cb3357724c83e85666bc8dc5c1ee2e898 /lua/telescope/utils.lua | |
| parent | 75b57304323861631519e204d9fbca7bdbf1c4c5 (diff) | |
feat: improve UX with vim.notify (#1763)
* fix(notify): don't report request on new line
* ref(notify): update message format
* ref(msgs): always quote values + decrease duplication
* fix(ci): undefined variables
* ref(actions): temporary silent actions.__index errors
* cleanup
* revert: panic effort, we continue to use error for those
Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/telescope/utils.lua')
| -rw-r--r-- | lua/telescope/utils.lua | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index c564c06..b8935ca 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -50,7 +50,10 @@ utils.filter_symbols = function(results, opts) local filtered_symbols if has_symbols and has_ignore then - error "Either opts.symbols or opts.ignore_symbols, can't process opposing options at the same time!" + utils.notify("filter_symbols", { + msg = "Either opts.symbols or opts.ignore_symbols, can't process opposing options at the same time!", + level = "ERROR", + }) return elseif not (has_ignore or has_symbols) then return results @@ -59,7 +62,10 @@ utils.filter_symbols = function(results, opts) opts.ignore_symbols = { opts.ignore_symbols } end if type(opts.ignore_symbols) ~= "table" then - print "Please pass ignore_symbols as either a string or a list of strings" + utils.notify("filter_symbols", { + msg = "Please pass ignore_symbols as either a string or a list of strings", + level = "ERROR", + }) return end @@ -72,7 +78,10 @@ utils.filter_symbols = function(results, opts) opts.symbols = { opts.symbols } end if type(opts.symbols) ~= "table" then - print "Please pass filtering symbols as either a string or a list of strings" + utils.notify("filter_symbols", { + msg = "Please pass filtering symbols as either a string or a list of strings", + level = "ERROR", + }) return end @@ -113,10 +122,16 @@ utils.filter_symbols = function(results, opts) -- print message that filtered_symbols is now empty if has_symbols then local symbols = table.concat(opts.symbols, ", ") - print(string.format("%s symbol(s) were not part of the query results", symbols)) + utils.notify("filter_symbols", { + msg = string.format("%s symbol(s) were not part of the query results", symbols), + level = "WARN", + }) elseif has_ignore then local symbols = table.concat(opts.ignore_symbols, ", ") - print(string.format("%s ignore_symbol(s) have removed everything from the query result", symbols)) + utils.notify("filter_symbols", { + msg = string.format("%s ignore_symbol(s) have removed everything from the query result", symbols), + level = "WARN", + }) end end @@ -370,7 +385,10 @@ end function utils.get_os_command_output(cmd, cwd) if type(cmd) ~= "table" then - print "Telescope: [get_os_command_output]: cmd has to be a table" + utils.notify("get_os_command_output", { + msg = "cmd has to be a table", + level = "ERROR", + }) return {} end local command = table.remove(cmd, 1) @@ -457,4 +475,25 @@ utils.get_devicons = load_once(function() end end) +--- Telescope Wrapper around vim.notify +---@param funname string: name of the function that will be +---@param opts table: opts.level string, opts.msg string +utils.notify = function(funname, opts) + local level = vim.log.levels[opts.level] + if not level then + error("Invalid error level", 2) + end + + vim.notify(string.format("[telescope.%s]: %s", funname, opts.msg), level, { + title = "telescope.nvim", + }) +end + +utils.__warn_no_selection = function(name) + utils.notify(name, { + msg = "Nothing currently selected", + level = "WARN", + }) +end + return utils |
