Skip to content

Commit 3d7e49c

Browse files
committed
feat(config)!: deprecate highlight groups in config.signs
These fields haven't been documented for some time, so now hard deprecate them.
1 parent 9291836 commit 3d7e49c

File tree

2 files changed

+52
-15
lines changed

2 files changed

+52
-15
lines changed

gen_help.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ local function gen_config_doc_field(field, out)
101101
end
102102

103103
local vtype = (function()
104-
if v.type == 'table' and v.deep_extend then
104+
local ty = v.type_help or v.type
105+
if ty == 'table' and v.deep_extend then
105106
return 'table[extended]'
106107
end
107-
local ty = v.type
108108
if type(ty) == 'table' then
109109
v.type = table.concat(ty, '|')
110110
end

lua/gitsigns/config.lua

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
--- @field hard? boolean
1212

1313
--- @class (exact) Gitsigns.SchemaElem
14-
--- @field type string|string[]
14+
--- @field type string|string[]|fun(x:any): boolean
15+
--- @field type_help? string
1516
--- @field refresh? fun(cb: fun()) Function to refresh the config value
1617
--- @field deep_extend? boolean
1718
--- @field default any
@@ -182,10 +183,50 @@ M.config = setmetatable({}, {
182183
end,
183184
})
184185

186+
local function warn(s, ...)
187+
vim.notify_once(s:format(...), vim.log.levels.WARN, { title = 'gitsigns' })
188+
end
189+
190+
--- @param x Gitsigns.SignConfig
191+
--- @return boolean
192+
local function validate_signs(x)
193+
if type(x) ~= 'table' then
194+
return false
195+
end
196+
197+
local warnings --- @type table<string,true>?
198+
199+
--- @diagnostic disable-next-line:no-unknown
200+
for kind, s in pairs(M.schema.signs.default) do
201+
--- @diagnostic disable-next-line:no-unknown
202+
for ty, v in pairs(s) do
203+
if x[kind] and x[kind][ty] and vim.endswith(ty, 'hl') then
204+
warnings = warnings or {}
205+
local w = string.format(
206+
"'signs.%s.%s' is now deprecated, please define highlight '%s'",
207+
kind,
208+
ty,
209+
v
210+
)
211+
warnings[w] = true
212+
end
213+
end
214+
end
215+
216+
if warnings then
217+
for w in vim.spairs(warnings) do
218+
warn(w)
219+
end
220+
end
221+
222+
return true
223+
end
224+
185225
--- @type table<string,Gitsigns.SchemaElem>
186226
M.schema = {
187227
signs = {
188-
type = 'table',
228+
type_help = 'table',
229+
type = validate_signs,
189230
deep_extend = true,
190231
default = {
191232
add = { hl = 'GitSignsAdd', text = '', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' },
@@ -861,22 +902,18 @@ M.schema = {
861902
},
862903
}
863904

864-
local function warn(s, ...)
865-
vim.notify(s:format(...), vim.log.levels.WARN, { title = 'gitsigns' })
866-
end
867-
868905
--- @param config Gitsigns.Config
869906
local function validate_config(config)
870-
--- @diagnostic disable-next-line:no-unknown
871-
for k, v in pairs(config) do
907+
for k, v in
908+
pairs(config --[[@as table<string,any>]])
909+
do
872910
local kschema = M.schema[k]
873911
if kschema == nil then
874912
warn("gitsigns: Ignoring invalid configuration field '%s'", k)
875-
elseif kschema.type then
876-
if type(kschema.type) == 'string' then
877-
vim.validate({
878-
[k] = { v, kschema.type },
879-
})
913+
else
914+
local ty = kschema.type
915+
if type(ty) == 'string' or type(ty) == 'function' then
916+
vim.validate({ [k] = { v, ty } })
880917
end
881918
end
882919
end

0 commit comments

Comments
 (0)