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:
@@ -7,7 +7,7 @@ extensions._health = {}
|
|||||||
local load_extension = function(name)
|
local load_extension = function(name)
|
||||||
local ok, ext = pcall(require, "telescope._extensions." .. name)
|
local ok, ext = pcall(require, "telescope._extensions." .. name)
|
||||||
if not ok then
|
if not ok then
|
||||||
error("This extension doesn't exist or is not installed: " .. name .. "\n" .. ext)
|
error(string.format("'%s' extension doesn't exist or isn't installed: %s", name, ext))
|
||||||
end
|
end
|
||||||
return ext
|
return ext
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local conf = require("telescope.config").values
|
local conf = require("telescope.config").values
|
||||||
local Path = require "plenary.path"
|
local Path = require "plenary.path"
|
||||||
|
local utils = require "telescope.utils"
|
||||||
|
|
||||||
local uv = vim.loop
|
local uv = vim.loop
|
||||||
|
|
||||||
@@ -111,10 +112,10 @@ end
|
|||||||
---@return string: the next history item
|
---@return string: the next history item
|
||||||
function histories.History:get_next(line, picker)
|
function histories.History:get_next(line, picker)
|
||||||
if not self.enabled then
|
if not self.enabled then
|
||||||
print(
|
utils.notify("History:get_next", {
|
||||||
"You are cycling to next the history item but history is disabled.",
|
msg = "You are cycling to next the history item but history is disabled. Read ':help telescope.defaults.history'",
|
||||||
"Read ':help telescope.defaults.history'"
|
level = "WARN",
|
||||||
)
|
})
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if self._pre_get then
|
if self._pre_get then
|
||||||
@@ -136,10 +137,10 @@ end
|
|||||||
---@return string: the previous history item
|
---@return string: the previous history item
|
||||||
function histories.History:get_prev(line, picker)
|
function histories.History:get_prev(line, picker)
|
||||||
if not self.enabled then
|
if not self.enabled then
|
||||||
print(
|
utils.notify("History:get_prev", {
|
||||||
"You are cycling to previous the history item but history is disabled.",
|
msg = "You are cycling to next the history item but history is disabled. Read ':help telescope.defaults.history'",
|
||||||
"Read ':help telescope.defaults.history'"
|
level = "WARN",
|
||||||
)
|
})
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
if self._pre_get then
|
if self._pre_get then
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ end
|
|||||||
actions.edit_command_line = function(prompt_bufnr)
|
actions.edit_command_line = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.edit_command_line"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
@@ -285,7 +285,7 @@ end
|
|||||||
actions.set_command_line = function(prompt_bufnr)
|
actions.set_command_line = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.set_command_line"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
@@ -296,7 +296,7 @@ end
|
|||||||
actions.edit_search_line = function(prompt_bufnr)
|
actions.edit_search_line = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.edit_search_line"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
@@ -306,7 +306,7 @@ end
|
|||||||
actions.set_search_line = function(prompt_bufnr)
|
actions.set_search_line = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.set_search_line"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
@@ -338,7 +338,7 @@ end
|
|||||||
actions.paste_register = function(prompt_bufnr)
|
actions.paste_register = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.paste_register"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -346,7 +346,6 @@ actions.paste_register = function(prompt_bufnr)
|
|||||||
|
|
||||||
-- ensure that the buffer can be written to
|
-- ensure that the buffer can be written to
|
||||||
if vim.api.nvim_buf_get_option(vim.api.nvim_get_current_buf(), "modifiable") then
|
if vim.api.nvim_buf_get_option(vim.api.nvim_get_current_buf(), "modifiable") then
|
||||||
print "Paste!"
|
|
||||||
vim.api.nvim_paste(selection.content, true, -1)
|
vim.api.nvim_paste(selection.content, true, -1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -370,7 +369,7 @@ end
|
|||||||
actions.insert_value = function(prompt_bufnr)
|
actions.insert_value = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.insert_value"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -388,11 +387,17 @@ actions.git_create_branch = function(prompt_bufnr)
|
|||||||
local new_branch = action_state.get_current_line()
|
local new_branch = action_state.get_current_line()
|
||||||
|
|
||||||
if new_branch == "" then
|
if new_branch == "" then
|
||||||
print "Please enter the name of the new branch to create"
|
utils.notify("actions.git_create_branch", {
|
||||||
|
msg = "Missing the new branch name",
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
local confirmation = vim.fn.input(string.format('Create new branch "%s"? [y/n]: ', new_branch))
|
local confirmation = vim.fn.input(string.format("Create new branch '%s'? [y/n]: ", new_branch))
|
||||||
if string.len(confirmation) == 0 or string.sub(string.lower(confirmation), 0, 1) ~= "y" then
|
if string.len(confirmation) == 0 or string.sub(string.lower(confirmation), 0, 1) ~= "y" then
|
||||||
print(string.format('Didn\'t create branch "%s"', new_branch))
|
utils.notify("actions.git_create_branch", {
|
||||||
|
msg = string.format("fail to create branch: '%s'", new_branch),
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -400,11 +405,19 @@ actions.git_create_branch = function(prompt_bufnr)
|
|||||||
|
|
||||||
local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", "-b", new_branch }, cwd)
|
local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", "-b", new_branch }, cwd)
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
print(string.format("Switched to a new branch: %s", new_branch))
|
utils.notify("actions.git_create_branch", {
|
||||||
|
msg = string.format("Switched to a new branch: %s", new_branch),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print(
|
utils.notify("actions.git_create_branch", {
|
||||||
string.format('Error when creating new branch: %s Git returned "%s"', new_branch, table.concat(stderr, " "))
|
msg = string.format(
|
||||||
)
|
"Error when creating new branch: '%s' Git returned '%s'",
|
||||||
|
new_branch,
|
||||||
|
table.concat(stderr, " ")
|
||||||
|
),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -414,15 +427,21 @@ end
|
|||||||
actions.git_apply_stash = function(prompt_bufnr)
|
actions.git_apply_stash = function(prompt_bufnr)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.git_apply_stash"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local _, ret, stderr = utils.get_os_command_output { "git", "stash", "apply", "--index", selection.value }
|
local _, ret, stderr = utils.get_os_command_output { "git", "stash", "apply", "--index", selection.value }
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
print("applied: " .. selection.value)
|
utils.notify("actions.git_apply_stash", {
|
||||||
|
msg = string.format("applied: '%s' ", selection.value),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print(string.format('Error when applying: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")))
|
utils.notify("actions.git_apply_stash", {
|
||||||
|
msg = string.format("Error when applying: %s. Git returned: '%s'", selection.value, table.concat(stderr, " ")),
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -432,15 +451,25 @@ actions.git_checkout = function(prompt_bufnr)
|
|||||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.git_checkout"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", selection.value }, cwd)
|
local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", selection.value }, cwd)
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
print("Checked out: " .. selection.value)
|
utils.notify("actions.git_checkout", {
|
||||||
|
msg = string.format("Checked out: ", selection.value),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print(string.format('Error when checking out: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")))
|
utils.notify("actions.git_checkout", {
|
||||||
|
msg = string.format(
|
||||||
|
"Error when checking out: %s. Git returned: '%s'",
|
||||||
|
selection.value,
|
||||||
|
table.concat(stderr, " ")
|
||||||
|
),
|
||||||
|
level = "ERORR",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -452,7 +481,7 @@ actions.git_switch_branch = function(prompt_bufnr)
|
|||||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.git_switch_branch"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
@@ -463,9 +492,19 @@ actions.git_switch_branch = function(prompt_bufnr)
|
|||||||
end
|
end
|
||||||
local _, ret, stderr = utils.get_os_command_output({ "git", "switch", branch }, cwd)
|
local _, ret, stderr = utils.get_os_command_output({ "git", "switch", branch }, cwd)
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
print("Switched to: " .. branch)
|
utils.notify("actions.git_switch_branch", {
|
||||||
|
msg = string.format("Switched to: '%s'", branch),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print(string.format('Error when switching to: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")))
|
utils.notify("actions.git_switch_branch", {
|
||||||
|
msg = string.format(
|
||||||
|
"Error when switching to: %s. Git returned: '%s'",
|
||||||
|
selection.value,
|
||||||
|
table.concat(stderr, " ")
|
||||||
|
),
|
||||||
|
level = "ERORR",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -474,7 +513,7 @@ local function make_git_branch_action(opts)
|
|||||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection(opts.action_name)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -489,9 +528,15 @@ local function make_git_branch_action(opts)
|
|||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local _, ret, stderr = utils.get_os_command_output(opts.command(selection.value), cwd)
|
local _, ret, stderr = utils.get_os_command_output(opts.command(selection.value), cwd)
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
print(string.format(opts.success_message, selection.value))
|
utils.notify(opts.action_name, {
|
||||||
|
msg = string.format(opts.success_message, selection.value),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print(string.format(opts.error_message, selection.value, table.concat(stderr, " ")))
|
utils.notify(opts.action_name, {
|
||||||
|
msg = string.format(opts.error_message, selection.value, table.concat(stderr, " ")),
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -500,8 +545,9 @@ end
|
|||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
actions.git_track_branch = make_git_branch_action {
|
actions.git_track_branch = make_git_branch_action {
|
||||||
should_confirm = false,
|
should_confirm = false,
|
||||||
|
action_name = "actions.git_track_branch",
|
||||||
success_message = "Tracking branch: %s",
|
success_message = "Tracking branch: %s",
|
||||||
error_message = 'Error when tracking branch: %s. Git returned: "%s"',
|
error_message = "Error when tracking branch: %s. Git returned: '%s'",
|
||||||
command = function(branch_name)
|
command = function(branch_name)
|
||||||
return { "git", "checkout", "--track", branch_name }
|
return { "git", "checkout", "--track", branch_name }
|
||||||
end,
|
end,
|
||||||
@@ -511,9 +557,10 @@ actions.git_track_branch = make_git_branch_action {
|
|||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
actions.git_delete_branch = make_git_branch_action {
|
actions.git_delete_branch = make_git_branch_action {
|
||||||
should_confirm = true,
|
should_confirm = true,
|
||||||
|
action_name = "actions.git_delete_branch",
|
||||||
confirmation_question = "Do you really wanna delete branch %s? [Y/n] ",
|
confirmation_question = "Do you really wanna delete branch %s? [Y/n] ",
|
||||||
success_message = "Deleted branch: %s",
|
success_message = "Deleted branch: %s",
|
||||||
error_message = 'Error when deleting branch: %s. Git returned: "%s"',
|
error_message = "Error when deleting branch: %s. Git returned: '%s'",
|
||||||
command = function(branch_name)
|
command = function(branch_name)
|
||||||
return { "git", "branch", "-D", branch_name }
|
return { "git", "branch", "-D", branch_name }
|
||||||
end,
|
end,
|
||||||
@@ -523,9 +570,10 @@ actions.git_delete_branch = make_git_branch_action {
|
|||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
actions.git_merge_branch = make_git_branch_action {
|
actions.git_merge_branch = make_git_branch_action {
|
||||||
should_confirm = true,
|
should_confirm = true,
|
||||||
|
action_name = "actions.git_merge_branch",
|
||||||
confirmation_question = "Do you really wanna merge branch %s? [Y/n] ",
|
confirmation_question = "Do you really wanna merge branch %s? [Y/n] ",
|
||||||
success_message = "Merged branch: %s",
|
success_message = "Merged branch: %s",
|
||||||
error_message = 'Error when merging branch: %s. Git returned: "%s"',
|
error_message = "Error when merging branch: %s. Git returned: '%s'",
|
||||||
command = function(branch_name)
|
command = function(branch_name)
|
||||||
return { "git", "merge", branch_name }
|
return { "git", "merge", branch_name }
|
||||||
end,
|
end,
|
||||||
@@ -535,9 +583,10 @@ actions.git_merge_branch = make_git_branch_action {
|
|||||||
---@param prompt_bufnr number: The prompt bufnr
|
---@param prompt_bufnr number: The prompt bufnr
|
||||||
actions.git_rebase_branch = make_git_branch_action {
|
actions.git_rebase_branch = make_git_branch_action {
|
||||||
should_confirm = true,
|
should_confirm = true,
|
||||||
|
action_name = "actions.git_rebase_branch",
|
||||||
confirmation_question = "Do you really wanna rebase branch %s? [Y/n] ",
|
confirmation_question = "Do you really wanna rebase branch %s? [Y/n] ",
|
||||||
success_message = "Rebased branch: %s",
|
success_message = "Rebased branch: %s",
|
||||||
error_message = 'Error when rebasing branch: %s. Git returned: "%s"',
|
error_message = "Error when rebasing branch: %s. Git returned: '%s'",
|
||||||
command = function(branch_name)
|
command = function(branch_name)
|
||||||
return { "git", "rebase", branch_name }
|
return { "git", "rebase", branch_name }
|
||||||
end,
|
end,
|
||||||
@@ -547,7 +596,7 @@ local git_reset_branch = function(prompt_bufnr, mode)
|
|||||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.git_reset_branch"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -559,9 +608,15 @@ local git_reset_branch = function(prompt_bufnr, mode)
|
|||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local _, ret, stderr = utils.get_os_command_output({ "git", "reset", mode, selection.value }, cwd)
|
local _, ret, stderr = utils.get_os_command_output({ "git", "reset", mode, selection.value }, cwd)
|
||||||
if ret == 0 then
|
if ret == 0 then
|
||||||
print("Reset to: " .. selection.value)
|
utils.notify("actions.git_rebase_branch", {
|
||||||
|
msg = string.format("Reset to: '%s'", selection.value),
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print(string.format('Error when resetting to: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")))
|
utils.notify("actions.git_rebase_branch", {
|
||||||
|
msg = string.format("Rest to: %s. Git returned: '%s'", selection.value, table.concat(stderr, " ")),
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -587,7 +642,8 @@ actions.git_checkout_current_buffer = function(prompt_bufnr)
|
|||||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.git_checkout_current_buffer"
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
@@ -600,7 +656,7 @@ actions.git_staging_toggle = function(prompt_bufnr)
|
|||||||
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
local cwd = action_state.get_current_picker(prompt_bufnr).cwd
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "actions.git_staging_toggle"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if selection.status:sub(2) == " " then
|
if selection.status:sub(2) == " " then
|
||||||
@@ -707,7 +763,7 @@ end
|
|||||||
|
|
||||||
local smart_send = function(prompt_bufnr, mode, target)
|
local smart_send = function(prompt_bufnr, mode, target)
|
||||||
local picker = action_state.get_current_picker(prompt_bufnr)
|
local picker = action_state.get_current_picker(prompt_bufnr)
|
||||||
if table.getn(picker:get_multi_selection()) > 0 then
|
if #picker:get_multi_selection() > 0 then
|
||||||
send_selected_to_qf(prompt_bufnr, mode, target)
|
send_selected_to_qf(prompt_bufnr, mode, target)
|
||||||
else
|
else
|
||||||
send_all_to_qf(prompt_bufnr, mode, target)
|
send_all_to_qf(prompt_bufnr, mode, target)
|
||||||
@@ -744,7 +800,11 @@ actions.complete_tag = function(prompt_bufnr)
|
|||||||
local delimiter = current_picker.sorter._delimiter
|
local delimiter = current_picker.sorter._delimiter
|
||||||
|
|
||||||
if not tags then
|
if not tags then
|
||||||
print "No tag pre-filtering set for this picker"
|
utils.notify("actions.complete_tag", {
|
||||||
|
msg = "No tag pre-filtering set for this picker",
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -771,7 +831,10 @@ actions.complete_tag = function(prompt_bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(filtered_tags) then
|
if vim.tbl_isempty(filtered_tags) then
|
||||||
print "No matches found"
|
utils.notify("complete_tag", {
|
||||||
|
msg = "No matches found",
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ local a = vim.api
|
|||||||
local log = require "telescope.log"
|
local log = require "telescope.log"
|
||||||
local Path = require "plenary.path"
|
local Path = require "plenary.path"
|
||||||
local state = require "telescope.state"
|
local state = require "telescope.state"
|
||||||
|
local utils = require "telescope.utils"
|
||||||
|
|
||||||
local action_state = require "telescope.actions.state"
|
local action_state = require "telescope.actions.state"
|
||||||
|
|
||||||
@@ -88,7 +89,10 @@ action_set.edit = function(prompt_bufnr, command)
|
|||||||
local entry = action_state.get_selected_entry()
|
local entry = action_state.get_selected_entry()
|
||||||
|
|
||||||
if not entry then
|
if not entry then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.notify("actions.set.edit", {
|
||||||
|
msg = "Nothing currently selected",
|
||||||
|
level = "WARN",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -105,7 +109,10 @@ action_set.edit = function(prompt_bufnr, command)
|
|||||||
-- to put stuff into `filename`
|
-- to put stuff into `filename`
|
||||||
local value = entry.value
|
local value = entry.value
|
||||||
if not value then
|
if not value then
|
||||||
print "Could not do anything with blank line..."
|
utils.notify("actions.set.edit", {
|
||||||
|
msg = "Could not do anything with blank line...",
|
||||||
|
level = "WARN",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local conf = require("telescope.config").values
|
|||||||
local finders = require "telescope.finders"
|
local finders = require "telescope.finders"
|
||||||
local make_entry = require "telescope.make_entry"
|
local make_entry = require "telescope.make_entry"
|
||||||
local pickers = require "telescope.pickers"
|
local pickers = require "telescope.pickers"
|
||||||
|
local utils = require "telescope.utils"
|
||||||
|
|
||||||
local diagnostics = {}
|
local diagnostics = {}
|
||||||
|
|
||||||
@@ -28,7 +29,10 @@ local diagnostics_to_tbl = function(opts)
|
|||||||
local diagnosis_opts = { severity = {}, namespace = opts.namespace }
|
local diagnosis_opts = { severity = {}, namespace = opts.namespace }
|
||||||
if opts.severity ~= nil then
|
if opts.severity ~= nil then
|
||||||
if opts.severity_limit ~= nil or opts.severity_bound ~= 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 {}
|
return {}
|
||||||
end
|
end
|
||||||
diagnosis_opts.severity = opts.severity
|
diagnosis_opts.severity = opts.severity
|
||||||
@@ -110,7 +114,10 @@ diagnostics.get = function(opts)
|
|||||||
local locations = diagnostics_to_tbl(opts)
|
local locations = diagnostics_to_tbl(opts)
|
||||||
|
|
||||||
if vim.tbl_isempty(locations) then
|
if vim.tbl_isempty(locations) then
|
||||||
print "No diagnostics found"
|
utils.notify("builtin.diagnostics", {
|
||||||
|
msg = "No diagnostics found",
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -163,10 +163,10 @@ files.find_files = function(opts)
|
|||||||
end)()
|
end)()
|
||||||
|
|
||||||
if not find_command then
|
if not find_command then
|
||||||
print(
|
utils.notify("builtin.find_files", {
|
||||||
"You need to install either find, fd, or rg. "
|
msg = "You need to install either find, fd, or rg",
|
||||||
.. "You can also submit a PR to add support for another file finder :)"
|
level = "ERROR",
|
||||||
)
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -267,13 +267,19 @@ files.treesitter = function(opts)
|
|||||||
|
|
||||||
local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter")
|
local has_nvim_treesitter, _ = pcall(require, "nvim-treesitter")
|
||||||
if not has_nvim_treesitter then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local parsers = require "nvim-treesitter.parsers"
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
if not parsers.has_parser(parsers.get_buf_lang(opts.bufnr)) then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -397,7 +403,10 @@ end
|
|||||||
files.tags = function(opts)
|
files.tags = function(opts)
|
||||||
local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles()
|
local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles()
|
||||||
if vim.tbl_isempty(tagfiles) then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,21 @@ local git = {}
|
|||||||
|
|
||||||
git.files = function(opts)
|
git.files = function(opts)
|
||||||
if opts.is_bare then
|
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
|
end
|
||||||
|
|
||||||
local show_untracked = utils.get_default(opts.show_untracked, true)
|
local show_untracked = utils.get_default(opts.show_untracked, true)
|
||||||
local recurse_submodules = utils.get_default(opts.recurse_submodules, false)
|
local recurse_submodules = utils.get_default(opts.recurse_submodules, false)
|
||||||
if show_untracked and recurse_submodules then
|
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
|
end
|
||||||
|
|
||||||
-- By creating the entry maker after the cwd options,
|
-- By creating the entry maker after the cwd options,
|
||||||
@@ -300,7 +308,11 @@ end
|
|||||||
|
|
||||||
git.status = function(opts)
|
git.status = function(opts)
|
||||||
if opts.is_bare then
|
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
|
end
|
||||||
|
|
||||||
local gen_new_finder = function()
|
local gen_new_finder = function()
|
||||||
@@ -308,13 +320,17 @@ git.status = function(opts)
|
|||||||
local git_cmd = { "git", "status", "-s", "--", "." }
|
local git_cmd = { "git", "status", "-s", "--", "." }
|
||||||
|
|
||||||
if expand_dir then
|
if expand_dir then
|
||||||
table.insert(git_cmd, table.getn(git_cmd) - 1, "-u")
|
table.insert(git_cmd, #git_cmd - 1, "-u")
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = utils.get_os_command_output(git_cmd, opts.cwd)
|
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"
|
print "No changes found"
|
||||||
|
utils.notify("builtin.git_status", {
|
||||||
|
msg = "No changes found",
|
||||||
|
level = "WARN",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ internal.builtin = function(opts)
|
|||||||
actions.select_default:replace(function(_)
|
actions.select_default:replace(function(_)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if not selection then
|
if not selection then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.builtin"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -113,12 +113,18 @@ internal.resume = function(opts)
|
|||||||
|
|
||||||
local cached_pickers = state.get_global_key "cached_pickers"
|
local cached_pickers = state.get_global_key "cached_pickers"
|
||||||
if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then
|
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
|
return
|
||||||
end
|
end
|
||||||
local picker = cached_pickers[opts.cache_index]
|
local picker = cached_pickers[opts.cache_index]
|
||||||
if picker == nil then
|
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
|
return
|
||||||
end
|
end
|
||||||
-- reset layout strategy and get_window_options if default as only one is valid
|
-- reset layout strategy and get_window_options if default as only one is valid
|
||||||
@@ -144,7 +150,10 @@ end
|
|||||||
internal.pickers = function(opts)
|
internal.pickers = function(opts)
|
||||||
local cached_pickers = state.get_global_key "cached_pickers"
|
local cached_pickers = state.get_global_key "cached_pickers"
|
||||||
if cached_pickers == nil or vim.tbl_isempty(cached_pickers) then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -213,7 +222,7 @@ internal.planets = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.planets"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -243,10 +252,11 @@ internal.symbols = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if #files == 0 then
|
if #files == 0 then
|
||||||
print(
|
utils.notify("builtin.symbols", {
|
||||||
"No sources found! Check out https://github.com/nvim-telescope/telescope-symbols.nvim "
|
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."
|
.. "for some prebuild symbols or how to create you own symbol source.",
|
||||||
)
|
level = "ERROR",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -317,7 +327,7 @@ internal.commands = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.commands"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -505,7 +515,7 @@ internal.vim_options = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.vim_options"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -636,7 +646,7 @@ internal.help_tags = function(opts)
|
|||||||
action_set.select:replace(function(_, cmd)
|
action_set.select:replace(function(_, cmd)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.help_tags"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -674,7 +684,7 @@ internal.man_pages = function(opts)
|
|||||||
action_set.select:replace(function(_, cmd)
|
action_set.select:replace(function(_, cmd)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.man_pages"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -725,13 +735,16 @@ internal.reloader = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.reloader"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
require("plenary.reload").reload_module(selection.value)
|
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)
|
end)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -878,7 +891,7 @@ internal.colorscheme = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.colorscheme"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -995,7 +1008,7 @@ internal.keymaps = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.keymaps"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1046,7 +1059,7 @@ internal.highlights = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.highlights"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1143,7 +1156,7 @@ internal.autocommands = function(opts)
|
|||||||
action_set.select:replace(function(_, type)
|
action_set.select:replace(function(_, type)
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.autocommands"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1170,7 +1183,7 @@ internal.spell_suggest = function(opts)
|
|||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
local selection = action_state.get_selected_entry()
|
local selection = action_state.get_selected_entry()
|
||||||
if selection == nil then
|
if selection == nil then
|
||||||
print "[telescope] Nothing currently selected"
|
utils.__warn_no_selection "builtin.spell_suggest"
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1202,7 +1215,10 @@ internal.tagstack = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(tags) then
|
if vim.tbl_isempty(tags) then
|
||||||
print "No tagstack available"
|
utils.notify("builtin.tagstack", {
|
||||||
|
msg = "No tagstack available",
|
||||||
|
level = "WARN",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -117,7 +117,10 @@ lsp.document_symbols = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not result or vim.tbl_isempty(result) then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -129,7 +132,10 @@ lsp.document_symbols = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(locations) then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -165,12 +171,18 @@ lsp.code_actions = function(opts)
|
|||||||
)
|
)
|
||||||
|
|
||||||
if err then
|
if err then
|
||||||
print("ERROR: " .. err)
|
utils.notify("builin.lsp_code_actions", {
|
||||||
|
msg = err,
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if not results_lsp or vim.tbl_isempty(results_lsp) then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -206,7 +218,10 @@ lsp.code_actions = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if #results == 0 then
|
if #results == 0 then
|
||||||
print "No code actions available"
|
utils.notify("builtin.lsp_document_symbols", {
|
||||||
|
msg = "No code actions available",
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -317,7 +332,10 @@ lsp.code_actions = function(opts)
|
|||||||
then
|
then
|
||||||
client.request("codeAction/resolve", action, function(resolved_err, resolved_action)
|
client.request("codeAction/resolve", action, function(resolved_err, resolved_action)
|
||||||
if resolved_err then
|
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
|
return
|
||||||
end
|
end
|
||||||
if resolved_action then
|
if resolved_action then
|
||||||
@@ -358,10 +376,11 @@ lsp.workspace_symbols = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.tbl_isempty(locations) then
|
if vim.tbl_isempty(locations) then
|
||||||
print(
|
utils.notify("builtin.lsp_workspace_symbols", {
|
||||||
"No results from workspace/symbol. Maybe try a different query: "
|
msg = "No results from workspace/symbol. Maybe try a different query: "
|
||||||
.. "Telescope lsp_workspace_symbols query=example"
|
.. "'Telescope lsp_workspace_symbols query=example'",
|
||||||
)
|
level = "INFO",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -429,9 +448,15 @@ local function check_capabilities(feature, bufnr)
|
|||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
if #clients == 0 then
|
if #clients == 0 then
|
||||||
print "LSP: no client attached"
|
utils.notify("builtin.lsp_*", {
|
||||||
|
msg = "no client attached",
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
else
|
else
|
||||||
print("LSP: server does not support " .. feature)
|
utils.notify("builtin.lsp_*", {
|
||||||
|
msg = "server does not support " .. feature,
|
||||||
|
level = "INFO",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ local themes = require "telescope.themes"
|
|||||||
local builtin = require "telescope.builtin"
|
local builtin = require "telescope.builtin"
|
||||||
local extensions = require("telescope._extensions").manager
|
local extensions = require("telescope._extensions").manager
|
||||||
local config = require "telescope.config"
|
local config = require "telescope.config"
|
||||||
|
local utils = require "telescope.utils"
|
||||||
local command = {}
|
local command = {}
|
||||||
|
|
||||||
local arg_value = {
|
local arg_value = {
|
||||||
@@ -119,7 +120,10 @@ command.convert_user_opts = function(user_opts)
|
|||||||
|
|
||||||
local _switch_metatable = {
|
local _switch_metatable = {
|
||||||
__index = function(_, k)
|
__index = function(_, k)
|
||||||
print(string.format("Type of %s does not match", k))
|
utils.notify("command", {
|
||||||
|
msg = string.format("Type of '%s' does not match", k),
|
||||||
|
level = "WARN",
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +157,10 @@ end
|
|||||||
local function run_command(args)
|
local function run_command(args)
|
||||||
local user_opts = args or {}
|
local user_opts = args or {}
|
||||||
if next(user_opts) == nil and not user_opts.cmd then
|
if next(user_opts) == nil and not user_opts.cmd then
|
||||||
print "[Telescope] your command miss args"
|
utils.notify("command", {
|
||||||
|
msg = "Command missing arguments",
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -186,7 +193,10 @@ local function run_command(args)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
print "[Telescope] unknown command"
|
utils.notify("run_command", {
|
||||||
|
msg = "Unknown command",
|
||||||
|
level = "ERROR",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- @Summary get extensions sub command
|
-- @Summary get extensions sub command
|
||||||
|
|||||||
@@ -95,6 +95,10 @@ local get_default = require("telescope.utils").get_default
|
|||||||
local resolver = {}
|
local resolver = {}
|
||||||
local _resolve_map = {}
|
local _resolve_map = {}
|
||||||
|
|
||||||
|
local throw_invalid_config_option = function(key, value)
|
||||||
|
error(string.format("Invalid configuration option for '%s': '%s'", key, tostring(value)), 2)
|
||||||
|
end
|
||||||
|
|
||||||
-- Booleans
|
-- Booleans
|
||||||
_resolve_map[function(val)
|
_resolve_map[function(val)
|
||||||
return val == false
|
return val == false
|
||||||
@@ -148,8 +152,7 @@ end] = function(selector, val)
|
|||||||
return v(selector, value)
|
return v(selector, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
throw_invalid_config_option("padding", value)
|
||||||
error("invalid configuration option for padding:" .. tostring(value))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(...)
|
return function(...)
|
||||||
@@ -182,8 +185,7 @@ resolver.resolve_height = function(val)
|
|||||||
return v(3, val)
|
return v(3, val)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
throw_invalid_config_option("height", val)
|
||||||
error("invalid configuration option for height:" .. tostring(val))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Converts input to a function that returns the width.
|
--- Converts input to a function that returns the width.
|
||||||
@@ -210,7 +212,7 @@ resolver.resolve_width = function(val)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
error("invalid configuration option for width:" .. tostring(val))
|
throw_invalid_config_option("width", val)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Calculates the adjustment required to move the picker from the middle of the screen to
|
--- Calculates the adjustment required to move the picker from the middle of the screen to
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ function from_entry.path(entry, validate, escape)
|
|||||||
path = entry.value
|
path = entry.value
|
||||||
end
|
end
|
||||||
if path == nil then
|
if path == nil then
|
||||||
print("Invalid entry", vim.inspect(entry))
|
require("telescope.log").error(string.format("Invalid Entry: '%s'", vim.inspect(entry)))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ entry_display.create = function(configuration)
|
|||||||
return function(self, picker)
|
return function(self, picker)
|
||||||
local results = {}
|
local results = {}
|
||||||
local highlights = {}
|
local highlights = {}
|
||||||
for i = 1, table.getn(generator) do
|
for i = 1, #generator do
|
||||||
if self[i] ~= nil then
|
if self[i] ~= nil then
|
||||||
local str, hl = generator[i](self[i], picker)
|
local str, hl = generator[i](self[i], picker)
|
||||||
if hl then
|
if hl then
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ layout_strategies._format = function(name)
|
|||||||
table.insert(results, string.format(" - %s", line))
|
table.insert(results, string.format(" - %s", line))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error("Unknown type:" .. type(val))
|
error(string.format("expected string or table but found '%s'", type(val)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -902,7 +902,7 @@ layout_strategies.bottom_pane = make_documented_layout(
|
|||||||
results.border = { 1, 1, 0, 1 }
|
results.border = { 1, 1, 0, 1 }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error("Unknown prompt_position: " .. tostring(self.window.prompt_position) .. "\n" .. vim.inspect(layout_config))
|
error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Col
|
-- Col
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ function p_window.get_window_options(picker, max_columns, max_lines)
|
|||||||
local getter = require("telescope.pickers.layout_strategies")[layout_strategy]
|
local getter = require("telescope.pickers.layout_strategies")[layout_strategy]
|
||||||
|
|
||||||
if not getter then
|
if not getter then
|
||||||
error("Not a valid layout strategy: " .. layout_strategy)
|
error(string.format("'%s' is not a valid layout strategy", layout_strategy))
|
||||||
end
|
end
|
||||||
|
|
||||||
return getter(picker, max_columns, max_lines)
|
return getter(picker, max_columns, max_lines)
|
||||||
|
|||||||
@@ -948,7 +948,7 @@ previewers.highlights = defaulter(function(_)
|
|||||||
if v ~= "" then
|
if v ~= "" then
|
||||||
if v:sub(1, 1) == " " then
|
if v:sub(1, 1) == " " then
|
||||||
local part_of_old = v:match "%s+(.*)"
|
local part_of_old = v:match "%s+(.*)"
|
||||||
hl_groups[table.getn(hl_groups)] = hl_groups[table.getn(hl_groups)] .. part_of_old
|
hl_groups[#hl_groups] = hl_groups[#hl_groups] .. part_of_old
|
||||||
else
|
else
|
||||||
table.insert(hl_groups, v)
|
table.insert(hl_groups, v)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -50,7 +50,10 @@ utils.filter_symbols = function(results, opts)
|
|||||||
local filtered_symbols
|
local filtered_symbols
|
||||||
|
|
||||||
if has_symbols and has_ignore then
|
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
|
return
|
||||||
elseif not (has_ignore or has_symbols) then
|
elseif not (has_ignore or has_symbols) then
|
||||||
return results
|
return results
|
||||||
@@ -59,7 +62,10 @@ utils.filter_symbols = function(results, opts)
|
|||||||
opts.ignore_symbols = { opts.ignore_symbols }
|
opts.ignore_symbols = { opts.ignore_symbols }
|
||||||
end
|
end
|
||||||
if type(opts.ignore_symbols) ~= "table" then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -72,7 +78,10 @@ utils.filter_symbols = function(results, opts)
|
|||||||
opts.symbols = { opts.symbols }
|
opts.symbols = { opts.symbols }
|
||||||
end
|
end
|
||||||
if type(opts.symbols) ~= "table" then
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -113,10 +122,16 @@ utils.filter_symbols = function(results, opts)
|
|||||||
-- print message that filtered_symbols is now empty
|
-- print message that filtered_symbols is now empty
|
||||||
if has_symbols then
|
if has_symbols then
|
||||||
local symbols = table.concat(opts.symbols, ", ")
|
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
|
elseif has_ignore then
|
||||||
local symbols = table.concat(opts.ignore_symbols, ", ")
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -370,7 +385,10 @@ end
|
|||||||
|
|
||||||
function utils.get_os_command_output(cmd, cwd)
|
function utils.get_os_command_output(cmd, cwd)
|
||||||
if type(cmd) ~= "table" then
|
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 {}
|
return {}
|
||||||
end
|
end
|
||||||
local command = table.remove(cmd, 1)
|
local command = table.remove(cmd, 1)
|
||||||
@@ -457,4 +475,25 @@ utils.get_devicons = load_once(function()
|
|||||||
end
|
end
|
||||||
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
|
return utils
|
||||||
|
|||||||
Reference in New Issue
Block a user