Skip to content

Commit 85abe29

Browse files
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>
1 parent d8e495b commit 85abe29

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lua/nvim-tree.lua

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ local modified = require "nvim-tree.modified"
1515
local find_file = require "nvim-tree.actions.tree.find-file"
1616
local open = require "nvim-tree.actions.tree.open"
1717
local events = require "nvim-tree.events"
18-
19-
local function notify_once(msg, level)
20-
vim.schedule(function()
21-
vim.notify_once(msg, level or vim.log.levels.WARN, { title = "NvimTree" })
22-
end)
23-
end
18+
local notify = require "nvim-tree.notify"
2419

2520
local _config = {}
2621

@@ -730,7 +725,7 @@ local function validate_options(conf)
730725
if msg then
731726
msg = string.format("%s\n%s", msg, invalid)
732727
else
733-
msg = string.format("[NvimTree]\n%s", invalid)
728+
msg = invalid
734729
end
735730
user[k] = nil
736731
else
@@ -743,7 +738,7 @@ local function validate_options(conf)
743738
validate(conf, DEFAULT_OPTS, ACCEPTED_STRINGS, ACCEPTED_TYPES, "")
744739

745740
if msg then
746-
notify_once(msg .. "\n\nsee :help nvim-tree-opts for available configuration options")
741+
notify.warn(msg .. "\n\nsee :help nvim-tree-opts for available configuration options")
747742
end
748743
end
749744

@@ -766,7 +761,7 @@ end
766761

767762
function M.setup(conf)
768763
if vim.fn.has "nvim-0.8" == 0 then
769-
notify_once "nvim-tree.lua requires Neovim 0.8 or higher"
764+
notify.warn "nvim-tree.lua requires Neovim 0.8 or higher"
770765
return
771766
end
772767

lua/nvim-tree/notify.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ local config = {
55
absolute_path = true,
66
}
77

8+
local title_support
9+
function M.supports_title()
10+
-- TODO increase stylua column_width
11+
-- stylua: ignore start
12+
if title_support == nil then
13+
title_support = (package.loaded.notify and (vim.notify == require "notify" or vim.notify == require("notify").notify))
14+
or (package.loaded.noice and (vim.notify == require("noice").notify or vim.notify == require("noice.source.notify").notify))
15+
or (package.loaded.notifier and require("notifier.config").has_component "nvim")
16+
or false
17+
end
18+
-- stylua: ignore end
19+
20+
return title_support
21+
end
22+
823
local modes = {
924
{ name = "trace", level = vim.log.levels.TRACE },
1025
{ name = "debug", level = vim.log.levels.DEBUG },
@@ -20,6 +35,10 @@ do
2035
end
2136

2237
vim.schedule(function()
38+
if not M.supports_title() then
39+
msg = "[NvimTree]\n" .. msg
40+
end
41+
2342
vim.notify(msg, level, { title = "NvimTree" })
2443
end)
2544
end

0 commit comments

Comments
 (0)