Skip to content

Commit

Permalink
Add a 'variant' field to sign specifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dstein64 committed Jun 24, 2024
1 parent 9443fb3 commit 33df628
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 5 deletions.
2 changes: 2 additions & 0 deletions doc/scrollview.txt
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,8 @@ register_sign_spec({spec}) *scrollview.register_sign_spec()*
- symbol (string): Defaults to `''`.
- type (string): `'b'` for buffer-local signs, `'w'` for
window-local signs. Defaults to `'b'`.
- variant (string|nil): Used for groups that include multiple
variants. Defaults to `nil`.

Return: ~
(table) a table with the following key-value pairs.
Expand Down
15 changes: 14 additions & 1 deletion lua/scrollview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2714,6 +2714,12 @@ local handle_mouse = function(button, primary)
lhs = menu_name .. '.' .. group
rhs = '<nop>'
vim.cmd(menu_mode .. 'noremenu ' .. lhs .. ' ' .. rhs)
local variant = sign_specs[sign_props.sign_spec_id].variant
if variant ~= nil then
lhs = menu_name .. '.' .. variant
rhs = '<nop>'
vim.cmd(menu_mode .. 'noremenu ' .. lhs .. ' ' .. rhs)
end
-- We limit the number of items on the popup menu to prevent a
-- scenario where the menu pops up and then disappears unless
-- the mouse button is held.
Expand Down Expand Up @@ -2910,6 +2916,7 @@ local register_sign_spec = function(specification)
show_in_folds = nil, -- when set, overrides 'scrollview_signs_show_in_folds'
symbol = '', -- effectively ' '
type = 'b',
variant = nil,
}
for key, val in pairs(defaults) do
if specification[key] == nil then
Expand All @@ -2925,9 +2932,15 @@ local register_sign_spec = function(specification)
-- start with a digit. This matches the rules for internal variables (:help
-- internal-variables), but is more restrictive than what is possible with
-- e.g., nvim_buf_set_var.
if string.match(specification.group, '^[a-zA-Z_][a-zA-Z0-9_]*$') == nil then
local valid_pattern = '^[a-zA-Z_][a-zA-Z0-9_]*$'
if string.match(specification.group, valid_pattern) == nil then
error('Invalid group: ' .. specification.group)
end
-- Apply the same restrictions to variants.
if specification.variant ~= nil
and string.match(specification.variant, valid_pattern) == nil then
error('Invalid variant: ' .. specification.variant)
end
local name = 'scrollview_signs_' .. id .. '_' .. specification.group
specification.name = name
-- priority, symbol, and highlight can be arrays
Expand Down
7 changes: 6 additions & 1 deletion lua/scrollview/contrib/coc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,28 @@ function M.setup(config)
local value
if severity == 'error' then
value = {
'error',
config.error_priority,
config.error_symbol,
config.error_highlight
}
elseif severity == 'hint' then
value = {
'hint',
config.hint_priority,
config.hint_symbol,
config.hint_highlight
}
elseif severity == 'info' then
value = {
'info',
config.info_priority,
config.info_symbol,
config.info_highlight
}
elseif severity == 'warn' then
value = {
'warn',
config.warn_priority,
config.warn_symbol,
config.warn_highlight
Expand All @@ -98,12 +102,13 @@ function M.setup(config)
if vim.tbl_isempty(spec_data) then return end
local names = {} -- maps severity to registration name
for severity, item in pairs(spec_data) do
local priority, symbol, highlight = unpack(item)
local variant, priority, symbol, highlight = unpack(item)
local registration = scrollview.register_sign_spec({
group = group,
highlight = highlight,
priority = priority,
symbol = symbol,
variant = variant,
})
names[severity] = registration.name
end
Expand Down
3 changes: 3 additions & 0 deletions lua/scrollview/contrib/gitsigns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function M.setup(config)
highlight = config.add_highlight,
priority = config.add_priority,
symbol = config.add_symbol,
variant = 'add',
}).name

local change = scrollview.register_sign_spec({
Expand All @@ -101,6 +102,7 @@ function M.setup(config)
highlight = config.change_highlight,
priority = config.change_priority,
symbol = config.change_symbol,
variant = 'change',
}).name

local delete = scrollview.register_sign_spec({
Expand All @@ -109,6 +111,7 @@ function M.setup(config)
highlight = config.delete_highlight,
priority = config.delete_priority,
symbol = config.delete_symbol,
variant = 'delete',
}).name

