Skip to content

Commit 97a86c9

Browse files
fix: backwards compatibility for vim.validate (#61)
1 parent 20ea86e commit 97a86c9

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

.github/workflows/unit_tests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Run Tests
22

3-
on:
4-
pull_request: {}
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
56
push:
67
branches: [master]
78

@@ -16,7 +17,7 @@ jobs:
1617
- macos-latest
1718
- ubuntu-latest
1819
- windows-latest
19-
neovim_version:
20+
neovim_version:
2021
- v0.7.2
2122
- v0.8.3
2223
- v0.9.5

lua/auto-dark-mode/init.lua

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,29 @@ local default_options = {
1919

2020
---@param options AutoDarkModeOptions
2121
local function validate_options(options)
22-
vim.validate("fallback", options.fallback, function(opt)
23-
return vim.tbl_contains({ "dark", "light" }, opt)
24-
end, "`fallback` to be either 'light' or 'dark'")
25-
vim.validate("set_dark_mode", options.set_dark_mode, "function")
26-
vim.validate("set_light_mode", options.set_light_mode, "function")
27-
vim.validate("update_interval", options.update_interval, "number")
22+
local version = vim.version()
23+
24+
if (version.major == 0 and version.minor >= 11) or version.major > 0 then
25+
vim.validate("fallback", options.fallback, function(opt)
26+
return vim.tbl_contains({ "dark", "light" }, opt)
27+
end, "`fallback` to be either 'light' or 'dark'")
28+
vim.validate("set_dark_mode", options.set_dark_mode, "function")
29+
vim.validate("set_light_mode", options.set_light_mode, "function")
30+
vim.validate("update_interval", options.update_interval, "number")
31+
else
32+
vim.validate({
33+
fallback = {
34+
options.fallback,
35+
function(opt)
36+
return vim.tbl_contains({ "dark", "light" }, opt)
37+
end,
38+
"`fallback` to be either 'light' or 'dark'",
39+
},
40+
set_dark_mode = { options.set_dark_mode, "function" },
41+
set_light_mode = { options.set_light_mode, "function" },
42+
update_interval = { options.update_interval, "number" },
43+
})
44+
end
2845

2946
M.state.setup_correct = true
3047
end

0 commit comments

Comments
 (0)