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>
This commit is contained in:
tami5
2022-03-13 20:11:27 +03:00
committed by GitHub
parent 75b5730432
commit ef7b6ada6d
17 changed files with 311 additions and 116 deletions

View File

@@ -2,6 +2,7 @@ local conf = require("telescope.config").values
local finders = require "telescope.finders"
local make_entry = require "telescope.make_entry"
local pickers = require "telescope.pickers"
local utils = require "telescope.utils"
local diagnostics = {}
@@ -28,7 +29,10 @@ local diagnostics_to_tbl = function(opts)
local diagnosis_opts = { severity = {}, namespace = opts.namespace }
if opts.severity ~= nil then
if opts.severity_limit ~= nil or opts.severity_bound ~= nil then
print "Invalid severity parameters. Both a specific severity and a limit/bound is not allowed"
utils.notify("builtin.diagnostics", {
msg = "Invalid severity parameters. Both a specific severity and a limit/bound is not allowed",
level = "ERROR",
})
return {}
end
diagnosis_opts.severity = opts.severity
@@ -110,7 +114,10 @@ diagnostics.get = function(opts)
local locations = diagnostics_to_tbl(opts)
if vim.tbl_isempty(locations) then
print "No diagnostics found"
utils.notify("builtin.diagnostics", {
msg = "No diagnostics found",
level = "INFO",
})
return
end

View File

@@ -163,10 +163,10 @@ files.find_files = function(opts)
end)()
if not find_command then
print(
"You need to install either find, fd, or rg. "
.. "You can also submit a PR to add support for another file finder :)"
)
utils.notify("builtin.find_files", {
msg = "You need to install either find, fd, or rg",
level = "ERROR",
})
return
end
@@ -267,13 +267,19 @@ files.treesitter = function(opts)
local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter")
if not has_nvim_treesitter then
print "You need to install nvim-treesitter"
utils.notify("builtin.treesitter", {
msg = "User need to install nvim-treesitter needs to be installed",
level = "ERROR",
})
return
end
local parsers = require "nvim-treesitter.parsers"
if not parsers.has_parser(parsers.get_buf_lang(opts.bufnr)) then
print "No parser for the current buffer"
utils.notify("builtin.treesitter", {
msg = "No parser for the current buffer",
level = "ERROR",
})
return
end
@@ -397,7 +403,10 @@ end
files.tags = function(opts)
local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles()
if vim.tbl_isempty(tagfiles) then
print "No tags file found. Create one with ctags -R"
utils.notify("builtin.tags", {
msg = "No tags file found. Create one with ctags -R",
level = "ERROR",
})
return
end

View File

