refactor: Better messages

This commit is contained in:
hedy
2023-11-16 14:28:29 +08:00
parent 9f4cfa9417
commit 4d871ec64b
3 changed files with 23 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
local vim = vim local utils = require('outline.utils')
local M = {} local M = {}
@@ -198,7 +198,7 @@ end
---Check for inconsistent or mutually exclusive opts. Does not alter the opts ---Check for inconsistent or mutually exclusive opts. Does not alter the opts
function M.check_config() function M.check_config()
if M.o.outline_window.hide_cursor and not M.o.outline_window.show_cursorline then if M.o.outline_window.hide_cursor and not M.o.outline_window.show_cursorline then
vim.notify("[outline.config]: hide_cursor enabled WITHOUT cursorline enabled!", vim.log.levels.ERROR) utils.echo("config", "hide_cursor enabled without cursorline enabled!")
end end
end end

View File

@@ -497,9 +497,8 @@ end
function M._map_follow_cursor() function M._map_follow_cursor()
if not M.follow_cursor({ focus_outline = true }) then if not M.follow_cursor({ focus_outline = true }) then
vim.notify( utils.echo(
"Code window no longer active. Try closing and reopening the outline.", "Code window no longer active. Try closing and reopening the outline."
vim.log.levels.ERROR
) )
end end
end end
@@ -554,7 +553,7 @@ function M.open_outline(opts)
if not M.view:is_open() then if not M.view:is_open() then
local found = providers.request_symbols(handler, opts) local found = providers.request_symbols(handler, opts)
if not found then if not found then
vim.notify("[outline]: No providers found for current buffer", vim.log.levels.WARN) utils.echo("No providers found for current buffer")
end end
end end
end end

View File

@@ -55,7 +55,7 @@ end
---@param old_node table Old node ---@param old_node table Old node
---@param index? number Index of old_item in parent ---@param index? number Index of old_item in parent
---@param parent? table Parent of old_item ---@param parent? table Parent of old_item
M.merge_items_rec = function(new_node, old_node, index, parent) function M.merge_items_rec(new_node, old_node, index, parent)
local failed = false local failed = false
if not new_node or not old_node then if not new_node or not old_node then
@@ -110,7 +110,7 @@ M.merge_items_rec = function(new_node, old_node, index, parent)
end end
end end
M.flash_highlight = function(winnr, lnum, durationMs, hl_group) function M.flash_highlight(winnr, lnum, durationMs, hl_group)
hl_group = hl_group or "Visual" hl_group = hl_group or "Visual"
if durationMs == true or durationMs == 1 then if durationMs == true or durationMs == 1 then
durationMs = 300 durationMs = 300
@@ -123,4 +123,20 @@ M.flash_highlight = function(winnr, lnum, durationMs, hl_group)
vim.defer_fn(remove_highlight, durationMs) vim.defer_fn(remove_highlight, durationMs)
end end
---@param module string Used as message if second param omitted
---@param message string?
function M.echo(module, message)
if not message then
message = module
module = ""
end
local prefix = "outline"
if module ~= "" then
prefix = prefix.."."..module
end
local prefix_chunk = { '('..prefix..') ', "WarningMsg" }
-- For now we don't echo much, so add all to history
vim.api.nvim_echo({ prefix_chunk, { message } }, true, {})
end
return M return M