Skip to content

Commit 0e9f996

Browse files
Chamal1120glepnir
andauthored
feat(utils): Add a helper to handle vim.validate for tables (#508)
* refactor(utils): update deprecated Neovim 0.11 APIs - Replaced vim.validate() with Lua-style type checks - Future-proofed utility functions for Neovim 0.11+ * refactor(utils): switch to vim.validate() form 1 for Neovim 0.11+ Replaced custom assert() checks with official vim.validate() form 1, as recommended in Neovim 0.11+ to ensure better consistency with core APIs and forward compatibility. * refactor(utils): restore some deleted comments * feat(utils): Add a helper to handle validate table * refactor(util): change nvim 0.11 check function Co-authored-by: glepnir <[email protected]> * format(util): format nvim 0.11 check function with stylua * format(util): format nvim 0.11 check function with stylua --------- Co-authored-by: glepnir <[email protected]>
1 parent b0551fa commit 0e9f996

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

doc/tags

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dashboard-backers dashboard.txt /*dashboard-backers*
2+
dashboard-configuration dashboard.txt /*dashboard-configuration*
3+
dashboard-configuration-options dashboard.txt /*dashboard-configuration-options*
4+
dashboard-configuration-theme-config dashboard.txt /*dashboard-configuration-theme-config*
5+
dashboard-donate dashboard.txt /*dashboard-donate*
6+
dashboard-feature dashboard.txt /*dashboard-feature*
7+
dashboard-install dashboard.txt /*dashboard-install*
8+
dashboard-license dashboard.txt /*dashboard-license*
9+
dashboard-links dashboard.txt /*dashboard-links*
10+
dashboard-table-of-contents dashboard.txt /*dashboard-table-of-contents*
11+
dashboard.txt dashboard.txt /*dashboard.txt*

lua/dashboard/utils.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ local uv = vim.loop
22
local utils = {}
33

44
utils.is_win = uv.os_uname().version:match('Windows')
5+
local is_nvim_11_or_newer = vim.fn.has('nvim-0.11') == 1
56

67
function utils.path_join(...)
78
local path_sep = utils.is_win and '\\' or '/'
89
return table.concat({ ... }, path_sep)
910
end
1011

12+
-- dynamically use correct validate form method
13+
local function validate_table(name, value)
14+
if is_nvim_11_or_newer then
15+
vim.validate(name, value, 'table')
16+
else
17+
vim.validate({ [name] = { value, 't' } })
18+
end
19+
end
20+
1121
function utils.element_align(tbl)
1222
local lens = {}
1323
vim.tbl_map(function(k)
@@ -26,7 +36,7 @@ function utils.element_align(tbl)
2636
end
2737

2838
function utils.get_max_len(contents)
29-
vim.validate('contents', contents, 'table')
39+
validate_table('contents', contents)
3040
local cells = {}
3141
for _, v in pairs(contents) do
3242
table.insert(cells, vim.api.nvim_strwidth(v))
@@ -37,7 +47,7 @@ end
3747

3848
-- draw the graphics into the screen center
3949
function utils.center_align(tbl)
40-
vim.validate('tbl', tbl, 'table')
50+
validate_table('tbl', tbl)
4151
local function fill_sizes(lines)
4252
local fills = {}
4353
for _, line in pairs(lines) do

0 commit comments

Comments
 (0)