@@ -15,13 +15,21 @@ local git = {}
git.files = function(opts)
if opts.is_bare then
error "This operation must be run in a work tree"
utils.notify("builtin.git_files", {
msg = "This operation must be run in a work tree",
level = "ERROR",
})
return
end
local show_untracked = utils.get_default(opts.show_untracked, true)
local recurse_submodules = utils.get_default(opts.recurse_submodules, false)
if show_untracked and recurse_submodules then
error "Git does not support both --others and --recurse-submodules"
utils.notify("builtin.git_files", {
msg = "Git does not support both --others and --recurse-submodules",
level = "ERROR",
})
return
end
-- By creating the entry maker after the cwd options,
@@ -300,7 +308,11 @@ end
git.status = function(opts)
if opts.is_bare then
error "This operation must be run in a work tree"
utils.notify("builtin.git_status", {
msg = "This operation must be run in a work tree",
level = "ERROR",
})
return
end
local gen_new_finder = function()
@@ -308,13 +320,17 @@ git.status = function(opts)
local git_cmd = { "git", "status", "-s", "--", "." }
if expand_dir then
table.insert(git_cmd, table.getn(git_cmd) - 1, "-u")
table.insert(git_cmd, #git_cmd - 1, "-u")
end
local output = utils.get_os_command_output(git_cmd, opts.cwd)
if table.getn(output) == 0 then
if #output == 0 then
print "No changes found"
utils.notify("builtin.git_status", {
msg = "No changes found",
level = "WARN",
})
return
end

View File

@@ -84,7 +84,7 @@ internal.builtin = function(opts)
actions.select_default:replace(function(_)
local selection = action_state.get_selected_entry()
if not selection then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.builtin"
return
end
@@ -113,12 +113,18 @@ internal.resume = function(opts)
local cached_pickers = state.get_global_key "cached_pickers"
if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then
print "No picker(s) cached."
utils.notify("builtin.resume", {
msg = "No cached picker(s).",
level = "INFO",
})
return
end
local picker = cached_pickers[opts.cache_index]
if picker == nil then
print(string.format("Index too large as there are only %s pickers cached", #cached_pickers))
utils.notify("builtin.resume", {
msg = string.format("Index too large as there are only '%s' pickers cached", #cached_pickers),
level = "ERROR",
})
return
end
-- reset layout strategy and get_window_options if default as only one is valid
@@ -144,7 +150,10 @@ end
internal.pickers = function(opts)
local cached_pickers = state.get_global_key "cached_pickers"
if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then
print "No picker(s) cached."
utils.notify("builtin.pickers", {
msg = "No cached picker(s).",
level = "INFO",
})
return
end
@@ -213,7 +222,7 @@ internal.planets = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.planets"
return
end
@@ -243,10 +252,11 @@ internal.symbols = function(opts)
end
if #files == 0 then
print(
"No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim "
.. "for some prebuild symbols or how to create you own symbol source."
)
utils.notify("builtin.symbols", {
msg = "No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim "
.. "for some prebuild symbols or how to create you own symbol source.",
level = "ERROR",
})
return
end
@@ -317,7 +327,7 @@ internal.commands = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.commands"
return
end
@@ -505,7 +515,7 @@ internal.vim_options = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.vim_options"
return
end
@@ -636,7 +646,7 @@ internal.help_tags = function(opts)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.help_tags"
return
end
@@ -674,7 +684,7 @@ internal.man_pages = function(opts)
action_set.select:replace(function(_, cmd)
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.man_pages"
return
end
@@ -725,13 +735,16 @@ internal.reloader = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.reloader"
return
end
actions.close(prompt_bufnr)
require("plenary.reload").reload_module(selection.value)
print(string.format("[%s] - module reloaded", selection.value))
utils.notify("builtin.reloader", {
msg = string.format("[%s] - module reloaded", selection.value),
level = "INFO",
})
end)
return true
@@ -878,7 +891,7 @@ internal.colorscheme = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.colorscheme"
return
end
@@ -995,7 +1008,7 @@ internal.keymaps = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.keymaps"
return
end
@@ -1046,7 +1059,7 @@ internal.highlights = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.highlights"
return
end
@@ -1143,7 +1156,7 @@ internal.autocommands = function(opts)
action_set.select:replace(function(_, type)
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.autocommands"
return
end
@@ -1170,7 +1183,7 @@ internal.spell_suggest = function(opts)
actions.select_default:replace(function()
local selection = action_state.get_selected_entry()
if selection == nil then
print "[telescope] Nothing currently selected"
utils.__warn_no_selection "builtin.spell_suggest"
return
end
@@ -1202,7 +1215,10 @@ internal.tagstack = function(opts)
end
if vim.tbl_isempty(tags) then
print "No tagstack available"
utils.notify("builtin.tagstack", {
msg = "No tagstack available",
level = "WARN",
})
return
end

View File

@@ -117,7 +117,10 @@ lsp.document_symbols = function(opts)
end
if not result or vim.tbl_isempty(result) then
print "No results from textDocument/documentSymbol"
utils.notify("builtin.lsp_document_symbols", {
msg = "No results from textDocument/documentSymbol",
level = "INFO",
})
return
end
@@ -129,7 +132,10 @@ lsp.document_symbols = function(opts)
end
if vim.tbl_isempty(locations) then
print "locations table empty"
utils.notify("builtin.lsp_document_symbols", {
msg = "No document_symbol locations found",
level = "INFO",
})
return
end
@@ -165,12 +171,18 @@ lsp.code_actions = function(opts)
)
if err then
print("ERROR: " .. err)
utils.notify("builin.lsp_code_actions", {
msg = err,
level = "ERROR",
})
return
end
if not results_lsp or vim.tbl_isempty(results_lsp) then
print "No results from textDocument/codeAction"
utils.notify("builtin.lsp_document_symbols", {
msg = "No results from textDocument/codeAction",
level = "INFO",
})
return
end
@@ -206,7 +218,10 @@ lsp.code_actions = function(opts)
end
if #results == 0 then
print "No code actions available"
utils.notify("builtin.lsp_document_symbols", {
msg = "No code actions available",
level = "INFO",
})
return
end
@@ -317,7 +332,10 @@ lsp.code_actions = function(opts)
then
client.request("codeAction/resolve", action, function(resolved_err, resolved_action)
if resolved_err then
vim.notify(resolved_err.code .. ": " .. resolved_err.message, vim.log.levels.ERROR)
utils.notify("builtin.lsp_code_actions", {
msg = string.format("codeAction/resolve failed: %s : %s", resolved_err.code, resolved_err.message),
level = "ERROR",
})
return
end
if resolved_action then
@@ -358,10 +376,11 @@ lsp.workspace_symbols = function(opts)
end
if vim.tbl_isempty(locations) then
print(
"No results from workspace/symbol. Maybe try a different query: "
.. "Telescope lsp_workspace_symbols query=example"
)
utils.notify("builtin.lsp_workspace_symbols", {
msg = "No results from workspace/symbol. Maybe try a different query: "
.. "'Telescope lsp_workspace_symbols query=example'",
level = "INFO",
})
return
end
@@ -429,9 +448,15 @@ local function check_capabilities(feature, bufnr)
return true
else
if #clients == 0 then
print "LSP: no client attached"
utils.notify("builtin.lsp_*", {
msg = "no client attached",
level = "INFO",
})
else
print("LSP: server does not support " .. feature)
utils.notify("builtin.lsp_*", {
msg = "server does not support " .. feature,
level = "INFO",
})
end
return false
end