feat(Status): Better provider info and show filter info

This commit is contained in:
hedy
2023-11-19 16:59:49 +08:00
parent 4834db0802
commit 3b27272319
5 changed files with 48 additions and 11 deletions

View File

@@ -363,6 +363,8 @@ function M.resolve_filter_config()
end
end
M.o.symbols.user_config_filter = vim.deepcopy(tmp)
---@type outline.FilterFtList
local filter = tmp
---@type outline.FilterFtTable

View File

@@ -66,6 +66,15 @@ function M.show_help()
end)
end
local function get_filter_list_lines(f)
if f == nil then
return { '(not configured)' }
elseif f == false or (f and #f == 0 and f.exclude) then
return { '(all symbols included)' }
end
return vim.split(vim.inspect(f), '\n', { plain = true })
end
---Display outline window status in a floating window
---@param ctx outline.StatusContext
function M.show_status(ctx)
@@ -74,8 +83,28 @@ function M.show_status(ctx)
---@type outline.HL[]
local hl = { { line = 0, from = 0, to = #keyhint, name = 'Comment' } }
local p = ctx.provider
local priority = cfg.o.providers.priority
---@type string[]
local priority = ctx.priority
local pref
local indent = ' '
if ctx.ft then
table.insert(lines, 'Filetype of current or attached buffer: ' .. ctx.ft)
table.insert(lines, 'Symbols filter:')
table.insert(lines, '')
for _, line in ipairs(get_filter_list_lines(ctx.filter)) do
table.insert(lines, indent .. line)
end
table.insert(lines, '')
table.insert(lines, 'Default symbols filter:')
table.insert(lines, '')
for _, line in ipairs(get_filter_list_lines(ctx.default_filter)) do
table.insert(lines, indent .. line)
end
table.insert(lines, '')
else
table.insert(lines, 'Buffer number of code was invalid, could not get filetype.')
end
if utils.table_has_content(priority) then
pref = 'Configured providers are: '
@@ -92,8 +121,6 @@ function M.show_status(ctx)
table.insert(hl, { line = #lines - 1, from = #pref, to = #pref + #content, name = 'ErrorMsg' })
end
table.insert(lines, '')
if p ~= nil then
pref = 'Current provider: '
table.insert(lines, pref .. p.name)
@@ -102,7 +129,6 @@ function M.show_status(ctx)
table.insert(lines, 'Provider info:')
table.insert(lines, '')
local l = p.get_status()
local indent = ' '
for _, line in ipairs(vim.split(l, '\n', { plain = true, trimempty = false })) do
table.insert(lines, indent .. line)
end
@@ -115,8 +141,6 @@ function M.show_status(ctx)
('Outline window is %s.'):format((ctx.outline_open and 'open') or 'not open')
)
table.insert(lines, '')
if ctx.code_win_active then
table.insert(lines, 'Code window is active.')
else
@@ -124,7 +148,7 @@ function M.show_status(ctx)
table.insert(lines, 'Try closing and reopening the outline.')
end
else
table.insert(lines, 'No providers.')
table.insert(lines, 'No supported providers for current buffer.')
end
local f = Float:new()

View File

@@ -629,9 +629,16 @@ end
function M.show_status()
---@type outline.StatusContext
local ctx = {}
local ctx = { priority = cfg.o.providers.priority }
if vim.api.nvim_buf_is_valid(M.state.code_buf) then
ctx.ft = vim.api.nvim_buf_get_option(M.state.code_buf, 'ft')
end
ctx.filter = cfg.o.symbols.user_config_filter[ctx.ft]
ctx.default_filter = cfg.o.symbols.user_config_filter.default
local p = _G._outline_current_provider
if not M.is_focus_in_outline() then
if not M.view or not M.view:is_open() then
p = providers.find_provider()
end

View File

@@ -81,6 +81,10 @@
---@field provider outline.Provider?
---@field outline_open boolean?
---@field code_win_active boolean?
---@field ft string?
---@field filter outline.FilterList?
---@field default_filter outline.FilterList?
---@field priority string[]?
-- API

View File

@@ -137,12 +137,12 @@ function M.echo(module, message)
vim.api.nvim_echo({ prefix_chunk, { message } }, true, {})
end
---@param t table
---@param t table?
function M.table_has_content(t)
return t and next(t) ~= nil
end
---@param t table|string
---@param t table|string?
function M.str_or_nonempty_table(t)
return type(t) == 'string' or M.table_has_content(t)
end