Skip to content

feat: use virtual title in notifications if title is not supported #2439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions lua/nvim-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
19 changes: 19 additions & 0 deletions lua/nvim-tree/notify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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
Expand Down