feat(status): Use custom highlight with default links

This commit is contained in:
hedy
2023-11-24 16:47:36 +08:00
parent 896fd2ae63
commit fab3e8ce7c
4 changed files with 35 additions and 11 deletions

View File

@@ -659,6 +659,22 @@ preview_window = {
}, },
``` ```
### Help windows
| Highlight | Link |
| ------------------------- | -------- |
| OutlineHelpTip | Comment |
| OutlineStatusFt | Type |
| OutlineStatusError | ErrorMsg |
| OutlineStatusProvider | Special |
| OutlineKeymapHelpKey | Special |
| OutlineKeymapHelpDisabled | Comment |
Help windows include:
1. the keymap help from pressing `?` in the outline window
1. `:OutlineStatus`
### Other highlight groups ### Other highlight groups
| Highlight | Description | | Highlight | Description |

View File

@@ -9,12 +9,12 @@ function M.show_help()
local title = 'Current keymaps:' local title = 'Current keymaps:'
local lines = { keyhint, '', title, '' } local lines = { keyhint, '', title, '' }
---@type outline.HL[] ---@type outline.HL[]
local hl = { { line = 0, from = 0, to = #keyhint, name = 'Comment' } } local hl = { { line = 0, from = 0, to = #keyhint, name = 'OutlineHelpTip' } }
local left = {} local left = {}
local right = {} local right = {}
local max_left_width = 0 local max_left_width = 0
local indent = ' ' local indent = ' '
local key_hl = 'Special' local key_hl = 'OutlineKeymapHelpKey'
for action, keys in pairs(cfg.o.keymaps) do for action, keys in pairs(cfg.o.keymaps) do
if type(keys) == 'string' then if type(keys) == 'string' then
@@ -30,8 +30,8 @@ function M.show_help()
table.insert(hl, { table.insert(hl, {
line = #left + 3, line = #left + 3,
from = #indent, from = #indent,
name = 'OutlineKeymapHelpDisabled',
to = #indent + 6, to = #indent + 6,
name = 'Comment',
}) })
else else
local i = #indent local i = #indent
@@ -80,7 +80,7 @@ function M.show_status(ctx)
local keyhint = 'Press q or <Esc> to close this window.' local keyhint = 'Press q or <Esc> to close this window.'
local lines = { keyhint, '' } local lines = { keyhint, '' }
---@type outline.HL[] ---@type outline.HL[]
local hl = { { line = 0, from = 0, to = #keyhint, name = 'Comment' } } local hl = { { line = 0, from = 0, to = #keyhint, name = 'OutlineHelpTip' } }
local p = ctx.provider local p = ctx.provider
---@type string[] ---@type string[]
local priority = ctx.priority local priority = ctx.priority
@@ -90,7 +90,7 @@ function M.show_status(ctx)
if ctx.ft then if ctx.ft then
pref = 'Filetype of current or attached buffer: ' pref = 'Filetype of current or attached buffer: '
table.insert(lines, pref .. ctx.ft) table.insert(lines, pref .. ctx.ft)
table.insert(hl, { line = #lines - 1, from = #pref, to = -1, name = 'Type' }) table.insert(hl, { line = #lines - 1, from = #pref, to = -1, name = 'OutlineStatusFt'})
table.insert(lines, 'Symbols filter:') table.insert(lines, 'Symbols filter:')
table.insert(lines, '') table.insert(lines, '')
for _, line in ipairs(get_filter_list_lines(ctx.filter)) do for _, line in ipairs(get_filter_list_lines(ctx.filter)) do
@@ -101,7 +101,7 @@ function M.show_status(ctx)
table.insert(lines, 'Filetype of current or attached buffer: N/A') table.insert(lines, 'Filetype of current or attached buffer: N/A')
table.insert(lines, 'Symbols filter: N/A') table.insert(lines, 'Symbols filter: N/A')
table.insert(lines, 'Buffer number of code was invalid, could not get filetype!') table.insert(lines, 'Buffer number of code was invalid, could not get filetype!')
table.insert(hl, { line = #lines - 1, from = 0, to = -1, name = 'ErrorMsg' }) table.insert(hl, { line = #lines - 1, from = 0, to = -1, name = 'OutlineStatusError' })
table.insert(lines, '') table.insert(lines, '')
end end
@@ -117,20 +117,20 @@ function M.show_status(ctx)
table.insert(lines, pref .. table.concat(priority, ', ') .. '.') table.insert(lines, pref .. table.concat(priority, ', ') .. '.')
local i = #pref local i = #pref
for _, name in ipairs(priority) do for _, name in ipairs(priority) do
table.insert(hl, { line = #lines - 1, from = i, to = i + #name, name = 'Special' }) table.insert(hl, { line = #lines - 1, from = i, to = i + #name, name = 'OutlineStatusProvider' })
i = i + #name + 2 i = i + #name + 2
end end
else else
pref = 'config ' pref = 'config '
local content = 'providers.priority' local content = 'providers.priority'
table.insert(lines, pref .. content .. ' is an empty list!') table.insert(lines, pref .. content .. ' is an empty list!')
table.insert(hl, { line = #lines - 1, from = #pref, to = #pref + #content, name = 'ErrorMsg' }) table.insert(hl, { line = #lines - 1, from = #pref, to = #pref + #content, name = 'OutlineStatusError' })
end end
if p ~= nil then if p ~= nil then
pref = 'Current provider: ' pref = 'Current provider: '
table.insert(lines, pref .. p.name) table.insert(lines, pref .. p.name)
table.insert(hl, { line = #lines - 1, from = #pref, to = -1, name = 'Special' }) table.insert(hl, { line = #lines - 1, from = #pref, to = -1, name = 'OutlineStatusProvider' })
if p.get_status then if p.get_status then
table.insert(lines, 'Provider info:') table.insert(lines, 'Provider info:')
table.insert(lines, '') table.insert(lines, '')
@@ -151,8 +151,8 @@ function M.show_status(ctx)
else else
table.insert(lines, 'Code window is not active!') table.insert(lines, 'Code window is not active!')
table.insert(lines, 'Try closing and reopening the outline.') table.insert(lines, 'Try closing and reopening the outline.')
table.insert(hl, { line = #lines - 2, from = 0, to = -1, name = 'ErrorMsg' }) table.insert(hl, { line = #lines - 2, from = 0, to = -1, name = 'OutlineStatusError' })
table.insert(hl, { line = #lines - 1, from = 0, to = -1, name = 'ErrorMsg' }) table.insert(hl, { line = #lines - 1, from = 0, to = -1, name = 'OutlineStatusError' })
end end
else else
table.insert(lines, 'No supported providers for current buffer.') table.insert(lines, 'No supported providers for current buffer.')

View File

@@ -1,3 +1,4 @@
---@class outline.Float
local Float = {} local Float = {}
---@class outline.Float ---@class outline.Float
@@ -9,6 +10,7 @@ function Float:new()
return setmetatable({ bufnr = nil, winnr = nil, ns = nil }, { __index = Float }) return setmetatable({ bufnr = nil, winnr = nil, ns = nil }, { __index = Float })
end end
---Set up a floating window with OutlineHelp ft
---@param lines string[] ---@param lines string[]
---@param hl outline.HL[] ---@param hl outline.HL[]
---@param title string ---@param title string

View File

@@ -62,6 +62,12 @@ function M.setup_highlights()
Details = 'Comment', Details = 'Comment',
Lineno = 'LineNr', Lineno = 'LineNr',
JumpHighlight = 'Visual', JumpHighlight = 'Visual',
HelpTip = 'Comment',
StatusFt = 'Type',
StatusProvider = 'Special',
StatusError = 'ErrorMsg',
KeymapHelpKey = 'Special',
KeymapHelpDisabled = 'Comment',
}) do }) do
if vim.fn.hlexists('Outline' .. name) == 0 then if vim.fn.hlexists('Outline' .. name) == 0 then
vim.api.nvim_set_hl(0, 'Outline' .. name, { link = link }) vim.api.nvim_set_hl(0, 'Outline' .. name, { link = link })