|
11 | 11 | --- @field hard? boolean
|
12 | 12 |
|
13 | 13 | --- @class (exact) Gitsigns.SchemaElem
|
14 |
| ---- @field type string|string[] |
| 14 | +--- @field type string|string[]|fun(x:any): boolean |
| 15 | +--- @field type_help? string |
15 | 16 | --- @field refresh? fun(cb: fun()) Function to refresh the config value
|
16 | 17 | --- @field deep_extend? boolean
|
17 | 18 | --- @field default any
|
@@ -182,10 +183,50 @@ M.config = setmetatable({}, {
|
182 | 183 | end,
|
183 | 184 | })
|
184 | 185 |
|
| 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 | + |
185 | 225 | --- @type table<string,Gitsigns.SchemaElem>
|
186 | 226 | M.schema = {
|
187 | 227 | signs = {
|
188 |
| - type = 'table', |
| 228 | + type_help = 'table', |
| 229 | + type = validate_signs, |
189 | 230 | deep_extend = true,
|
190 | 231 | default = {
|
191 | 232 | add = { hl = 'GitSignsAdd', text = '┃', numhl = 'GitSignsAddNr', linehl = 'GitSignsAddLn' },
|
@@ -861,22 +902,18 @@ M.schema = {
|
861 | 902 | },
|
862 | 903 | }
|
863 | 904 |
|
864 |
| -local function warn(s, ...) |
865 |
| - vim.notify(s:format(...), vim.log.levels.WARN, { title = 'gitsigns' }) |
866 |
| -end |
867 |
| - |
868 | 905 | --- @param config Gitsigns.Config
|
869 | 906 | 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 |
872 | 910 | local kschema = M.schema[k]
|
873 | 911 | if kschema == nil then
|
874 | 912 | 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 } }) |
880 | 917 | end
|
881 | 918 | end
|
882 | 919 | end
|
|
0 commit comments