scrollview.set_sign_group_state(group, config.enabled)
Expand Down
6 changes: 5 additions & 1 deletion lua/scrollview/signs/changelist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,33 @@ function M.init(enable)

local spec_data = {
[PREVIOUS] = {
'previous',
vim.g.scrollview_changelist_previous_priority,
vim.g.scrollview_changelist_previous_symbol,
'ScrollViewChangeListPrevious'
},
[CURRENT] = {
'current',
vim.g.scrollview_changelist_current_priority,
vim.g.scrollview_changelist_current_symbol,
'ScrollViewChangeListCurrent'
},
[NEXT] = {
'next',
vim.g.scrollview_changelist_next_priority,
vim.g.scrollview_changelist_next_symbol,
'ScrollViewChangeListNext'
},
}
local names = {} -- maps direction to registration name
for direction, item in pairs(spec_data) do
local priority, symbol, highlight = unpack(item)
local variant, priority, symbol, highlight = unpack(item)
local registration = scrollview.register_sign_spec({
group = group,
highlight = highlight,
priority = priority,
symbol = symbol,
variant = variant,
})
names[direction] = registration.name
end
Expand Down
6 changes: 5 additions & 1 deletion lua/scrollview/signs/conflicts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,33 @@ function M.init(enable)
local group = 'conflicts'
local spec_data = {
[TOP] = {
'top',
vim.g.scrollview_conflicts_top_priority,
vim.g.scrollview_conflicts_top_symbol,
'ScrollViewConflictsTop'
},
[MIDDLE] = {
'middle',
vim.g.scrollview_conflicts_middle_priority,
vim.g.scrollview_conflicts_middle_symbol,
'ScrollViewConflictsMiddle'
},
[BOTTOM] = {
'bottom',
vim.g.scrollview_conflicts_bottom_priority,
vim.g.scrollview_conflicts_bottom_symbol,
'ScrollViewConflictsBottom'
},
}
local names = {} -- maps position to registration name
for position, item in pairs(spec_data) do
local priority, symbol, highlight = unpack(item)
local variant, priority, symbol, highlight = unpack(item)
local registration = scrollview.register_sign_spec({
group = group,
highlight = highlight,
priority = priority,
symbol = symbol,
variant = variant,
})
names[position] = registration.name
end
Expand Down
7 changes: 6 additions & 1 deletion lua/scrollview/signs/diagnostics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@ function M.init(enable)
local value
if severity == vim.diagnostic.severity.ERROR then
value = {
'error',
vim.g.scrollview_diagnostics_error_priority,
vim.g.scrollview_diagnostics_error_symbol,
'ScrollViewDiagnosticsError'
}
elseif severity == vim.diagnostic.severity.HINT then
value = {
'hint',
vim.g.scrollview_diagnostics_hint_priority,
vim.g.scrollview_diagnostics_hint_symbol,
'ScrollViewDiagnosticsHint'
}
elseif severity == vim.diagnostic.severity.INFO then
value = {
'info',
vim.g.scrollview_diagnostics_info_priority,
vim.g.scrollview_diagnostics_info_symbol,
'ScrollViewDiagnosticsInfo'
}
elseif severity == vim.diagnostic.severity.WARN then
value = {
'warn',
vim.g.scrollview_diagnostics_warn_priority,
vim.g.scrollview_diagnostics_warn_symbol,
'ScrollViewDiagnosticsWarn'
Expand All @@ -47,12 +51,13 @@ function M.init(enable)
if vim.tbl_isempty(spec_data) then return end
local names = {} -- maps severity to registration name
for severity, item in pairs(spec_data) do
local priority, symbol, highlight = unpack(item)
local variant, priority, symbol, highlight = unpack(item)
local registration = scrollview.register_sign_spec({
group = group,
highlight = highlight,
priority = priority,
symbol = symbol,
variant = variant,
})
names[severity] = registration.name
end
Expand Down
1 change: 1 addition & 0 deletions lua/scrollview/signs/marks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function M.init(enable)
highlight = 'ScrollViewMarks',
priority = vim.g.scrollview_marks_priority,
symbol = char,
variant = char,
})
names[char] = registration.name
end
Expand Down

0 comments on commit 33df628

Please sign in to comment.