feat: use virtual title in notifications if title is not supported (#2439)
* feat: use virtual title in notifications if title is not supported * Fix boolean expressions * Replace `pcall` with `package.loaded` * Detect title support before sending notification * Prevent `title_support` from being nil after evaluation * temporary stylua suppression --------- Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
d8e495b235
commit
85abe29396
@ -15,12 +15,7 @@ local modified = require "nvim-tree.modified"
|
||||
local find_file = require "nvim-tree.actions.tree.find-file"
|
||||
local open = require "nvim-tree.actions.tree.open"
|
||||
local events = require "nvim-tree.events"
|
||||
|
||||
local function notify_once(msg, level)
|
||||
vim.schedule(function()
|
||||
vim.notify_once(msg, level or vim.log.levels.WARN, { title = "NvimTree" })
|
||||
end)
|
||||
end
|
||||
local notify = require "nvim-tree.notify"
|
||||
|
||||
local _config = {}
|
||||
|
||||
@ -730,7 +725,7 @@ local function validate_options(conf)
|
||||
if msg then
|
||||
msg = string.format("%s\n%s", msg, invalid)
|
||||
else
|
||||
msg = string.format("[NvimTree]\n%s", invalid)
|
||||
msg = invalid
|
||||
end
|
||||
user[k] = nil
|
||||
else
|
||||
@ -743,7 +738,7 @@ local function validate_options(conf)
|
||||
validate(conf, DEFAULT_OPTS, ACCEPTED_STRINGS, ACCEPTED_TYPES, "")
|
||||
|
||||
if msg then
|
||||
notify_once(msg .. "\n\nsee :help nvim-tree-opts for available configuration options")
|
||||
notify.warn(msg .. "\n\nsee :help nvim-tree-opts for available configuration options")
|
||||
end
|
||||
end
|
||||
|
||||
@ -766,7 +761,7 @@ end
|
||||
|
||||
function M.setup(conf)
|
||||
if vim.fn.has "nvim-0.8" == 0 then
|
||||
notify_once "nvim-tree.lua requires Neovim 0.8 or higher"
|
||||
notify.warn "nvim-tree.lua requires Neovim 0.8 or higher"
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@ -5,6 +5,21 @@ local config = {
|
||||
absolute_path = true,
|
||||
}
|
||||
|
||||
local title_support
|
||||
function M.supports_title()
|
||||
-- TODO increase stylua column_width
|
||||
-- stylua: ignore start
|
||||
if title_support == nil then
|
||||
title_support = (package.loaded.notify and (vim.notify == require "notify" or vim.notify == require("notify").notify))
|
||||
or (package.loaded.noice and (vim.notify == require("noice").notify or vim.notify == require("noice.source.notify").notify))
|
||||
or (package.loaded.notifier and require("notifier.config").has_component "nvim")
|
||||
or false
|
||||
end
|
||||
-- stylua: ignore end
|
||||
|
||||
return title_support
|
||||
end
|
||||
|
||||
local modes = {
|
||||
{ name = "trace", level = vim.log.levels.TRACE },
|
||||
{ name = "debug", level = vim.log.levels.DEBUG },
|
||||
@ -20,6 +35,10 @@ do
|
||||
end
|
||||
|
||||
vim.schedule(function()
|
||||
if not M.supports_title() then
|
||||
msg = "[NvimTree]\n" .. msg
|
||||
end
|
||||
|
||||
vim.notify(msg, level, { title = "NvimTree" })
|
||||
end)
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user