feat: display ignore status in AerialInfo

This commit is contained in:
Steven Arcangeli 2023-01-06 09:52:14 -08:00
parent 7acdd616ee
commit a562b9d99f
3 changed files with 32 additions and 14 deletions

View file

@ -96,6 +96,14 @@ M.info = function(params)
print("Aerial Info")
print("-----------")
print(string.format("Filetype: %s", data.filetype))
if data.ignore.ignored then
print(
string.format(
"Aerial ignores this window: %s. See the 'ignore' config in :help aerial-options",
data.ignore.message
)
)
end
print("Configured backends:")
for _, status in ipairs(data.backends) do
local line = " " .. status.name

View file

@ -552,7 +552,7 @@ M.tree_close = lazy("tree", "close")
M.tree_toggle = lazy("tree", "toggle")
---Sync code folding with the current tree state.
---@param bufnr integer
---@param bufnr nil|integer
---@note
--- Ignores the 'link_tree_to_folds' config option.
M.sync_folds = function(bufnr)
@ -585,7 +585,12 @@ M.info = function()
local util = require("aerial.util")
local bufnr = util.get_buffers(0)
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
local ignored, message = util.is_ignored_win()
return {
ignore = {
ignored = ignored,
message = message,
},
filetype = filetype,
filter_kind_map = require("aerial.config").get_filter_kind_map(),
backends = require("aerial.backends").get_status(bufnr),

View file

@ -223,39 +223,42 @@ end
---@param bufnr nil|integer
---@return boolean
---@return nil|string
M.is_ignored_buf = function(bufnr)
bufnr = bufnr or 0
if not vim.api.nvim_buf_is_valid(bufnr) then
return true
return true, "Buffer is not valid"
end
local filetype = vim.api.nvim_buf_get_option(bufnr, "filetype")
local filetypes = M.get_filetypes(bufnr)
-- Never ignore aerial buffers
if filetype == "aerial" then
if vim.tbl_contains(filetypes, "aerial") then
return false
end
local ignore = config.ignore
if ignore.unlisted_buffers and not vim.api.nvim_buf_get_option(bufnr, "buflisted") then
return true
return true, "Buffer is not listed"
end
if ignore.buftypes then
local buftype = vim.api.nvim_buf_get_option(bufnr, "buftype")
if ignore.buftypes == "special" then
if buftype ~= "" and buftype ~= "help" then
return true
return true, string.format("Buftype '%s' is \"special\"", buftype)
end
elseif type(ignore.buftypes) == "table" then
if vim.tbl_contains(ignore.buftypes, buftype) then
return true
return true, string.format("Buftype '%s' is ignored", buftype)
end
elseif type(ignore.buftypes) == "function" then
if ignore.buftypes(bufnr, buftype) then
return true
return true, string.format("Buftype '%s' is ignored", buftype)
end
end
end
if ignore.filetypes then
if M.is_ignored_filetype(filetype) then
return true
for _, filetype in ipairs(filetypes) do
if M.is_ignored_filetype(filetype) then
return true, string.format("Filetype '%s' is ignored", filetype)
end
end
end
return false
@ -263,20 +266,22 @@ end
---@param winid nil|integer
---@return boolean
---@return nil|string
M.is_ignored_win = function(winid)
winid = winid or 0
local bufnr = vim.api.nvim_win_get_buf(winid)
if M.is_ignored_buf(bufnr) then
return true
local ignore_buf, message = M.is_ignored_buf(bufnr)
if ignore_buf then
return ignore_buf, message
end
local ignore = config.ignore
if ignore.wintypes then
local wintype = vim.fn.win_gettype(winid)
if ignore.wintypes == "special" and wintype ~= "" then
return true
return true, string.format("Wintype '%s' is \"special\"", wintype)
elseif type(ignore.wintypes) == "table" then
if vim.tbl_contains(ignore.wintypes, wintype) then
return true
return true, string.format("Wintype '%s' is ignored", wintype)
end
end
end